-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
138 lines (109 loc) · 5.07 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
cmake_minimum_required(VERSION 3.10.1)
include(GNUInstallDirs)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose type of build (Debug or Release)")
endif(NOT CMAKE_BUILD_TYPE)
set(ENABLE_PLOTTER 0 CACHE BOOL "Build plotting class. Requires SFML 2.x!")
set(BUILD_DOCUMENTATION 0 CACHE BOOL "Build documentation with Doxygen.")
project(SandpileSimulator VERSION 0.2.0)
set(EXECUTABLE_NAME ${PROJECT_NAME})
set(BUILD_SHARED_LIBS ON)
if(BUILD_DOCUMENTATION)
find_package(Doxygen)
endif()
if(ENABLE_PLOTTER)
find_package(SFML 2 REQUIRED graphics system window)
endif(ENABLE_PLOTTER)
set(FILENAMES
argumentparser
aux
avalanche
avalanchestatistics
logger
momentanalysis
noncopyable
randomizer
sandbox
simulationmanager
simulationmodel
simulationmodel_btw
simulationmodel_fwm
)
set(FILENAMES_sfReq
plotter
)
set(FILENAMES_sfMod
simulator
)
set(FILENAMES_hdOnl
version
)
foreach(filename ${FILENAMES})
set(SOURCES "${SOURCES}" "${PROJECT_SOURCE_DIR}/src/sources/${filename}.cpp")
endforeach(filename)
foreach(filename ${FILENAMES_sfReq})
set(FILENAMES ${FILENAMES} ${filename})
if(ENABLE_PLOTTER)
set(SOURCES "${SOURCES}" "${PROJECT_SOURCE_DIR}/src/sources/${filename}.cpp")
endif(ENABLE_PLOTTER)
endforeach(filename)
foreach(filename ${FILENAMES})
set(HEADERS "${HEADERS}" "${filename}.h")
configure_file("${PROJECT_SOURCE_DIR}/src/headers/${filename}.h" "${PROJECT_BINARY_DIR}/include/${filename}.h" COPYONLY)
endforeach(filename)
foreach(filename ${FILENAMES_hdOnl})
set(HEADERS "${HEADERS}" "${filename}.h")
configure_file("${PROJECT_SOURCE_DIR}/src/headers/${filename}.h" "${PROJECT_BINARY_DIR}/include/${filename}.h" COPYONLY)
endforeach(filename)
#Always include these, but headers need to be configured
foreach(filename ${FILENAMES_sfMod})
set(HEADERS "${HEADERS}" "${filename}.h")
set(SOURCES "${SOURCES}" "${PROJECT_SOURCE_DIR}/src/sources/${filename}.cpp")
configure_file("${PROJECT_SOURCE_DIR}/src/headers/${filename}.in.h" "${PROJECT_BINARY_DIR}/include/${filename}.h" @ONLY)
endforeach(filename)
set(LIB_SOURCES "${SOURCES}")
set(SOURCES "${SOURCES}" "${PROJECT_SOURCE_DIR}/src/sources/main.cpp")
add_executable("${EXECUTABLE_NAME}-bin" ${SOURCES})
add_library("${EXECUTABLE_NAME}-lib" ${LIB_SOURCES})
set_target_properties("${EXECUTABLE_NAME}-bin" "${EXECUTABLE_NAME}-lib" PROPERTIES OUTPUT_NAME ${EXECUTABLE_NAME})
set_target_properties("${EXECUTABLE_NAME}-lib" PROPERTIES VERSION ${PROJECT_VERSION})
include_directories("${PROJECT_BINARY_DIR}/include")
set(LINKER_FLAGS_REQUIRED "-pthread -lgslcblas -lgsl -lm")
if(ENABLE_PLOTTER)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries("${EXECUTABLE_NAME}-bin" ${SFML_LIBRARIES} ${SFML_DEPENDENCIES})
set(LINKER_FLAGS_REQUIRED "${LINKER_FLAGS_REQUIRED} -lsfml-graphics -lsfml-system -lsfml-window")
endif(ENABLE_PLOTTER)
set(LINKER_FLAGS_REQUIRED "${LINKER_FLAGS_REQUIRED}" CACHE STRING "Linker flags that are required to link the dependencies." FORCE)
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_LINKER "g++")
set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS "" CACHE STRING "" FORCE)
set(CXX_FLAGS_RELEASE "-pipe -O2 -march=corei7 -mtune=native -fstack-protector-strong -fno-plt -fPIC -std=c++17 -Wall -Wextra -fopenmp"
CACHE STRING "Flags used by the compiler for release builds.")
set(CXX_FLAGS_DEBUG "-pipe -O0 -ggdb -march=corei7 -mtune=native -fstack-protector-strong -fno-plt -fPIC -std=c++17 -Wall -Wextra -fopenmp"
CACHE STRING "Flags used by the compiler for debug builds.")
set(LINKER_FLAGS_RELEASE "-Wl,-O1"
CACHE STRING "Some flags used by the linker for release builds.")
set(LINKER_FLAGS_DEBUG "-Wl,-O1"
CACHE STRING "Some flags used by the linker for debug builds.")
set(CMAKE_CXX_FLAGS_RELEASE "${CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG "${CXX_FLAGS_DEBUG}")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${LINKER_FLAGS_RELEASE} ${LINKER_FLAGS_REQUIRED}")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${LINKER_FLAGS_DEBUG} ${LINKER_FLAGS_REQUIRED}")
if(BUILD_DOCUMENTATION AND DOXYGEN_FOUND)
set(doxyfile_in "${PROJECT_SOURCE_DIR}/doc/Doxyfile.in")
set(doxyfile "${PROJECT_BINARY_DIR}/Doxyfile")
set(TEMPLATE_DIR "${PROJECT_SOURCE_DIR}/doc/template")
set(HEADERS_DIR "${PROJECT_BINARY_DIR}/include")
set(SOURCES_DIR "${PROJECT_SOURCE_DIR}/src/sources")
configure_file("${doxyfile_in}" "${doxyfile}" @ONLY)
add_custom_target(Documentation ALL ${DOXYGEN_EXECUTABLE} "${doxyfile}" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" VERBATIM)
endif()
install(TARGETS "${EXECUTABLE_NAME}-bin" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS "${EXECUTABLE_NAME}-lib" LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY "${PROJECT_BINARY_DIR}/include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
if(BUILD_DOCUMENTATION AND DOXYGEN_FOUND)
install(DIRECTORY "${PROJECT_BINARY_DIR}/doc/" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/doc")
endif()