forked from marekpetrik/CRAAM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
168 lines (139 loc) · 5.98 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
# Build a debug or release version
# Debug:
# cmake -DCMAKE_BUILD_TYPE=Debug .
# Release:
# cmake -DCMAKE_BUILD_TYPE=Release .
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # Required for C++11 support
set(VERSION "1.0.0")
project(CRAAM)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED)
# **** Build type ****
if (NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(IS_DEBUG TRUE)
endif ()
# **** Find packages ****
find_package(OpenMP)
find_package(Boost COMPONENTS unit_test_framework) # CMake does not detect header-only packages. Also needs uBlas and format
find_package(Doxygen)
if (${Boost_FOUND} LESS 1)
message(WARNING "Unit tests (testit) require Boost unit test library and may not compile.")
endif ()
# DEBUG
# Prints all variables (for debugging)
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
# DEBUG
#set(CMAKE_VERBOSE_MAKEFILE on) - just run make
# **** TURN FEATURES ON AND OFF ****
option(BUILD_TESTS "Build tests (requires Boost)" ON)
option(BUILD_DOCUMENTATION "Build source code documentation" ${DOXYGEN_FOUND})
option(BUILD_ADVANCED "Build advandced functionality beyond pure RMDPs (requires Boost)" ON)
# **** CONFIGURATION ****
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
# use position-independent code
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
# use OpenMP if possible
if (OPENMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()
# set gcc-specific parameters
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.9.0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Wuninitialized")
endif ()
set(CMAKE_CXX_FLAGS_DEBUG "-g -rdynamic") # -D_GLIBCXX_DEBUG -- incompatible with boost :(
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast")
endif ()
# **** PROCESS CONFIGURATION FILE ****
# configure a header file to pass some of the CMake settings
# to the source code
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/config.hpp.in
${CMAKE_CURRENT_SOURCE_DIR}/include/config.hpp
)
# **** SOURCE FILES ****
include_directories(include
${Boost_INCLUDE_DIRS}
${Boost_LIBRARY_DIRS})
set(SRCS
${CMAKE_CURRENT_SOURCE_DIR}/src/Action.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Action.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/definitions.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/definitions.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/RMDP.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/RMDP.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/State.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/State.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Transition.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Transition.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/modeltools.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/modeltools.hpp
)
set(TSTS ${CMAKE_CURRENT_SOURCE_DIR}/test/test.cpp)
set(DEV ${CMAKE_CURRENT_SOURCE_DIR}/test/dev.cpp)
set(BANDITS ${CMAKE_CURRENT_SOURCE_DIR}/test/bandits.cpp)
set(BENCH ${CMAKE_CURRENT_SOURCE_DIR}/test/benchmark.cpp)
if (BUILD_ADVANCED)
# whether to build the simulation component of the library
set(SRCS ${SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/src/Simulation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Simulation.hpp
${CMAKE_CURRENT_SOURCE_DIR}/src/Samples.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/Samples.hpp
)
set(TSTS ${TSTS} ${CMAKE_CURRENT_SOURCE_DIR}/test/test_simulation.cpp)
# whether to build the implementable component of the library
set(SRCS ${SRCS}
${CMAKE_CURRENT_SOURCE_DIR}/src/ImMDP.cpp
${CMAKE_CURRENT_SOURCE_DIR}/include/ImMDP.hpp)
set(TSTS ${TSTS} ${CMAKE_CURRENT_SOURCE_DIR}/test/test_implementable.cpp)
endif (BUILD_ADVANCED)
# **** LIBRARY ****
add_library(craam STATIC ${SRCS} ${Boost_LIBRARIES})
# **** DEVELOPMENT EXECUTABLE ****
add_executable(develop_exe ${DEV})
target_link_libraries(develop_exe craam)
add_custom_target(develop COMMAND develop_exe
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
COMMENT "Running executable")
# **** TEST ****
if (BUILD_TESTS)
add_executable(unit_tests ${TSTS})
target_link_libraries(unit_tests ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} craam)
add_custom_target(testit COMMAND unit_tests --show_progress --detect_memory_leaks --detect_fp_exceptions
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin
COMMENT "Running unit tests")
endif (BUILD_TESTS)
# **** benchmark ****
add_executable(benchmark EXCLUDE_FROM_ALL ${BENCH})
target_link_libraries(benchmark ${boost_unit_test_framework_library} craam)
# **** bandits ****
add_executable(bandits ${BANDITS})
target_link_libraries(bandits craam)
# **** DOCUMENTATION ****
if (BUILD_DOCUMENTATION)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Needs Doxygen to build the documentation.")
endif ()
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxygen.config.in)
set(doxyfile ${CMAKE_CURRENT_SOURCE_DIR}/doc/doxyfile.config)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
#install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
endif ()