-
Notifications
You must be signed in to change notification settings - Fork 24
/
CMakeLists.txt
386 lines (327 loc) · 13.5 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
cmake_minimum_required(VERSION 3.0.0)
###############################################################################
# Announce ourselves
###############################################################################
project(MPQC)
set (MPQC_MAJOR_VERSION 4)
set (MPQC_MINOR_VERSION 0)
set (MPQC_PATCH_VERSION 0)
set(MPQC_BUILDID beta.1)
set(MPQC_VERSION "${MPQC_MAJOR_VERSION}.${MPQC_MINOR_VERSION}.${MPQC_PATCH_VERSION}")
if (MPQC_BUILDID)
set(MPQC_VERSION "${MPQC_VERSION}-${MPQC_BUILDID}")
endif(MPQC_BUILDID)
set(TARGET_ARCH "${CMAKE_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR}")
###############################################################################
# Load up extra CMake packages
###############################################################################
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules/")
include(FeatureSummary)
include(GNUInstallDirs)
include(AddMPQCLibrary)
include(CMakePackageConfigHelpers)
include(AppendFlags)
#include(cotire)
# Set install paths ============================================================
set(MPQC_INSTALL_BINDIR "bin"
CACHE PATH "MPQC binary install directory")
set(MPQC_INSTALL_INCLUDEDIR "include"
CACHE PATH "MPQC INCLUDE install directory")
set(MPQC_INSTALL_LIBDIR "lib"
CACHE PATH "MPQC LIB install directory")
set(MPQC_INSTALL_DATADIR "share/mpqc/${MPQC_VERSION}/data"
CACHE PATH "MPQC DATA install directory")
# TODO this matches Automake value, should be adjusted to the convention: share/mpqc/${MPQC_VERSION}/doc
set(MPQC_INSTALL_DOCDIR "share/doc/mpqc"
CACHE PATH "MPQC DOC install directory")
set(MPQC_INSTALL_CMAKEDIR "lib/cmake/mpqc"
CACHE PATH "MPQC CMAKE install directory")
###############################################################################
# Options
###############################################################################
# boolean
# non-boolean
if (NOT DEFINED MPQC_MEMORY_CHECK)
set(MPQC_MEMORY_CHECK -1) # How to check memory use (see mpqc_config.h for details)
else()
message("MPQC_MEMORY_CHECK = ${MPQC_MEMORY_CHECK}")
endif()
if (NOT DEFINED MPQC_ASSERT_MODE)
set(MPQC_ASSERT_MODE -1) # How to implement assertions (see mpqc_config.h for details)
endif()
set(TA_POLICY sparse CACHE STRING "Set to \"dense\" (to default to TA::DensePolicy) or \"sparse\" (to default to TA::SparsePolicy)")
# convert string value of TA_POLICY to numerical values as TA_DEFAULT_POLICY
set(TA_DEFAULT_POLICY 1)
if(TA_POLICY STREQUAL sparse)
set(TA_DEFAULT_POLICY 1)
MESSAGE("Set to TA::SparsePolicy")
elseif(TA_POLICY STREQUAL dense)
set(TA_DEFAULT_POLICY 0)
MESSAGE("Set to TA::DensePolicy")
endif()
##########################
# Standard build variables
##########################
# Get standard build variables from the environment if they have not already been set
if(NOT CMAKE_C_FLAGS OR NOT DEFINED CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "$ENV{CPPFLAGS}")
append_flags(CMAKE_C_FLAGS "$ENV{CFLAGS}")
endif()
if(NOT CMAKE_CXX_FLAGS OR NOT DEFINED CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "$ENV{CPPFLAGS}")
append_flags(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS}")
endif()
if(NOT CMAKE_EXE_LINKER_FLAGS OR NOT DEFINED CMAKE_EXE_LINKER_FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "$ENV{LDFLAGS}")
endif()
enable_language (CXX)
if (NOT CMAKE_CXX_COMPILER)
message(FATAL_ERROR "C++ compiler not found")
endif()
###############################################################################
# How to compile
###############################################################################
### RPATH config to ensure full path is used
### see https://cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH
set(CMAKE_MACOSX_RPATH FALSE)
# use RPATH if possible
set(CMAKE_SKIP_RPATH FALSE)
# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
# MacOS specific
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG "-Wl,-rpath,")
# look for frameworks and appbundles last
set(CMAKE_FIND_FRAMEWORK LAST)
set(CMAKE_FIND_APPBUNDLE LAST)
endif()
# may need this to link in MPI library via MADWorld dependency alone
# e.g. when MADNESS is configured with non-throwing asserts there is no direct mention of MPI
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set (CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")
endif()
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
# by default, use same type of BLAS/LAPACK libs (shared/static) as we are using for MPQC
if(BUILD_SHARED_LIBS)
set(BLA_STATIC FALSE)
else()
set(BLA_STATIC TRUE)
endif()
# look for ccache
find_program(CCACHE ccache)
if(CCACHE)
message (STATUS "Found ccache: ${CCACHE}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
endif(CCACHE)
###############################################################################
# Compiler/library features
###############################################################################
include(CheckCXXSourceCompiles)
include(CheckIncludeFiles)
include(CheckFunctionExists)
# Check compiler feature support ===============================================
# need for C++14 will be inherited from madness
# but insist on strict standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
check_include_files(sys/resource.h HAVE_SYS_RESOURCE_H)
check_include_files(pwd.h HAVE_PWD_H)
check_include_files(libunwind.h HAVE_LIBUNWIND_H)
check_include_files(execinfo.h HAVE_EXECINFO_H)
check_include_files(fenv.h HAVE_FENV_H)
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(cxxabi.h HAVE_CXXABI_H)
if (HAVE_CXXABI_H)
CHECK_CXX_SOURCE_COMPILES("
#include <cxxabi.h>
int main(int argc, char* argv[]) {
char* result = abi::__cxa_demangle(\"\", 0, 0, 0);
return 0;
}" HAVE_CXA_DEMANGLE)
if (HAVE_CXA_DEMANGLE)
message("-- Looking for abi::__cxa_demangle - found")
else()
message("-- Looking for abi::__cxa_demangle - not found")
endif()
endif(HAVE_CXXABI_H)
if (HAVE_LIBUNWIND_H)
CHECK_FUNCTION_EXISTS (unw_init_local HAVE_LIBUNWIND)
endif(HAVE_LIBUNWIND_H)
if (HAVE_EXECINFO_H)
CHECK_FUNCTION_EXISTS (backtrace HAVE_BACKTRACE_FN)
CHECK_FUNCTION_EXISTS (backtrace_symbols HAVE_BACKTRACE_SYMBOLS_FN)
if (HAVE_BACKTRACE_FN AND HAVE_BACKTRACE_SYMBOLS_FN)
set (HAVE_BACKTRACE 1)
endif()
else (HAVE_EXECINFO_H)
#find_package(ExecInfo)
endif (HAVE_EXECINFO_H)
CHECK_FUNCTION_EXISTS (gethostname HAVE_GETHOSTNAME)
CHECK_FUNCTION_EXISTS (getpwuid HAVE_GETPWUID)
CHECK_FUNCTION_EXISTS (geteuid HAVE_GETEUID)
CHECK_FUNCTION_EXISTS (getrusage HAVE_GETRUSAGE)
CHECK_FUNCTION_EXISTS (posix_spawn HAVE_POSIX_SPAWN)
CHECK_FUNCTION_EXISTS (system HAVE_SYSTEM)
CHECK_FUNCTION_EXISTS (signal HAVE_SIGNAL)
CHECK_FUNCTION_EXISTS (feenableexcept HAVE_FEENABLEEXCEPT)
CHECK_FUNCTION_EXISTS (fedisableexcept HAVE_FEDISABLEEXCEPT)
CHECK_FUNCTION_EXISTS (setrlimit HAVE_SETRLIMIT)
###############################################################################
# Dependencies
###############################################################################
##### TiledArray #####
# search for TA first, other packages can be found with it
if(TiledArray_INSTALL_DIR)
set(TiledArray_DIR ${TiledArray_INSTALL_DIR}/lib/cmake/tiledarray)
endif()
FIND_PACKAGE(TiledArray CONFIG REQUIRED COMPONENTS tiledarray)
include(ValidateTiledArray)
validate_tiledarray()
message(STATUS "Found TiledArray CONFIG at ${TiledArray_CONFIG}")
##### Boost #####
FIND_PACKAGE(Boost REQUIRED COMPONENTS filesystem locale serialization system)
##### TBB #####
# TiledArray and MADNESS set search path for TBB to TBB_ROOT_DIR, KitWare's FindTBB expects TBB_ROOT
if(TBB_ROOT_DIR)
set(TBB_ROOT ${TBB_ROOT_DIR})
endif(TBB_ROOT_DIR)
FIND_PACKAGE(TBB REQUIRED)
# set up an interface library for TBB a la https://github.com/justusc/FindTBB
include(ImportTBB)
import_tbb()
##### Eigen3 #####
include(external/eigen.cmake)
##### BTAS #####
include(external/btas.cmake)
##### Libint2 #####
FIND_PACKAGE(LIBINT2 REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${LIBINT2_INCLUDE_DIRS})
add_definitions(${LIBINT2_EXTRA_DEFINITIONS})
find_package(PythonInterp)
# pass on some info to pkg-config
list(APPEND MPQC_CONFIG_INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${LIBINT2_INCLUDE_DIRS})
list(APPEND MPQC_CONFIG_LIBRARIES ${Boost_LIBRARIES})
list(APPEND MPQC_CONFIG_DEFINITIONS ${LIBINT2_EXTRA_DEFINITIONS})
###############################################################################
# Descend into the source tree and build component libraries and MPQC exec
###############################################################################
INCLUDE_DIRECTORIES(${MPQC_SOURCE_DIR}/src)
INCLUDE_DIRECTORIES(${MPQC_BINARY_DIR}/src)
ADD_SUBDIRECTORY(${MPQC_SOURCE_DIR}/src/mpqc)
MESSAGE(STATUS "Using CXX Flags ${CMAKE_CXX_FLAGS}")
###############################################################################
# Declare MPQC program
###############################################################################
ADD_SUBDIRECTORY(${MPQC_SOURCE_DIR}/src/bin)
###############################################################################
# Declare MPQC tests, examples, and docs
###############################################################################
ADD_SUBDIRECTORY(${MPQC_SOURCE_DIR}/doc)
ADD_SUBDIRECTORY(${MPQC_SOURCE_DIR}/tests)
ADD_SUBDIRECTORY(${MPQC_SOURCE_DIR}/examples)
##########################
# pkg-config variables
##########################
foreach(_inc ${MPQC_CONFIG_INCLUDE_DIRS})
append_flags(MPQC_PC_CFLAGS "-I${_inc}")
endforeach()
foreach(_def ${MPQC_CONFIG_DEFINITIONS})
append_flags(MPQC_PC_CFLAGS "${_def}")
endforeach()
foreach(_lib ${MPQC_CONFIG_LIBRARIES})
append_flags(MPQC_PC_LIBS "${_lib}")
endforeach()
##########################
# Get the git revision tag information
##########################
if(EXISTS ${PROJECT_SOURCE_DIR}/.git)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse -q HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE MPQC_REVISION )
string(REGEX MATCH "[0-9a-f]*"
MPQC_REVISION "${MPQC_REVISION}")
else()
set(MPQC_REVISION "${MPQC_REVISION}")
endif()
###############################################################################
# Wrap up
###############################################################################
# Force cache refresh for compile flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "C compile flags" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "C++ compile flags" FORCE)
CONFIGURE_FILE(
${PROJECT_SOURCE_DIR}/src/mpqc/mpqc_config.h.in
${PROJECT_BINARY_DIR}/src/mpqc/mpqc_config.h
)
CONFIGURE_FILE(
${PROJECT_SOURCE_DIR}/mpqc.pc.in
${PROJECT_BINARY_DIR}/mpqc.pc
)
# sample CMakeLists.txt
set(sample_dirs "mp2;aoints")
foreach(sample_dir ${sample_dirs})
configure_file(
${PROJECT_SOURCE_DIR}/doc/devsamp/${sample_dir}/CMakeLists.txt.in
${PROJECT_BINARY_DIR}/doc/devsamp/${sample_dir}/CMakeLists.txt
@ONLY
)
endforeach()
# install config files
install(FILES ${PROJECT_BINARY_DIR}/mpqc.pc
DESTINATION lib/pkgconfig)
# Create the version file
write_basic_package_version_file(mpqc-config-version.cmake
VERSION ${MPQC_VERSION} COMPATIBILITY AnyNewerVersion)
# Create the targets file
export(EXPORT mpqc
FILE "${PROJECT_BINARY_DIR}/mpqc-targets.cmake")
# Create the configure file
configure_package_config_file(cmake/mpqc-config.cmake.in
"${PROJECT_BINARY_DIR}/mpqc-config.cmake"
INSTALL_DESTINATION "${MPQC_INSTALL_CMAKEDIR}"
PATH_VARS CMAKE_INSTALL_PREFIX MPQC_INSTALL_BINDIR
MPQC_INSTALL_INCLUDEDIR MPQC_INSTALL_LIBDIR
MPQC_INSTALL_DOCDIR MPQC_INSTALL_CMAKEDIR)
# Install config, version, and target files
install(EXPORT mpqc
FILE "mpqc-targets.cmake"
DESTINATION "${MPQC_INSTALL_CMAKEDIR}"
COMPONENT mpqc-config)
install(FILES
"${PROJECT_BINARY_DIR}/mpqc-config.cmake"
"${PROJECT_BINARY_DIR}/mpqc-config-version.cmake"
DESTINATION "${MPQC_INSTALL_CMAKEDIR}"
COMPONENT mpqc-config)
add_custom_target(install-config
COMMAND ${CMAKE_COMMAND} -DCOMPONENT=mpqc-config -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
COMMENT "Installing MPQC config components")
feature_summary(WHAT ALL
DESCRIPTION "=== MPQC Package/Feature Info ===")
###############################################################################
# appendix: misc details
###############################################################################
SET(CMAKE_COLOR_MAKEFILE ON)