-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
173 lines (148 loc) · 6.24 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
cmake_minimum_required(VERSION 2.6)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
SET(CMAKE_CXX_FLAGS " -fPIC -D_FILE_OFFSET_BITS=64 ${CMAKE_CXX_FLAGS}")
endif()
# ----------------------------------------------------------------------------
# OpenMP (optional for shared memory multiprocessing)
# ----------------------------------------------------------------------------
option(ENABLE_OPENMP "OpenMP for multithreading" ON)
if(ENABLE_OPENMP)
include(FindOpenMP)
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(OPENMP_FOUND)
endif(ENABLE_OPENMP)
# ----------------------------------------------------------------------------
# ROOT
# ----------------------------------------------------------------------------
option(QUIMBY_ENABLE_ROOT "ENABLE ROOT Output" off)
if (QUIMBY_ENABLE_ROOT)
FIND_PROGRAM(ROOT_CONFIG root-config REQUIRED ROOT_CONFIG_PATH)
execute_process(COMMAND ${ROOT_CONFIG} "--cflags" OUTPUT_VARIABLE ROOT_CFLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${ROOT_CONFIG} "--libs" OUTPUT_VARIABLE ROOT_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
if(ROOT_CFLAGS AND ROOT_LIBS)
message(STATUS "ROOT found!")
message(STATUS " CFLAGS: ${ROOT_CFLAGS}")
message(STATUS " LIBS: ${ROOT_LIBS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ROOT_CFLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${ROOT_LIBS}")
add_definitions(-DQUIMBY_ROOT_ENABLED)
else()
set(QUIMBY_ENABLE_ROOT Off)
endif()
endif()
# ----------------------------------------------------------------------------
# Quimby
# ----------------------------------------------------------------------------
include_directories (include)
add_library( quimby-lib
src/Database.cpp
src/GadgetFile.cpp
src/MagneticField.cpp
src/MMapFile.cpp
src/tga.cpp
)
SET_TARGET_PROPERTIES(quimby-lib PROPERTIES OUTPUT_NAME "Quimby")
add_executable( quimby-tool
tool/main
tool/arguments
tool/bfieldtest
tool/paged_grid
tool/mass
tool/sph
tool/sph-dump
tool/database
)
SET_TARGET_PROPERTIES(quimby-tool PROPERTIES OUTPUT_NAME "quimby")
add_dependencies(quimby-tool quimby-lib)
target_link_libraries (quimby-tool quimby-lib)
INSTALL(TARGETS quimby-tool RUNTIME DESTINATION bin)
INSTALL(TARGETS quimby-lib DESTINATION lib)
INSTALL(DIRECTORY include/ DESTINATION include
FILES_MATCHING PATTERN "*.h")
if(UNIX)
SET(QUIMBY_PREFIX ${CMAKE_INSTALL_PREFIX})
SET(QUIMBY_LIBRARY ${CMAKE_INSTALL_PREFIX}/lib/libQuimby.a)
SET(QUIMBY_PREFIX ${CMAKE_SOURCE_DIR})
SET(QUIMBY_LIBRARY ${CMAKE_BINARY_DIR}/libQuimby.a)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif(UNIX)
# ----------------------------------------------------------------------------
# Testing
# ----------------------------------------------------------------------------
option(QUIMBY_ENABLE_TESTING "Build unit tests" OFF)
if(QUIMBY_ENABLE_TESTING)
enable_testing()
add_executable(pg_test test/pg_test.cpp)
add_executable(mf_test test/mf_test.cpp)
add_executable(coma_profile test/coma_profile.cpp)
target_link_libraries(coma_profile quimby-lib)
add_executable(benchmark test/benchmark.cpp)
target_link_libraries(benchmark quimby-lib)
add_executable(database_test test/database_test.cpp)
target_link_libraries(database_test quimby-lib)
add_executable(hcube_test test/hcube_test.cpp)
target_link_libraries(hcube_test quimby-lib)
add_executable(sph_grid_test test/sph_grid_test.cpp)
target_link_libraries(mf_test quimby-lib)
target_link_libraries(sph_grid_test quimby-lib)
ADD_TEST(mf mf_test)
ADD_TEST(pg pg_test)
ADD_TEST(sph_grid sph_grid_test)
endif()
# ----------------------------------------------------------------------------
# Python
# ----------------------------------------------------------------------------
option(QUIMBY_ENABLE_PYTHON "Create python library via SWIG" ON)
if(QUIMBY_ENABLE_PYTHON)
include(python/Python.cmake)
include_directories(${PYTHON_INCLUDE_PATH})
option(ENABLE_SWIG_BUILTIN "Use SWIG's -builtin option" ON)
if(ENABLE_SWIG_BUILTIN)
set(BUILTIN "-builtin")
set(PY3 "-py3")
else(ENABLE_SWIG_BUILTIN)
set(BUILTIN "")
set(PY3 "")
endif(ENABLE_SWIG_BUILTIN)
file(GLOB_RECURSE QUIMBY_INCLUDES include/*.h)
set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/quimby_wrap.cxx PROPERTIES GENERATED true )
add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/quimby_wrap.cxx
COMMAND swig ${BUILTIN} -c++ -python ${PY3} ${QUIMBY_SWIG_DEFINES} -I${CMAKE_SOURCE_DIR}/include -o ${CMAKE_CURRENT_BINARY_DIR}/quimby_wrap.cxx -outdir ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}/python/quimby.i
DEPENDS ${CMAKE_SOURCE_DIR}/python/quimby.i DEPENDS ${QUIMBY_INCLUDES} )
add_library(quimby-swig MODULE ${CMAKE_CURRENT_BINARY_DIR}/quimby_wrap.cxx)
set_target_properties(quimby-swig PROPERTIES PREFIX "")
set_target_properties(quimby-swig PROPERTIES OUTPUT_NAME "_quimby")
target_link_libraries(quimby-swig quimby-lib ${PYTHON_LIBRARY})
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/quimby.py" DESTINATION ${PYTHON_SITE_PACKAGES})
install(TARGETS quimby-swig LIBRARY DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES python/quimby.i DESTINATION share/quimby)
endif()
# ----------------------------------------------------------------------------
# Print feature overview
# ----------------------------------------------------------------------------
message(STATUS "Features:")
if(QUIMBY_ENABLE_ROOT)
message(STATUS " ROOT: Yes")
else()
message(STATUS " ROOT: No")
endif()
if(QUIMBY_ENABLE_PYTHON)
message(STATUS " Python: Yes")
else()
message(STATUS " Python: No")
endif()
if(QUIMBY_ENABLE_TESTING)
message(STATUS " Testing: Yes")
else()
message(STATUS " Testing: No")
endif()