-
Notifications
You must be signed in to change notification settings - Fork 30
/
CMakeLists.txt
206 lines (167 loc) · 7.56 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
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
# Root CMake configuration for OpenMalaria
# Copyright © 2005-2013 Swiss Tropical Institute and Liverpool School Of Tropical Medicine
# Licence: GNU General Public Licence version 2 or later (see COPYING)
cmake_minimum_required (VERSION 3.5)
project (OpenMalaria CXX)
# The FindXXX.cmake files included are not quite the same as standard ones.
# They abort if not found, and look in a few extra places (e.g. ${CMAKE_SOURCE_DIR}/lib).
set (CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# ----- Compile options -----
set(CMAKE_CXX_STANDARD 17)
set (OM_STD_LIBS)
# -D_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
# auto_ptr has been removed from c++17
# This extension is needed because XSD still use auto_ptr in its headers
# Note that is doe snot use auto_ptr in the generated code, only in the library headers
if (NOT MSVC)
# Enable builds on Raspberry pi (although without optimizations)
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
else (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -msse2 -mfpmath=sse")
endif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^arm")
# We almost always want optimisations enabled:
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O2")
endif (NOT MSVC)
if (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fp-model strict")
endif (CMAKE_CXX_COMPILER_ID MATCHES "Intel")
# Statically link libgcc; isn't going to work when other C++ libraries are dynamically linked
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
# This doesn't show up in the cache, but it is passed to gcc:
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -D_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR")
option (OM_COVERAGE "Produce coverage into binary.")
if (OM_COVERAGE)
# Add coverage
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
endif (OM_COVERAGE)
option (OM_STATICALLY_LINK "Attempt to link libraries, including stdc++, statically.")
if (OM_STATICALLY_LINK)
link_directories (${CMAKE_SOURCE_DIR}/lib)
# Note: -static-libstdc++ is only available since GCC 4.5
# See: http://www.trilithium.com/johan/2005/06/static-libstdc/
add_definitions(-static-libgcc -static-libstdc++)
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -static-libgcc -static-libstdc++")
endif (OM_STATICALLY_LINK)
endif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
option (BUILD_SHARED_LIBS "Link xsdcxx, model, etc. libraries dynamically instead of statically (almost certainly not wanted)." OFF)
mark_as_advanced (BUILD_SHARED_LIBS)
if (MSVC)
# We almost always want optimisations enabled:
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /O2")
# This is now the OM_STATICALLY_LINK for windows
option (OM_USE_LIBCMT "Use LIBCMT.lib instead of MSVCRT[D].lib when linking, and link statically. This removes a dependency on a .net library, but usually requires manually building dependency libraries." OFF)
# set a temporary variable, since cache variables don't get rewritten
if (OM_USE_LIBCMT)
#piece of code from http://stackoverflow.com/questions/1618927/cmake-microsoft-visual-studio-and-monolithic-runtimes
#Note: doesn't update cmake cache (but still works)
#We statically link to reduce dependancies
foreach(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag_var} MATCHES "/MDd")
string(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MDd")
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
set (OM_LINK_FLAGS "/NODEFAULTLIB:MSVCRT /NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:library")
set (OM_COMPILE_FLAGS "/DXERCES_STATIC_LIBRARY")
else (OM_USE_LIBCMT)
set (OM_LINK_FLAGS "/NODEFAULTLIB:LIBCMT")
set (OM_COMPILE_FLAGS)
endif (OM_USE_LIBCMT)
set (OM_COMPILE_FLAGS "${OM_COMPILE_FLAGS} /D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS")
endif (MSVC)
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -D_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR")
# These are actually only needed when using "clang" not "clang++" (same with
# "gcc"), but adding here saves a user error:
set (OM_STD_LIBS m stdc++)
endif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -D_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR")
# These are actually only needed when using "clang" not "clang++" (same with
# "gcc"), but adding here saves a user error:
set (OM_STD_LIBS m stdc++)
endif("${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang")
# ----- Find dependencies -----
set (CMAKE_LIBRARY_PATH /usr/lib64)
find_package (XSD)
find_package (XercesC)
find_package (GSL)
find_package (Z)
find_package (Python)
if (NOT PYTHON_EXECUTABLE)
message (SEND_ERROR "Unable to find a Python interpreter (required).")
endif (NOT PYTHON_EXECUTABLE)
# ----- Compile-time optional features -----
# (must come before add_subdirectory (model))
option (OM_STREAM_VALIDATOR "Compile in StreamValidator (see model/util/StreamValidator.h for usage notes)" OFF)
if (OM_STREAM_VALIDATOR)
add_definitions (-DOM_STREAM_VALIDATOR)
endif (OM_STREAM_VALIDATOR)
# ----- Compile code -----
add_subdirectory (contrib)
add_subdirectory (schema)
add_subdirectory (model)
# add_subdirectory (util/SchemaTranslator)
add_dependencies (model schema)
# ----- generate openMalaria -----
if (UNIX)
find_library (PTHREAD_LIBRARIES pthread PATHS ${CMAKE_SOURCE_DIR}/lib /usr/lib /usr/local/lib)
if (NOT PTHREAD_LIBRARIES)
message (SEND_ERROR "PThread library not found")
endif (NOT PTHREAD_LIBRARIES)
endif (UNIX)
mark_as_advanced (PTHREAD_LIBRARIES)
include_directories (SYSTEM
${XSD_INCLUDE_DIRS}
${XERCESC_INCLUDE_DIRS}
${GSL_INCLUDE_DIRS}
${Z_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/contrib
)
include_directories (
${CMAKE_SOURCE_DIR}/model ${CMAKE_BINARY_DIR}
)
add_executable (openMalaria model/main.cpp)
target_link_libraries (openMalaria
model
schema
contrib
${GSL_LIBRARIES}
${XERCESC_LIBRARIES}
${Z_LIBRARIES}
${PTHREAD_LIBRARIES}
${OM_STD_LIBS}
)
if (MSVC)
set_target_properties (openMalaria PROPERTIES
LINK_FLAGS "${OM_LINK_FLAGS}"
COMPILE_FLAGS "${OM_COMPILE_FLAGS}"
)
endif (MSVC)
# Dependencies from outside this repository are linked dynamically. Since we
# cannot be sure deployment systems have the same versions, we copy the ones
# from the build system, and add an rpath entry to link from the current dir.
option (OM_COPY_LIBS "Copy linked library files")
if (OM_COPY_LIBS)
set_target_properties (openMalaria PROPERTIES
LINK_FLAGS "-Wl,-rpath,\"\$ORIGIN\"")
foreach (lib ${GSL_LIBRARIES} ${XERCESC_LIBRARIES} ${Z_LIBRARIES})
configure_file (${lib} ${CMAKE_BINARY_DIR} COPYONLY)
endforeach (lib)
endif (OM_COPY_LIBS)
# add_executable (pVivax model/Pv_mod/Source.cpp)
# target_link_libraries (pVivax libpvivax)
# ----- OM_BOXTEST - black-box & unit testing -----
option(OM_CXXTEST_ENABLE "Enable lower-level unittests using cxx (use 'make test' or Visual Studio build target)test" ON)
if (OM_CXXTEST_ENABLE)
enable_testing()
add_subdirectory (unittest)
endif (OM_CXXTEST_ENABLE)
option(OM_BOXTEST_ENABLE "Enable black-box testing of openMalaria (use 'make test' or Visual Studio build target)" ON)
if (OM_BOXTEST_ENABLE)
enable_testing()
add_subdirectory (test)
endif (OM_BOXTEST_ENABLE)