-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
298 lines (224 loc) · 9.45 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
290
291
292
293
294
295
296
297
project( SchiffbruchEngine )
option( SBE_ENABLE_COTIRE "" OFF)
if(SBE_ENABLE_COTIRE)
include(cotire)
endif()
cmake_minimum_required( VERSION 3.8 )
# set sbe version
set(VER_MAJOR 0)
set(VER_MINOR 1)
set(VER_PATCH 0)
#############################################################
################### Cmake Options ###########################
#############################################################
option( SBE_PROFILE "" OFF)
option( SBE_USE_PYTHON "" OFF)
option( SBE_USE_RUBY "" OFF)
option( SBE_BUILD_SHARED_LIBS "" ON )
option( SBE_USE_SHARED_LIBS "" ON )
option( SBE_ENABLE_LTO "enable ltoclion " OFF)
SET( CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
if (NOT CMAKE_BUILD_TYPE)
set( CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "-- INFO --")
message(STATUS "SBE_BUILD_SHARED_LIBS: ${SBE_BUILD_SHARED_LIBS}" )
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}" )
message(STATUS "CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}" )
message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}\n")
#############################################################
#################### External Libraries Configuration #####################
#############################################################
if (SBE_USE_SHARED_LIBS)
set(SFML_STATIC_LIBRARIES false)
set(SFGUI_STATIC_LIBRARIES false)
else()
set(SFML_STATIC_LIBRARIES true)
set(SFGUI_STATIC_LIBRARIES true)
set( ADD_SFML_MAIN "main")
endif()
#############################################################
#################### External Libraries #####################
#############################################################
set(REQUIRED_Boost_VERSION 1.60)
set(REQUIRED_SFML_VERSION 2)
set( SFML_FIND_REQUIRED true )
find_package(Boost ${REQUIRED_Boost_VERSION} COMPONENTS thread system filesystem)
#find_package(SFML 2 COMPONENTS audio graphics window system main ${ADD_SFML_MAIN})
find_package(SFML ${REQUIRED_SFML_VERSION} COMPONENTS audio window graphics system ${ADD_SFML_MAIN} REQUIRED)
find_package(SFGUI REQUIRED )
find_package(glm REQUIRED )
add_definitions( -DGLM_FORCE_RADIANS -DGLM_FORCE_CXX11 -DGLM_ENABLE_EXPERIMENTAL )
# set the list ourselves
# see: https://en.sfml-dev.org/forums/index.php?topic=24070.0
set(SFML_LIBRARIES sfml-audio sfml-window sfml-graphics sfml-system)
include_directories(${Boost_INCLUDE_DIR})
include_directories(${SFGUI_INCLUDE_DIR})
include_directories(${GLM_INCLUDE_DIRS})
#############################################################
#################### File inclusion #########################
#############################################################
file( GLOB_RECURSE sbe_SRCS RELATIVE "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/src/*.cpp" )
file( GLOB_RECURSE sbe_SRCHDRS RELATIVE "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/src/*.hpp" "${PROJECT_SOURCE_DIR}/src/*.ipp" )
file( GLOB_RECURSE sbe_HDRS RELATIVE "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/include/*.hpp" "${PROJECT_SOURCE_DIR}/include/*.ipp" )
#left here for debugging purposes
if (true)
message(STATUS "-- INCLUDES --")
message(STATUS "sfml libs: ${SFML_LIBRARIES}" )
message(STATUS "sfml includes: ${SFML_INCLUDE_DIR}" )
message(STATUS "sfgui lib: ${SFGUI_LIBRARY}" )
message(STATUS "sfgui includes: ${SFGUI_INCLUDE_DIR}" )
message(STATUS "glm includes: ${GLM_INCLUDE_DIRS}" )
message(STATUS "boost includes: ${Boost_INCLUDE_DIR}\n\n" )
message(STATUS "-- CXX FEATURES SUPPORTED BY COMPILER --")
message(STATUS "compile features: ${CMAKE_CXX_COMPILE_FEATURES}\n\n" )
# message( "-- FILES --" )
# message( "-- Found the following SRCS:\n ${sbe_SRCS}" )
# message( "-- Found the following SRCS:\n ${sbe_SRCS}" )
# message( "-- Found the following HDRS:\n ${sbe_HDRS}" )
# message( "-- Found the following SRCHDRS:\n ${sbe_SRCHDRS}" )
endif()
#############################################################
#################### Compiler Options #######################
#############################################################
set(CMAKE_CXX_STANDARD 17)
if(CMAKE_SYSTEM_NAME MATCHES Windows)
# nogdi prevents a "#define ERROR 0" from wingdi.h which fucks up our code
# wingdi.h is sometimes included in gl.h ( some mingw versions of glew don't include it, most do )
add_definitions( -DNOGDI -DWIN32_LEAN_AND_MEAN )
#disable boosts auto-linking feature. The required libs are already included by find_package
add_definitions(-DBOOST_ALL_NO_LIB)
# enable dllexport define in config.h
set(DLLEXPORT "__declspec(dllexport)")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
endif()
#
# General Compiler Options
#
IF(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_THREAD_USE_LIB -D_stdcall -D_cdecl -D_thiscall -D_fastcall -pipe")
else()
# FIXME: remove std-flag here if CMAKE_CXX_STANDARD works with msvc!
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++14 /MP /Gm- /EHsc /GR /W3")
endif()
#
# Debug Options
#
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DCOUNT_EVENTS")
if(NOT MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -fstack-protector --param=ssp-buffer-size=4")
else()
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /RTC1")
endif()
#
# Release Options
#
if( SBE_PROFILE)
if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /PROFILE")
add_definitions()
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O1 -pg")
endif()
else()
if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ox /Oy")
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fomit-frame-pointer -fexpensive-optimizations")
endif()
endif()
if(SBE_ENABLE_LTO AND NOT MSVC)
if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
endif()
endif()
#############################################################
#################### Scripting / Swig #######################
#############################################################
add_subdirectory( scripting )
# set by the scripting CMakelists
include_directories( ${SBE_SCRIPT_INCLUDES} )
#################### Generate config.h ######################
configure_file(config.h.in config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
#################### Final lib ##############################
# Add the library.
if( SBE_BUILD_SHARED_LIBS )
#set_target_properties( sbe PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE )
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
add_library( sbe SHARED ${sbe_HDRS} ${sbe_SRCHDRS} ${sbe_SRCS} )
set_target_properties( sbe PROPERTIES DEBUG_POSTFIX -d )
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_SYSTEM_NAME MATCHES Windows) # mingw-gcc!
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -shared -Wl,-rdynamic, -Wl,-export-all-symbols")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default")
else() # msvc
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /LD")
endif()
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSBE_STATIC")
add_library( sbe ${sbe_HDRS} ${sbe_SRCHDRS} ${sbe_SRCS} include/sbe/util/Meta.hpp)
set_target_properties( sbe PROPERTIES DEBUG_POSTFIX -s-d )
set_target_properties( sbe PROPERTIES DEBUG_POSTFIX -s-d )
set_target_properties( sbe PROPERTIES RELEASE_POSTFIX -s )
set_target_properties( sbe PROPERTIES MINSIZEREL_POSTFIX -s )
endif()
#
# setup of the library
#
target_link_libraries(sbe ${SFGUI_LIBRARY} ${SFML_LIBRARIES} ${Boost_LIBRARIES} ${SBE_SCRIPT_LIBS} ${SFML_DEPENDENCIES} ${Boost_DEPENDENCIES})
set_target_properties(sbe PROPERTIES SOVERSION ${VER_MAJOR})
set_target_properties(sbe PROPERTIES VERSION ${VER_MAJOR}.${VER_MINOR})
target_include_directories( sbe
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> # <prefix>/include/
PRIVATE ${PROJECT_SOURCE_DIR}/src
)
#set_target_properties(sbe PROPERTIES PUBLIC_HEADER "${sbe_HDRS}")
install(DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX})
install(TARGETS sbe EXPORT SBEConfigExport
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include)
if(SBE_ENABLE_COTIRE)
set_target_properties(sbe PROPERTIES COTIRE_ENABLE_PRECOMPILED_HEADER FALSE)
cotire(sbe)
endif()
######################################################
# Generate and install SBEConfig.cmake #
# (that's the new and hot FindX.cmake replacement) #
######################################################
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/SBEConfigVersion.cmake"
VERSION ${VER_MAJOR}.${VER_MINOR}.${VER_PATCH}
COMPATIBILITY SameMajorVersion
)
set(targets_config_filename "SBETargets.cmake")
export(EXPORT SBEConfigExport
FILE "${CMAKE_CURRENT_BINARY_DIR}/${targets_config_filename}")
set(config_package_location lib/cmake/SBE)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/SBEConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/SBEConfig.cmake"
INSTALL_DESTINATION "${config_package_location}"
)
#configure_package_config_file(
# "${PROJECT_SOURCE_DIR}/cmake/SBEConfigDependencies.cmake.in"
# "${CMAKE_CURRENT_BINARY_DIR}/SBEConfigDependencies.cmake"
# INSTALL_DESTINATION "${config_package_location}"
#)
install(EXPORT SBEConfigExport
FILE ${targets_config_filename}
DESTINATION ${config_package_location}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/SBEConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/SBEConfigVersion.cmake"
DESTINATION ${config_package_location}
COMPONENT devel
)