-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
134 lines (112 loc) · 4.99 KB
/
CMakeLists.txt
File metadata and controls
134 lines (112 loc) · 4.99 KB
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
# This must be called before project() since it sets this variable as empty into the cache
set(CMAKE_BUILD_TYPE Release CACHE STRING "Type of build to create, Release (optimized) by default")
project("template")
cmake_minimum_required(VERSION 3.2)
# Version number
set(TEMPLATE_VERSION "1.0.0")
# Global setting: Use C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Conda has a separate set of debug flags defined, which is more than just
# adding a -g. If we are doing a debug rather than release build, use those
# flags if we find them.
set(DEBUG_CXXFLAGS "$ENV{DEBUG_CXXFLAGS}" CACHE STRING "Flags to use in Debug")
set(DEBUG_CFLAGS "$ENV{DEBUG_CFLAGS}" CACHE STRING "Flags to use in Debug")
set(DEBUG_FFLAGS "$ENV{DEBUG_FFLAGS}" CACHE STRING "Flags to use in Debug")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(DEBUG_CXXFLAGS)
set(CMAKE_CXX_FLAGS "${DEBUG_CXXFLAGS}")
endif(DEBUG_CXXFLAGS)
if(DEBUG_CFLAGS)
set(CMAKE_C_FLAGS "${DEBUG_CFLAGS}")
endif(DEBUG_CFLAGS)
if(DEBUG_FFLAGS)
# Suppress warning about comparing reals. This is often a bad thing
# to do, but the fortran code we have does this the "right" way, e.g.
# checking for identical to zero as a flag value.
set(CMAKE_Fortran_FLAGS "${DEBUG_FFLAGS} -Wno-compare-reals")
endif(DEBUG_FFLAGS)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
# By default install into the build directory
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "..." FORCE)
message(STATUS "Setting install prefix to: " ${CMAKE_INSTALL_PREFIX})
message(STATUS "Specify -DCMAKE_INSTALL_PREFIX to cmake to change")
else()
message(STATUS "Using install prefix: " ${CMAKE_INSTALL_PREFIX})
endif()
set(THIRDPARTY_LIBRARIES "")
set(THIRDPARTY_INCLUDES "")
# Find ReFRACTOR
find_package(Refractor
REQUIRED COMPONENTS python
CONFIG
HINTS ${REFRACTOR_DIR} ${CONDA_PREFIX})
list(APPEND THIRDPARTY_INCLUDES ${REFRACTOR_INCLUDE_DIRS})
list(APPEND THIRDPARTY_LIBRARIES ${REFRACTOR_LIBRARIES})
list(APPEND THIRDPARTY_LIBRARIES ${REFRACTOR_PYTHON_LIBRARIES})
# Insert the ReFRACtor cmake modules directory at the beginning of
# our search path so we can override built in modules with updated
# copies and to enable the finding of additional packages
if(DEFINED REFRACTOR_DIR)
list(INSERT CMAKE_MODULE_PATH 0 "${REFRACTOR_DIR}/cmake/Modules/")
else()
# If not otherwise pointed to a different directory, use CONDA_PREFIX
# if defined
if(DEFINED ENV{CONDA_PREFIX})
list(INSERT CMAKE_MODULE_PATH 0 "$ENV{CONDA_PREFIX}/cmake/Modules/")
endif(DEFINED ENV{CONDA_PREFIX})
endif(DEFINED REFRACTOR_DIR)
# Find Blitz++
find_package(Blitz REQUIRED)
list(APPEND THIRDPARTY_INCLUDES ${BLITZ_INCLUDE_DIR})
list(APPEND THIRDPARTY_LIBRARIES ${BLITZ_LIBRARIES})
# Find HDF5
find_package(HDF5 REQUIRED COMPONENTS C CXX)
# Different versions of FindHDF5 may use one or the other of these variable names, with
# newer versions saying that HDF5_C_INCLUDE_DIRS deprecates the other
if(HDF5_C_INCLUDE_DIRS)
list(APPEND THIRDPARTY_INCLUDES ${HDF5_C_INCLUDE_DIRS})
else()
list(APPEND THIRDPARTY_INCLUDES ${HDF5_C_INCLUDE_DIR})
endif()
list(APPEND THIRDPARTY_LIBRARIES ${HDF5_LIBRARIES})
include_directories(${THIRDPARTY_INCLUDES})
# Find Boost
# We want to use the Conda version if it is available, and the user hasn't
# otherwise specified a different version
if(NOT BOOST_ROOT AND DEFINED ENV{CONDA_PREFIX})
set(BOOST_ROOT $ENV{CONDA_PREFIX})
endif(NOT BOOST_ROOT AND DEFINED ENV{CONDA_PREFIX})
find_package(Boost REQUIRED COMPONENTS system)
list(APPEND THIRDPARTY_INCLUDES ${Boost_INCLUDE_DIRS})
list(APPEND THIRDPARTY_LIBRARIES ${Boost_LIBRARIES})
# When we are using debug mode, turn on the blitz range checking.
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DBZ_DEBUG")
if(POLICY CMP0068)
cmake_policy(SET CMP0068 NEW)
endif()
# use, i.e. don't skip the full RPATH for the build tree
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# For some reason on the Mac we don't automatically figure out that CONDA
# should be on the rpath. So add that. This seems like a bug, the reading of
# CMAKE_INSTALL_RPATH_USE_LINK_PATH seems to indicate it should do this
# automatically. But it doesn't, so go ahead and set this
if(DEFINED ENV{CONDA_PREFIX})
list(APPEND CMAKE_INSTALL_RPATH "$ENV{CONDA_PREFIX}/lib")
endif(DEFINED ENV{CONDA_PREFIX})
# 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)
include_directories(${THIRDPARTY_INCLUDES})
add_subdirectory(lib)
add_subdirectory(python)
enable_testing()
add_subdirectory(test)
# Configure setup shell script to have appropriate paths and install
configure_file (
"${PROJECT_SOURCE_DIR}/script/setup_template_env.sh.in"
"${PROJECT_BINARY_DIR}/setup_template_env.sh"
)
install(FILES "${PROJECT_BINARY_DIR}/setup_template_env.sh" DESTINATION "${CMAKE_INSTALL_PREFIX}")