File: CMakeLists.txt

package info (click to toggle)
mpqc3 0.0~git20170114-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 148,800 kB
  • sloc: cpp: 545,687; ansic: 13,220; perl: 5,065; fortran: 1,990; lisp: 1,269; python: 717; yacc: 392; sh: 304; f90: 238; lex: 184; xml: 182; makefile: 114
file content (474 lines) | stat: -rw-r--r-- 13,824 bytes parent folder | download | duplicates (2)
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#; -*-CMake-*-

cmake_minimum_required(VERSION 3.0.0)
project (MPQC CXX C Fortran)

# extra cmake files are shipped with MPQC
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/modules/")

set (MPQC_MAJOR_VERSION 3)
set (MPQC_MINOR_VERSION 0)
set (MPQC_PATCH_VERSION 0)
set(MPQC_BUILDID alpha)
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_NAME}-${CMAKE_SYSTEM_PROCESSOR}")

#####################
# Options
#####################
# boolean
option(MPQC_EXPERT "MPQC Expert mode: disables automatically downloading or building dependencies" OFF)
option(MPQC_NEW_FEATURES "Use new MPQC features (requires C++11)" OFF)
option(MPQC_OPENMP "Use OpenMP" OFF)
option(GAMESS "MPQC-GAMESS interface: checks for GAMESS-compatible libint2, adjusts normalization, etc." OFF)
# 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()

# MPQC-GAMESS interface requires exact normalization convention
if (GAMESS AND NOT DEFINED INTEGRALLIBINT2_NORMCONV)
  set (INTEGRALLIBINT2_NORMCONV 2)
endif()

include(cotire)

include(CTest)
enable_testing()

enable_language (CXX)
if (NOT CMAKE_CXX_COMPILER)
  message(FATAL_ERROR "C++ compiler not found")
endif()

# FORTRAN setup
enable_language (Fortran)
if (NOT CMAKE_Fortran_COMPILER)
   message(FATAL_ERROR "Fortran compiler not found")
endif()
if(INTEGER8) 
  set(F77_INTEGER_WIDTH 8)
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DINTEGER77='INTEGER*8' ")
else()
  set(F77_INTEGER_WIDTH 4)
  set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -DINTEGER77='INTEGER*4' ")
endif()
#list(append CMAKE_Fortran_FLAGS "-m64")



##############################
# Build Type Information
##############################
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")

set(CMAKE_SKIP_RPATH FALSE)

set(BUILD_TESTING FALSE CACHE BOOLEAN "BUILD_TESTING")
set(BUILD_TESTING_STATIC FALSE CACHE BOOLEAN "BUILD_TESTING_STATIC")
set(BUILD_TESTING_SHARED FALSE CACHE BOOLEAN "BUILD_TESTING_SHARED")

if (MPQC_OPENMP)
  find_package(OpenMP)
  if (OPENMP_FOUND)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
  endif()
endif()

include(TestCXXAcceptsFlag)
include(CheckCXXSourceCompiles)

# Enable CI
if (MPQC_NEW_FEATURES)
  if (NOT DEFINED MPQC_CI)
    set(MPQC_CI FALSE)
  endif()
  if (MPQC_CI)
    add_definitions(-DMPQC_CI)
  endif()
endif()

# Enable Unit Test
if (MPQC_UNITTEST)
  if (NOT MPQC_NEW_FEATURES) 
    message(FATAL_ERROR "Unit testing requires MPQC_NEW_FEATURES")
  endif()
  if (BOOST)
    message(FATAL_ERROR "Must have MPQC build Boost for unit testing")
  endif()
  add_definitions(-DMPQC_UNITTEST)
endif()
    

if (MPQC_NEW_FEATURES)
  add_definitions(-DMPQC_NEW_FEATURES)
  
  # "some" C++11 features are required, check if we need a flag to turn on the support in the compiler
  # N.B. even though clang++ assumes c++11, it still needs the flag for some features (e.g. static_assert)
  CHECK_CXX_ACCEPTS_FLAG("-std=c++11" CXX_FLAG_CXX11)
  if(CXX_FLAG_CXX11)
    set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
    message(STATUS "C++11 flag: -std=c++11")
  endif()
  if (NOT CXX_FLAG_CXX11)
    CHECK_CXX_ACCEPTS_FLAG("-std=c++0x" CXX_FLAG_CXX0X)
  endif()
  if (CXX_FLAG_CXX0X)
    set(CMAKE_CXX_FLAGS "-std=c++0x ${CMAKE_CXX_FLAGS}")
    message(STATUS "C++11 flag: -std=c++0x")
  endif()
  
endif()

# C++11 features
CHECK_CXX_SOURCE_COMPILES("
  int main() {
  auto c = 1;
  }"
  HAVE_CXX_AUTO)  
if (MPQC_NEW_FEATURES AND NOT HAVE_CXX_AUTO)
  message(FATAL_ERROR "MPQC_NEW_FEATURES requires support for C++11 auto")
endif()

# std::array
CHECK_CXX_SOURCE_COMPILES("
    #include <array>
    int main(void)
    {
      std::array<int,2> array;
    }"
    HAVE_STD_ARRAY)

CHECK_CXX_SOURCE_COMPILES("
  int main() {
  void *restrict ptr;
  }" HAVE_CXX_RESTRICT)

CHECK_CXX_SOURCE_COMPILES("
  int main() {
  void *__restrict__ ptr;
  }" HAVE_CXX___RESTRICT__)



option(USE_STATIC_LIBS "use static libraries" OFF)
if(USE_STATIC_LIBS)
  set(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
ENDIF()

include(CheckIncludeFiles)
include(CheckFunctionExists)

include(CheckIncludeFiles)
find_package(Threads)
if (Threads_FOUND)
  set(Threads_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
  check_include_files(pthread.h HAVE_PTHREAD)
  check_function_exists(pthread_attr_setstacksize HAVE_PTHREAD_ATTR_SETSTACKSIZE)
  check_function_exists(pthread_attr_getstacksize HAVE_PTHREAD_ATTR_GETSTACKSIZE)
  check_function_exists(pthread_attr_setscope HAVE_PTHREAD_ATTR_SETSCOPE)
  check_function_exists(pthread_attr_getscope HAVE_PTHREAD_ATTR_GETSCOPE)
  check_function_exists(pthread_attr_setinheritsched HAVE_PTHREAD_ATTR_SETINHERITSCHED)
  check_function_exists(pthread_attr_getinheritsched HAVE_PTHREAD_ATTR_GETINHERITSCHED)
  check_function_exists(pthread_attr_setschedpolicy HAVE_PTHREAD_ATTR_SETSCHEDPOLICY)
  check_function_exists(pthread_attr_getschedpolicy HAVE_PTHREAD_ATTR_GETSCHEDPOLICY)
  check_function_exists(pthread_attr_setschedparam HAVE_PTHREAD_ATTR_SETSCHEDPARAM)
  check_function_exists(pthread_attr_getschedparam HAVE_PTHREAD_ATTR_GETSCHEDPARAM)
  check_function_exists(pthread_attr_getschedparam HAVE_PTHREAD_ATTR_GETSCHEDPARAM)
  check_function_exists(sched_get_priority_max HAVE_SCHED_GET_PRIORITY_MAX)
  check_function_exists(sched_get_priority_min HAVE_SCHED_GET_PRIORITY_MIN)
endif()



include(CheckTypeSize)
check_type_size(int64_t C_TYPE_INT64_T)
check_type_size(int32_t C_TYPE_INT32_T)
check_type_size(long C_TYPE_LONG)
check_type_size(int C_TYPE_INT)

check_include_files(stdint.h             HAVE_STDINT_H)
check_include_files(dlfcn.h              HAVE_DLFCN_H)
check_include_files(sys/time.h           HAVE_SYS_TIME_H)
check_include_files(sys/times.h          HAVE_SYS_TIMES_H)
check_include_files(sys/types.h          HAVE_SYS_TYPES_H)
check_include_files(sys/resource.h       HAVE_SYS_RESOURCE_H)
check_include_files(unistd.h             HAVE_UNISTD_H)
check_include_files(pwd.h                HAVE_PWD_H)
check_include_files(time.h               HAVE_TIME_H)
check_include_files(fenv.h               HAVE_FENV_H)
check_include_files(libunwind.h          HAVE_LIBUNWIND_H)
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(cxxabi.h          HAVE_CXXABI_H)
check_include_files(execinfo.h           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 (lstat             HAVE_LSTAT)
CHECK_FUNCTION_EXISTS (time              HAVE_TIME)
CHECK_FUNCTION_EXISTS (ctime             HAVE_CTIME)
CHECK_FUNCTION_EXISTS (posix_spawn       HAVE_POSIX_SPAWN)
CHECK_FUNCTION_EXISTS (setenv            HAVE_SETENV)
CHECK_FUNCTION_EXISTS (system            HAVE_SYSTEM)
CHECK_FUNCTION_EXISTS (signal            HAVE_SIGNAL)
CHECK_FUNCTION_EXISTS (drang48           HAVE_DRAND48)
CHECK_FUNCTION_EXISTS (fchdir            HAVE_FCHDIR)
CHECK_FUNCTION_EXISTS (feenableexcept    HAVE_FEENABLEEXCEPT)
CHECK_FUNCTION_EXISTS (fedisableexcept   HAVE_FEDISABLEEXCEPT)
CHECK_FUNCTION_EXISTS (setrlimit         HAVE_SETRLIMIT)
CHECK_FUNCTION_EXISTS (isnan             HAVE_ISNAN)
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)
  endif()
else (HAVE_EXECINFO_H)
  #find_package(ExecInfo)
endif (HAVE_EXECINFO_H)


include(FortranCInterface)
FortranCInterface_VERIFY(CXX)

set(FORTRAN_FUNCTIONS
  PDSTEQR
  DCOPY
  DNRM2
  DSCAL
  DGEMM
  DGEMV
  DAXPY
  DDOT
  DSPMV
  DGESVD
  DSPSVX
  DSYEVD
  DSPTRF
  DPPTRF
  DSPTRI
  DPPTRI
  DLANSP
  DSPCON
  DPPCON
  DLAMCH
  DLACPY
  DSPTRS
  DPPTRS
  DSPRFS
  DPPRFS
  DSYGV
  DGEQRF
  DGETRF
  DGETRS
  DORGQR
  DPOTF2
  DTRTRS
  )

set(fortran_headers 
lib/math/optimize/f77sym.h
lib/math/optimize/levmar/f77sym.h
lib/math/scmat/f77sym.h
)

foreach(header ${fortran_headers})
  FortranCInterface_HEADER(
    ${PROJECT_BINARY_DIR}/src/${header}
    MACRO_NAMESPACE "FC_"
    SYMBOL_NAMESPACE "F77_"
    SYMBOLS ${FORTRAN_FUNCTIONS}
    )
endforeach()

include(GNUInstallDirs)           

set(SRC_MPQC_DATA_PATH ${PROJECT_SOURCE_DIR}/lib)
set(MPQCDATAPATH ${CMAKE_INSTALL_FULL_DATAROOTDIR}/mpqc/${MPQC_VERSION})
set(INSTALLED_MPQC_DATA_PATH ${CMAKE_INSTALL_FULL_DATAROOTDIR}/mpqc/${MPQC_VERSION})

INSTALL(FILES ./lib/atominfo.kv DESTINATION ${MPQCDATAPATH})
INSTALL(DIRECTORY ./lib/basis DESTINATION ${MPQCDATAPATH})

include_directories("${PROJECT_BINARY_DIR}/src/lib")
include_directories("${PROJECT_SOURCE_DIR}/src/lib")
include_directories("${PROJECT_SOURCE_DIR}/include") # flex/lexer

# external dependencies
include(external/External)

CONFIGURE_FILE(
  ${PROJECT_SOURCE_DIR}/src/lib/mpqc_config.h.in
  ${PROJECT_BINARY_DIR}/src/lib/mpqc_config.h
)
add_definitions(-DHAVE_CONFIG_H)

CONFIGURE_FILE(
  ${PROJECT_SOURCE_DIR}/bin/mpqcrun.in
  ${PROJECT_BINARY_DIR}/bin/mpqcrun
  @ONLY
)

# libraries
set(LINK_LIBRARIES)
list(APPEND LINK_LIBRARIES ${LIBRYSQ_LIBRARY})
list(APPEND LINK_LIBRARIES ${LIBINT2_LIBRARY})
list(APPEND LINK_LIBRARIES ${PSI3_LIBRARIES})
list(APPEND LINK_LIBRARIES ${TILEDARRAY_LIBRARIES})
list(APPEND LINK_LIBRARIES ${OPENBABEL2_LIBRARIES})
list(APPEND LINK_LIBRARIES ${Boost_LIBRARIES})
if (MPQC_UNITTEST)
  list(APPEND LINK_LIBRARIES ${Boost_UNITTEST_LIBRARIES})
endif()
list(APPEND LINK_LIBRARIES ${LAPACK_LIBRARIES})
list(APPEND LINK_LIBRARIES ${BLAS_LIBRARIES})
list(APPEND LINK_LIBRARIES ${PYTHON_LIBRARIES})
list(APPEND LINK_LIBRARIES ${HDF5_LIBRARIES})
list(APPEND LINK_LIBRARIES ${ARMCI_LIBRARIES})
list(APPEND LINK_LIBRARIES ${MPI_LIBRARIES})
list(APPEND LINK_LIBRARIES ${PAPI_LIBRARIES})
list(APPEND LINK_LIBRARIES ${Threads_LIBRARIES})
list(APPEND LINK_LIBRARIES ${LIBRARIES})
list(APPEND LINK_LIBRARIES ${CMAKE_DL_LIBS})

########################################################
# determine whether certain features lack preprequisites
########################################################
# R12
if (HAVE_LIBINT2)
  set(MPQC_R12 TRUE)
  add_definitions(-DMPQC_R12)
else()
  message("** R12 methods require Libint2.  R12 methods are disabled")
endif()

# propagate some variables into Makefiles
if (MPQC_NEW_FEATURES)
  set(MAKE_ASSUME_NEW_FEATURES yes)
endif()

if (MPQC_CI)
  set(MAKE_ASSUME_CI yes)
endif()

if (MPQC_R12)
  set(MAKE_ASSUME_R12 yes)
endif()

if (HAVE_PSI3)
  set(MAKE_ASSUME_PSI yes)
endif()

if (HAVE_LIBINT2)
  if (LIBINT_SUPPORTS_G12_T1G12_INTEGRALS)
    set(MAKE_ASSUME_LIBINT2_SUPPORTS_T1G12 yes)
  endif()
endif()

# sources
add_subdirectory(src)
add_subdirectory(doc EXCLUDE_FROM_ALL) # will not build docs by default

# checking/testing
add_subdirectory(test)


# Export include dirs, library list

set(MPQC_CONFIG_LIBRARIES "")

# Fortran libraries
foreach (_lib ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
  set(_libpath _libpath-NOTFOUND)
  find_library(_libpath ${_lib} PATHS ${CMAKE_Fortran_IMPLICIT_LINK_DIRECTORIES})
  if (_libpath)
    list(APPEND LINK_LIBRARIES ${_libpath})
  else()
    list(APPEND LINK_LIBRARIES ${_lib})
  endif()
endforeach()

# transform library list into compiler args
include(ConvertLibrariesListToCompilerArgs)
convert_libs_to_compargs(MPQC_CONFIG_LIBRARIES "${LINK_LIBRARIES}")
#message(STATUS "MPQC_CONFIG_LIBRARIES = ${MPQC_CONFIG_LIBRARIES}")

# include dirs
get_directory_property(MPQC_INCLUDE_DIRECTORIES DIRECTORY src/bin/mpqc INCLUDE_DIRECTORIES)
# remove internal source dirs
list(REMOVE_ITEM
  MPQC_INCLUDE_DIRECTORIES
  ${PROJECT_BINARY_DIR}/src/lib
  ${PROJECT_SOURCE_DIR}/src/lib
  ${PROJECT_SOURCE_DIR}/include
) 

set(MPQC_CPP_FLAGS "${CMAKE_CPP_FLAGS}")
foreach (_dir ${MPQC_INCLUDE_DIRECTORIES})
  set(MPQC_CPP_FLAGS "${MPQC_CPP_FLAGS} -I${_dir}")
endforeach()
# MPQC includes
set(MPQC_CPP_FLAGS "-I${CMAKE_INSTALL_PREFIX}/include/ ${MPQC_CPP_FLAGS}")
set(MPQC_CPP_FLAGS "-I${CMAKE_INSTALL_PREFIX}/include/mpqc ${MPQC_CPP_FLAGS}")
#message(STATUS "MPQC_CPP_FLAGS = ${MPQC_CPP_FLAGS}")

CONFIGURE_FILE(
  ${PROJECT_SOURCE_DIR}/bin/mpqc-config.in
  ${PROJECT_BINARY_DIR}/bin/mpqc-config
  @ONLY
)

# GLOB all the files so they show up in qt_creator
if(USING_QT_CREATOR_AS_IDE)
  file(GLOB_RECURSE QT_CREATOR_SRC 
    "*.h" 
    "*.hpp" 
    "*.cpp" 
    "*.c" 
    "*.txt" 
    "*.in" 
    "*.cc"
    "*.f"
    "TODO"
  )

  add_library(qt_creator_get_sources EXCLUDE_FROM_ALL ${QT_CREATOR_SRC})

  set_target_properties(qt_creator_get_sources PROPERTIES LINKER_LANGUAGE CXX)

endif(USING_QT_CREATOR_AS_IDE)


install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/bin/mpqc-config DESTINATION bin)