-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt.in
124 lines (102 loc) · 4.38 KB
/
CMakeLists.txt.in
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
# this file is mean to be parsed by python before being a proper CMakeLists.txt file
# in particular, the following strings will be set by python
# TODO This package depends on as_cpp_potential from pele which adds
# an unfortunate petsc dependency. This should be fixed.
# ################################### petsc #############################################
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
set(numpy_include __NUMPY_INCLUDE__)
set(PYTHON_INCLUDE_DIRS __PYTHON_INCLUDE__)
set(PYTHON_LDFLAGS "__PYTHON_LDFLAGS__")
set(pele_dir __PELE_INCLUDE__)
# osx makes the suffix for shared object libraries .dylib
IF(APPLE)
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
ENDIF(APPLE)
# BLAS and LAPACK
find_package(BLAS REQUIRED)
find_package(LAPACK REQUIRED)
set(EXT_INSTALL_PATH "${pele_dir}/../extern/install")
# lapacke.h comes with Eigen
set(LAPACKE_INCLUDE_DIR
${EXT_INSTALL_PATH}/include/Eigen/src/misc
CACHE PATH "Location of lapacke include")
message("lapacke include directory: ${LAPACKE_INCLUDE_DIR}")
set(SUNDIALS_INCLUDE_DIR
${EXT_INSTALL_PATH}/include
CACHE PATH "Location of SUNDIALS header files")
if(EXISTS "${EXT_INSTALL_PATH}/lib")
set(SUNDIALS_LIBRARY_DIR
${EXT_INSTALL_PATH}/lib
CACHE PATH "Location of SUNDIALS libraries")
else()
set(SUNDIALS_LIBRARY_DIR
${EXT_INSTALL_PATH}/lib64
CACHE PATH "Location of SUNDIALS libraries")
endif()
# Find the SUNDIALS libraries
find_library(SUNDIALS_SOLVER_LIB
sundials_cvode ${SUNDIALS_LIBRARY_DIR} PATHS ${SUNDIALS_LIBRARY_DIR} NO_DEFAULT_PATH
DOC "CVODE library")
find_library(SUNDIALS_NVEC_LIB
sundials_nvecserial ${SUNDIALS_LIBRARY_DIR} PATHS ${SUNDIALS_LIBRARY_DIR} NO_DEFAULT_PATH
DOC "NVECTOR_SERIAL library")
find_library(SUNDIALS_MANYVEC_LIB
sundials_nvecmanyvector ${SUNDIALS_LIBRARY_DIR} PATHS ${SUNDIALS_LIBRARY_DIR} NO_DEFAULT_PATH
DOC "NVECTOR_MANYVECTOR library")
message("SUNDIALS_LIBRARY_DIR: ${SUNDIALS_LIBRARY_DIR}")
set(SUNDIALS_LIBRARIES
-L${SUNDIALS_LIBRARY_DIR}
${SUNDIALS_SOLVER_LIB}
${SUNDIALS_NVEC_LIB}
${SUNDIALS_MANYVEC_LIB}
${SUNDIALS_EXTRA_LIBS})
message("python include dirs: ${PYTHON_INCLUDE_DIRS}")
message("numpy include dirs: ${numpy_include}")
message("pele include dirs: ${pele_dir}")
include_directories(${numpy_include})
include_directories(SYSTEM ${MPI_INCLUDE_DIR})
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${pele_dir})
include_directories(${LAPACKE_INCLUDE_DIR})
include_directories(${SUNDIALS_INCLUDE_DIR})
cmake_minimum_required(VERSION 2.8)
enable_language(CXX)
SET(CMAKE_CXX_FLAGS __COMPILER_EXTRA_ARGS__)
# cmake_policy(SET CMP0015 NEW)
# set the PyCG_DESCENT include directory
set(PyCG_DESCENT_include ${CMAKE_SOURCE_DIR}/source)
include_directories(${PyCG_DESCENT_include})
message("PyCG_DESCENT include directory: ${PyCG_DESCENT_include}")
# build the PyCG_DESCENT library
FILE(GLOB pele_sources ${PyCG_DESCENT_include}/PyCG_DESCENT/*.cpp)
FILE(GLOB PyCG_DESCENT_sources ${PyCG_DESCENT_include}/CG_DESCENT/*.c*)
add_library(PyCG_DESCENT_lib SHARED ${PyCG_DESCENT_sources} ${pele_sources})
# Apple changed the ld linker in Xcode 15 which breaks the build.
# The classic linker can be chosen with -ld_classic flag.
# However, on older Xcode versions, this flag throws an error.
# Thus, we simply check here whether this flag exists.
# See https://www.scivision.dev/xcode-ld_classic/
# For the undefined flag, see
# https://github.com/nasa/cFE/issues/476#issuecomment-579436106
if(APPLE)
include(CheckLinkerFlag)
check_linker_flag(C "-ld_classic" CLASSIC_FLAG)
if(CLASSIC_FLAG)
set(APPLE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup,-ld_classic")
else(CLASSIC_FLAG)
set(APPLE_LINK_OPTIONS "LINKER:-undefined,dynamic_lookup")
endif(CLASSIC_FLAG)
endif(APPLE)
function(make_cython_lib cython_cxx_source)
get_filename_component(library_name ${cython_cxx_source} NAME)
string(REGEX REPLACE ".cxx$" "" library_name ${library_name})
add_library(${library_name} SHARED ${cython_cxx_source})
target_link_libraries(${library_name} PyCG_DESCENT_lib)
target_link_libraries(${library_name} ${SUNDIALS_LIBRARIES})
target_link_libraries(${library_name} ${LAPACK_LIBRARIES})
if(APPLE)
target_link_options(${library_name} PUBLIC ${APPLE_LINK_OPTIONS})
endif(APPLE)
set_target_properties(${library_name} PROPERTIES PREFIX "")
message("making library ${library_name} from source ${cython_cxx_source}")
endfunction(make_cython_lib)