-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
158 lines (131 loc) · 4.54 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 3.9)
#--- OPTIONS
option(OPENMP "ON - enables adding of OpenMP targets, OFF - disables adding of OpenMP targets" ON)
option(INTEL "Use <ifort> Intel compiler" OFF)
option(GNU "Use <gfortran> GNU compiler" OFF)
option(PGI "Use <pgfortran> PGI compiler" OFF)
option(CLANG "Turn ON/OFF clang compiler" OFF)
option(Enable_D3 "Use dftd3 lib" OFF)
option(Enable_GCP "Use gcplib" OFF)
option(Enable_LBFGS "Use bfgs lib" OFF)
option(Enable_EXTRAS "Use all 3 above libs" OFF)
option(Enable_LEGACY "Option for 'my Fortran compiler is too old'" OFF)
# lazy compiler request
if(INTEL)
set(CMAKE_Fortran_COMPILER ifort)
list(APPEND D_FLAGS INTEL)
elseif(GNU)
set(CMAKE_Fortran_COMPILER gfortran)
list(APPEND D_FLAGS GNU)
elseif(PGI)
set(CMAKE_Fortran_COMPILER pgfortran)
list(APPEND D_FLAGS PGI)
endif()
if(Enable_D3)
list(APPEND D_FLAGS DFTD3)
endif()
if(Enable_GCP)
list(APPEND D_FLAGS GCP)
endif()
if(Enable_LBFGS)
list(APPEND D_FLAGS GCP)
endif()
if(Enable_EXTRAS)
list(APPEND D_FLAGS GCP DFTD3 BFGS)
endif()
if(Enable_EXTRAS)
list(APPEND D_FLAGS LEGAGY)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# set project data
project(xopt Fortran)
set(xopt_URL "https://github.com/hokru/xopt")
set(xopt_LICENSE "GNU Lesser General Public License, version 3 (LGPL-3.0)")
set(xopt_DESCRIPTION "Open-Source External Optimizer for Quantum Chemistry")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(custom_color_messages)
set(CMAKE_Fortran_FORMAT FREE)
find_package(OpenMP)
if(OpenMP_FC_FOUND)
target_link_libraries(MyTarget PUBLIC OpenMP::OpenMP_FC)
endif()
# BLAS AND LAPACK DETECTION
set(BLAS "MKL" CACHE STRING "Default Lapack/Blas library")
set_property(CACHE BLAS PROPERTY STRINGS "MKL;OpenBLAS;Generic")
message(STATUS "Searching for Lapack/Blas backend: " ${BLAS})
if(BLAS STREQUAL "MKL")
find_package(MKL REQUIRED)
list(APPEND LAPACK_LIBRARIES ${MKL_LIBRARY})
elseif(BLAS STREQUAL "OpenBLAS")
find_package(OpenBLAS REQUIRED)
# include_directories(LAPACK_INCLUDE_DIR ${OpenBLAS_INCLUDE_DIR})
list(APPEND LAPACK_LIBRARIES ${OpenBLAS_LIB})
elseif(BLAS STREQUAL "Generic")
find_package(LAPACK REQUIRED)
endif()
# find_package(BLAS REQUIRED)
#find_package(LAPACK REQUIRED)
message(STATUS "${Cyan}Using LAPACK${ColourReset}: ${LAPACK_LIBRARIES};...")
#--- Add a distclean target to the Makefile
ADD_CUSTOM_TARGET(distclean
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/distclean.cmake
)
# Write version.dat file
execute_process(COMMAND git describe --abbrev=4 --dirty --always --tags
RESULT_VARIABLE git_return
OUTPUT_VARIABLE commit)
if(git_return)
set(GIT_VERSION "unknown")
else()
string(REGEX REPLACE "\n$" "" GIT_VERSION ${commit})
endif()
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
RESULT_VARIABLE git_return
OUTPUT_VARIABLE branch)
if(git_return)
set(GIT_VERSION "unknown")
else()
string(REGEX REPLACE "\n$" "" GIT_BRANCH ${branch})
endif()
string(TIMESTAMP DATE "%H:%M:%S %Y-%m-%d ")
set(USER $ENV{USER})
set(HOST $ENV{HOSTNAME})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/version.dat.in ${CMAKE_CURRENT_SOURCE_DIR}/src/version.dat)
# compiler flags
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS_DEBUG "-fbounds-check -Og -g -Wunused-dummy-argument -std=f2008 -fall-intrinsics -fbacktrace")
# set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
endif()
if(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS_DEBUG "-check bounds -O0 -g traceback -std08 -debug -fp-model=consistent -fp-speculation=save ")
# set(CMAKE_Fortran_FLAGS_RELEASE "-O3")
endif()
# Have the .mod files placed in a special directory
set(mod-dir ${CMAKE_BINARY_DIR}/mod)
file(MAKE_DIRECTORY ${mod-dir})
set(CMAKE_Fortran_MODULE_DIRECTORY ${mod-dir})
add_executable(xopt "")
add_subdirectory(src)
# target_link_libraries(xopt
# tgt::lapack)
target_link_libraries(xopt
${LAPACK_LIBRARIES})
message(STATUS "${Cyan}pre-processor flags${ColourReset}: ${D_FLAGS}")
# message(pre-processor flags: ${D_FLAGS})
# set pre-processor flags
target_compile_definitions(xopt
PRIVATE
${D_FLAGS}
)
#--- Install
# if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# set(CMAKE_INSTALL_PREFIX "/usr/local/xopt" CACHE PATH "Install path" FORCE)
# endif()
# message(STATUS "xopt install: ${CMAKE_INSTALL_PREFIX}")
# set(STAGED_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/stage)
# message(STATUS "xopt staging: ${STAGED_INSTALL_PREFIX}")
install(DIRECTORY ${STAGED_INSTALL_PREFIX}/
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS)