-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
290 lines (238 loc) · 7.93 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
#
# General
#
cmake_minimum_required(VERSION 3.5)
# Compiler - must be done before "project"
set(WARN_EXC "")
if(COMPILER STREQUAL "gcc")
# enable these flags if you get tons of errors from boost...
#set(WARN_EXC "-Wno-unused-local-typedefs -Wno-maybe-uninitialized")
set(CMAKE_CXX_FLAGS_RELEASE "-flto")
#set(FLTO_FLAGS "-flto") # TODO
set(FLTO_FLAGS "")
SET( CMAKE_CXX_COMPILER "g++" )
SET( CMAKE_C_COMPILER "gcc" )
elseif(COMPILER STREQUAL "clang")
set(FLTO_FLAGS "") # not supported by clang on most platforms
SET( CMAKE_CXX_COMPILER "clang++" )
SET( CMAKE_C_COMPILER "clang" )
elseif(COMPILER STREQUAL "native")
message("Using native C/C++ compilers.")
else()
message(FATAL_ERROR "Please specify -DCOMPILER=[gcc|clang]")
endif()
project(sca-toolsuite)
SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "0")
SET(VERSION_PATCH "0")
SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
MESSAGE("")
MESSAGE("WELCOME")
MESSAGE("This is the Makefile for ${PROJECT_NAME} ${VERSION}")
MESSAGE("")
MESSAGE("READING CONFIGURATION...")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
# help
# TODO: $myproject from project()
# MESSAGE("This is the Makefile for ${MYPROJECT} (version ${VERSION}).")
# MESSAGE("Options: (-D...=..., cmake -L for details)")
# MESSAGE(" * COMPILER: ${COMPILER} (allowed: [gcc|clang])")
SET(COMPILER "" CACHE STRING "Compiler to use (allowed: [gcc|clang])")
option(WANT_IMAGEMAGICK "Compile files using imagemagick" OFF)
# testing
enable_testing ()
#
# Machine
#
#IF(WIN32)
# SET(OS "win32")
#ELSE(WIN32)
# SET(OS "linux")
#ENDIF(WIN32)
#
#SET(MY_HOST_X86 FALSE)
#SET(MY_HOST_X86_64 FALSE)
#
#IF(IS_X86)
# SET(MY_HOST_X86 TRUE)
# SET(MY_HOST_STR "x86")
#ELSEIF(IS_X86_64)
# SET(MY_HOST_X86_64 TRUE)
# SET(MY_HOST_STR "x86_64")
#ELSE(IS_X86)
# MESSAGE("Can't identify target host. Assuming 32 bit platform.")
# SET(MY_HOST_X86 TRUE)
# SET(MY_HOST_STR "x86")
#ENDIF(IS_X86)
#
#MESSAGE("-- Target host is ${OS}, ${MY_HOST_STR}")
#include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src/res/")
SET(src_base "${CMAKE_CURRENT_SOURCE_DIR}/src/")
SET(res_dir "${src_base}res/")
SET(general "${res_dir}/io.cpp" "${res_dir}/io.h" "${res_dir}/general.h" "${res_dir}/general.cpp" "${res_dir}/random.h")
SET(geometry "${res_dir}/geometry.h" "${res_dir}/geometry.cpp")
SET(eq_solver "${res_dir}/equation_solver.cpp" "${res_dir}/equation_solver.h" "${res_dir}/eqs_internal.h" "${res_dir}/eqs_functions.cpp" "${res_dir}/eqs_functions.h")
SET(ca "${res_dir}/ca.h" "${res_dir}/ca.cpp")
SET(ca_basics "${res_dir}/ca_basics.h")
SET(image "${res_dir}/image.h" "${res_dir}/image.cpp")
SET(print "${res_dir}/print.h")
SET(sim "${res_dir}/simulate.h" "${res_dir}/simulate.cpp")
function(cp_script script_name)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${script_name}
${CMAKE_CURRENT_BINARY_DIR}/${script_name} COPYONLY)
endfunction()
# expects something like "${src_dir}/math.cpp"
function(compile cpp_name)
get_filename_component(target_path "${cpp_name}" NAME_WE)
add_executable("${target_path}" "${CMAKE_CURRENT_SOURCE_DIR}/${cpp_name}")
target_link_libraries("${target_path}" res)
endfunction()
include_directories("${CMAKE_CURRENT_BINARY_DIR}src/") # for config.h
include_directories("${res_dir}")
#
# special headers
#
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/version.h)
# if(CUSTOM_INCLUDE_PATHS STREQUAL "")
# else()
# include_directories("${CUSTOM_INCLUDE_PATHS}")
# endif()
#link_directories("${ADD_LINK_DIRS}")
# INCLUDE (CheckIncludeFiles)
# add the command to generate the source code
add_custom_command (
OUTPUT _sza2
COMMAND echo ${VERSION} > ${CMAKE_CURRENT_BINARY_DIR}/sza2
)
add_custom_target (
sza2
DEPENDS _sza2
)
MESSAGE("CHECKING FOR LIBRARIES...")
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.46.0
REQUIRED
COMPONENTS graph)
find_package(Qt5
COMPONENTS Widgets)
if(Qt5_FOUND)
set(BUILD_QT_GUI true)
else(Qt5_FOUND)
set(BUILD_QT_GUI false)
endif(Qt5_FOUND)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/usr/CMakeLists.txt")
set(BUILD_USR_DIR true)
else()
set(BUILD_USR_DIR false)
endif()
find_package(ImageMagick COMPONENTS MagickCore Magick++)
if(ImageMagick_FOUND AND WANT_IMAGEMAGICK)
set(BUILD_IMG_MAGICK true)
else()
set(BUILD_IMG_MAGICK false)
endif()
#if(Boost_FOUND)
# include_directories(${Boost_INCLUDE_DIRS})
# add_executable(progname file1.cxx file2.cxx)
# target_link_libraries(progname ${Boost_LIBRARIES})
#endif()
#
# Compile
#
#if(LFTO STREQUAL "1")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
message(FATAL_ERROR "Please set -DCMAKE_BUILD_TYPE=[Debug|Release]")
endif()
endif()
# FLAGS
# the order of -Wall -Wno-unknown-pragmas is important
# TODO: -Werror
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-implicit-fallthrough ${WARN_EXC} -std=c++11 -pipe -march=native -mtune=native")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 ${FLTO_FLAGS}")
# add profiling for gcc:
if(COMPILER STREQUAL "gcc")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
endif()
MESSAGE("READING SUB-DIRECTORIES...")
add_subdirectory(src)
add_subdirectory(doc)
#find_package(Doxygen) # TODO: wrong place
#target_link_libraries(calc ...)
#add_test (test sh ${CMAKE_CURRENT_BINARY_DIR}/src/test.sh)
#TODO: use cmake instead of sh script?
#
# CPack Stuff
#
SET(MY_NAME_CAP ${PROJECT_NAME})
#SET(MY_NAME_LOW ${PROJECT_NAME}) # (TODO: tolower)
STRING(TOLOWER ${MY_NAME_CAP} MY_NAME_LOW)
#SET(MY_PACKAGE_FILE_NAME "${MY_NAME_LOW}-${VERSION}-${OS}-${MY_HOST_STR}")
SET(MY_PACKAGE_FILE_NAME "${MY_NAME_LOW}-${VERSION}")
SET(MY_SRC_PACKAGE_FILE_NAME "${MY_NAME_LOW}-${VERSION}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${MY_NAME_CAP} - sca cellular automata toolsuite")
IF(WIN32)
SET(CPACK_PACKAGE_EXECUTABLES "${MY_NAME_LOW}.exe")
ELSE(WIN32)
SET(CPACK_PACKAGE_EXECUTABLES "${MY_NAME_LOW}")
SET(CPACK_STRIP_FILES "bin/${MY_NAME_LOW}") # TODO: bin?
ENDIF(WIN32)
SET(CPACK_PACKAGE_FILE_NAME ${MY_PACKAGE_FILE_NAME})
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${MY_SRC_PACKAGE_FILE_NAME}")
SET(CPACK_PACKAGE_VENDOR "${MY_NAME_CAP} Developers")
SET(CPACK_PACKAGE_VERSION ${VERSION})
SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
SET(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE.txt")
SET(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
SET(CPACK_SOURCE_GENERATOR "TBZ2")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${MY_SRC_PACKAGE_FILE_NAME}")
INCLUDE(CPack)
#
# Summary
#
MESSAGE("")
MESSAGE("SUMMARY:")
MESSAGE(" * Project: ${PROJECT_NAME} ${VERSION}")
MESSAGE(" * Compilers Used: ${COMPILER} (${CMAKE_CXX_COMPILER}, ${CMAKE_CC_COMPILER})")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(MSG_BUILD_TYPE_FLAG ${CMAKE_CXX_FLAGS_DEBUG})
else()
set(MSG_BUILD_TYPE_FLAG ${CMAKE_CXX_FLAGS_RELEASE})
endif()
MESSAGE(" * Build Type: ${CMAKE_BUILD_TYPE} (${MSG_BUILD_TYPE_FLAG})")
if(BUILD_QT_GUI)
set(MSG_QT_FOUND "Yes")
else(BUILD_QT_GUI)
set(MSG_QT_FOUND "No - install Qt if you want")
endif(BUILD_QT_GUI)
MESSAGE(" * Build Qt GUI: ${MSG_QT_FOUND}")
if(BUILD_USR_DIR)
set(MSG_USR_FOUND "Yes - Found source files")
else(BUILD_USR_DIR)
set(MSG_USR_FOUND "No - No usr dir in /src")
endif(BUILD_USR_DIR)
MESSAGE(" * Build USR DIR: ${MSG_USR_FOUND}")
if(BUILD_IMG_MAGICK)
set(MSG_IM_FOUND "Yes - Found Magick++")
else(BUILD_IMG_MAGICK)
set(MSG_IM_FOUND "No - No Magick++ found")
endif(BUILD_IMG_MAGICK)
MESSAGE(" * Build ImageMagick components: ${MSG_IM_FOUND}")
if(DOXYGEN_FOUND)
set(MSG_DOXY_FOUND "No - Type make doc if you want")
else(DOXYGEN_FOUND)
set(MSG_DOXY_FOUND "No - No Doxygen found")
endif(DOXYGEN_FOUND)
MESSAGE(" * Building Doc: ${MSG_DOXY_FOUND}")
MESSAGE(" * Executing Tests: No - Type make test if you want")
MESSAGE("")
MESSAGE("Now, type make and pray...")
MESSAGE("")