-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCMakeLists.txt
163 lines (148 loc) · 4.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
#
# Minimum cmake version:
# Setting C++ standard seems to require at least 3.7
#
cmake_minimum_required(VERSION 3.7 FATAL_ERROR)
#
# Set project name and language
#
project(hbtplus)
enable_language(CXX)
#
# Set default build mode to Release
#
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build (e.g. Debug, Release)" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
#
# Store library paths in executables
#
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
#
# Put executables directly in build directory
#
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
#
# Find OpenMP flag for this compiler, if necessary
#
option(HBT_USE_OPENMP "Whether to enable OpenMP support" ON)
if(HBT_USE_OPENMP)
find_package(OpenMP)
if(OPENMP_FOUND)
add_compile_options(${OpenMP_CXX_FLAGS})
link_libraries(${OpenMP_CXX_FLAGS})
else(OPENMP_FOUND)
error("Unable to find OpenMP flag for this compiler")
endif(OPENMP_FOUND)
else(HBT_USE_OPENMP)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
# Suppress warnings about unrecognised '#pragma omp' from Intel compiler
add_compile_options("-diag-disable 3180")
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
endif(HBT_USE_OPENMP)
#
# Find MPI libraries for C++
#
find_package(MPI COMPONENTS CXX REQUIRED)
add_definitions(${MPI_CXX_COMPILE_FLAGS})
include_directories(${MPI_CXX_INCLUDE_PATH})
link_directories(${MPI_CXX_LIBRARIES})
#
# Find HDF5 library
#
find_package(HDF5 COMPONENTS CXX HL REQUIRED)
include_directories(${HDF5_INCLUDE_DIRS})
link_directories(${HDF5_LIBRARY_DIRS})
#
# Find GSL library (optional)
#
option(HBT_USE_GSL "Enable to use GSL for eigenvalue decomposition of inertial tensors" OFF)
if(HBT_USE_GSL)
find_package(GSL)
if(GSL_FOUND)
include_directories(${GSL_INCLUDE_DIRS})
link_directories(${GSL_LIBRARY_DIRS})
add_definitions(-DHAS_GSL)
else(GSL_FOUND)
error("Unable to find GSL library")
endif(GSL_FOUND)
endif(HBT_USE_GSL)
#
# List of HBT source files.
# Headers are found automatically by cmake.
#
set(HBT_SRC
HBT.cpp
src/config_parser.cpp
src/geometric_tree.cpp
src/gravity_tree.cpp
src/halo.cpp
src/hdf_wrapper.cpp
src/linkedlist_base.cpp
src/linkedlist.cpp
src/mpi_wrapper.cpp
src/mymath.cpp
src/particle_exchanger.cpp
src/snapshot.cpp
src/snapshot_exchanger.cpp
src/subhalo.cpp
src/subhalo_merge.cpp
src/subhalo_tracking.cpp
src/subhalo_unbind.cpp
src/io/apostle_io.cpp
src/io/gadget_group_io.cpp
src/io/gadget_io.cpp
src/io/halo_io.cpp
src/io/snapshot_io.cpp
src/io/subhalo_io.cpp
)
#
# Specify which C++ standard we need
#
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
#
# Function for defining optional features
#
function(hbt_option NAME DEFINE DESCRIPTION DEFAULT)
option(${NAME} ${DESCRIPTION} ${DEFAULT})
if(${NAME})
add_definitions(-D${DEFINE})
endif(${NAME})
endfunction()
#
# Optional features:
#
# CMake option name Preprocessor macro Description Default
hbt_option(HBT_DM_ONLY DM_ONLY "Enable to save memory in DMONLY runs" OFF)
hbt_option(HBT_INPUT_INT8 INPUT_INT8 "Enable to read 8 byte integers from input files" ON)
hbt_option(HBT_INT8 HBT_INT8 "Enable to use 8 byte integers" ON)
hbt_option(HBT_REAL8 HBT_REAL8 "Enable to use 8 byte reals" OFF)
hbt_option(HBT_UNSIGNED_LONG_ID_OUTPUT UNSIGNED_LONG_ID_OUTPUT "Enable to output IDs as unsigned long" ON)
#
# HBT executable
#
add_executable(HBT ${HBT_SRC})
target_link_libraries(HBT ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} ${GSL_LIBRARIES} ${MPI_CXX_LIBRARIES})
#
# Hide some variables we usually don't need from the default view in the cmake GUI
#
mark_as_advanced(HDF5_DIR)
mark_as_advanced(HDF5_CXX_LIBRARY_dl)
mark_as_advanced(HDF5_CXX_LIBRARY_hdf5)
mark_as_advanced(HDF5_CXX_LIBRARY_hdf5_cpp)
mark_as_advanced(HDF5_CXX_LIBRARY_hdf5_hl)
mark_as_advanced(HDF5_CXX_LIBRARY_hdf5_hl_cpp)
mark_as_advanced(HDF5_CXX_LIBRARY_m)
mark_as_advanced(HDF5_CXX_LIBRARY_rt)
mark_as_advanced(HDF5_CXX_LIBRARY_z)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
#
# Show C++ compiler flags in default view
#
mark_as_advanced(CLEAR CMAKE_CXX_FLAGS)
mark_as_advanced(CLEAR CMAKE_CXX_FLAGS_RELEASE)
mark_as_advanced(CLEAR CMAKE_CXX_FLAGS_DEBUG)