-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
182 lines (155 loc) · 8.01 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
cmake_minimum_required(VERSION 3.8.2) # source_group TREE
#cmake_policy(SET CMP0048 NEW)
project(deusexmachina) # VERSION 0.1.0)
# TODO: make project version work without breaking deps (CMP0048)
# TODO: exclude platform-specific sources & headers from unsupported platforms,?hide DEM_PLATFORM_WIN32 etc to PRIVATE?
# TODO: conditional addition of Win32, D3D9, D3D11 sources, headers & libs
include(CheckIncludeFile)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT "DEMRPG")
option(DEM_RENDER_DEBUG "Debug rendering API" ON)
option(DEM_DISABLE_CXX_EXCEPTIONS "Disable C++ exceptions" ON)
option(DEM_DISABLE_CXX_RTTI "Disable C++ RTTI" ON)
option(DEM_ASAN "Enable address sanitizer" OFF)
set(DEM_PREBUILT_DEPS_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Deps/Build" CACHE STRING "Prebuilt dependency package location")
if(EXISTS ${DEM_PREBUILT_DEPS_PATH})
option(DEM_PREBUILT_DEPS "Use prebuilt dependencies" ON)
else()
option(DEM_PREBUILT_DEPS "Use prebuilt dependencies" OFF)
endif()
message(STATUS "DEM_RENDER_DEBUG = ${DEM_RENDER_DEBUG}")
message(STATUS "DEM_ASAN = ${DEM_ASAN}")
include(CMake/DEMCMakeUtils.cmake)
if(MSVC AND DEM_DISABLE_CXX_EXCEPTIONS)
if(CMAKE_CXX_FLAGS MATCHES "/EHsc")
string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
endif()
endif()
# Dependencies
if(DEM_PREBUILT_DEPS)
# Prebuild dependency package can be built from source once for necessary configuration and
# its targets will not appear in a build system. It is recommended for game app development.
#set(DEMDeps_ROOT ${DEM_PREBUILT_DEPS_PATH})
set(DEMDeps_DIR "${DEM_PREBUILT_DEPS_PATH}" CACHE INTERNAL "" FORCE) # Suppress GUI entry without DEM_ prefix as it is not grouped to DEM
find_package(DEMDeps)
set(DEM_DEPS_POSSIBLE_TARGETS DEMDeps::lua DEMDeps::ogg DEMDeps::theora DEMDeps::CEGUIBase-0_Static DEMDeps::CEGUIPugiXMLParser_Static DEMDeps::CEGUISILLYImageCodec_Static DEMDeps::CEGUICoreWindowRendererSet_Static DEMDeps::CEGUICommonDialogs-0_Static DEMDeps::LinearMath DEMDeps::BulletCollision DEMDeps::BulletDynamics DEMDeps::DebugUtils DEMDeps::Detour DEMDeps::DetourCrowd DEMDeps::DetourTileCache DEMDeps::Recast) # TODO: add acl, rtm, sol, TracyClient and check
foreach(_TARGET_NAME IN LISTS DEM_DEPS_POSSIBLE_TARGETS)
if(TARGET ${_TARGET_NAME})
list(APPEND DEM_DEPS_TARGETS ${_TARGET_NAME})
endif()
endforeach()
else()
# Dependencies are built from sources as a part of DEM engine with the same configuration and
# appear in a build system. It is recommended for engine development and 3rd-party debugging.
#set(DEM_DEPS_DISABLE_CXX_EXCEPTIONS ${DEM_DISABLE_CXX_EXCEPTIONS} CACHE INTERNAL "" FORCE)
#set(DEM_DEPS_DISABLE_CXX_RTTI ${DEM_DISABLE_CXX_RTTI} CACHE INTERNAL "" FORCE)
set(DEM_DEPS_TARGET_TYPES_TO_PROCESS STATIC_LIBRARY MODULE_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY EXECUTABLE)
set(DEM_DEPS_TARGET_TYPES_TO_EXPORT STATIC_LIBRARY MODULE_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY INTERFACE_LIBRARY EXECUTABLE)
set(DEM_DEPS_TARGET_TYPES_TO_LINK STATIC_LIBRARY MODULE_LIBRARY SHARED_LIBRARY OBJECT_LIBRARY INTERFACE_LIBRARY)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/Deps" "${CMAKE_CURRENT_BINARY_DIR}/Deps")
get_all_targets(DEM_DEPS_TARGETS "${CMAKE_CURRENT_SOURCE_DIR}/Deps")
foreach(_TARGET_NAME IN LISTS DEM_DEPS_TARGETS)
get_target_property(_TARGET_TYPE ${_TARGET_NAME} TYPE)
if (${_TARGET_TYPE} IN_LIST DEM_DEPS_TARGET_TYPES_TO_LINK)
list(APPEND DEM_DEPS_TARGETS_TO_LINK ${_TARGET_NAME})
endif()
if (NOT ${_TARGET_TYPE} STREQUAL "INTERFACE_LIBRARY")
get_target_property(_TARGET_FOLDER ${_TARGET_NAME} FOLDER)
if(_TARGET_FOLDER)
set_target_properties(${_TARGET_NAME} PROPERTIES FOLDER "Deps/${_TARGET_FOLDER}")
else()
set_target_properties(${_TARGET_NAME} PROPERTIES FOLDER "Deps")
endif()
endif()
endforeach()
#???set aliases with namespace DEMDeps:: for all targets? or use namespaces DEM_DEPS_TARGETS in prebuilt case instead?
endif()
# DEMLow
include(CMake/DEMLow.cmake)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/DEM/Low/src" FILES ${DEM_L1_LOW_HEADERS} ${DEM_L1_LOW_SOURCES})
add_library(DEMLow ${DEM_L1_LOW_HEADERS} ${DEM_L1_LOW_SOURCES})
target_include_directories(DEMLow PUBLIC DEM/Low/src)
target_link_libraries(DEMLow PUBLIC ${DEM_DEPS_TARGETS_TO_LINK})
target_compile_definitions(DEMLow PUBLIC "$<IF:$<BOOL:${DEM_RENDER_DEBUG}>,DEM_RENDER_DEBUG=1,DEM_RENDER_DEBUG=0>")
if(WIN32)
target_compile_definitions(DEMLow PUBLIC DEM_PLATFORM_WIN32=1) # Public because app uses headers. Exclude headers when not Win32!
target_link_libraries(DEMLow PUBLIC UxTheme.lib Secur32.lib DbgHelp.lib) # Win32 platform, window and stack trace
target_link_libraries(DEMLow PUBLIC DXGI.lib D3D11.lib) # TODO: only when D3D11 renderer is built
target_link_libraries(DEMLow PUBLIC D3d9.lib) # TODO: only when D3D9 renderer is built
if(DEM_RENDER_DEBUG)
target_link_libraries(DEMLow PUBLIC dxguid.lib) # For any D3D, WKPDID_D3DDebugObjectName
check_include_file("d3d11_1.h" HAS_D3D11_1_H)
check_include_file("d3d9.h" HAS_D3D9_H)
if(HAS_D3D11_1_H)
# ID3DUserDefinedAnnotation
target_compile_definitions(DEMLow PUBLIC DEM_RENDER_DEBUG_D3D11_1)
elseif(HAS_D3D9_H)
# D3DPERF_BeginEvent, ... (DX10+ too!)
target_compile_definitions(DEMLow PUBLIC DEM_RENDER_DEBUG_D3D9)
else()
# No gfx API zones
endif()
endif()
endif()
if(DEM_DISABLE_CXX_EXCEPTIONS)
target_compile_definitions(DEMLow PUBLIC _HAS_EXCEPTIONS=0)
endif()
list(APPEND DEM_TARGETS DEMLow)
# DEMGame
include(CMake/DEMGame.cmake)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/DEM/Game/src" FILES ${DEM_L2_GAME_HEADERS} ${DEM_L2_GAME_SOURCES})
add_library(DEMGame ${DEM_L2_GAME_HEADERS} ${DEM_L2_GAME_SOURCES})
target_include_directories(DEMGame PUBLIC DEM/Game/src)
target_link_libraries(DEMGame DEMLow)
list(APPEND DEM_TARGETS DEMGame)
# DEMRPG
include(CMake/DEMRPG.cmake)
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/DEM/RPG/src" FILES ${DEM_L3_RPG_HEADERS} ${DEM_L3_RPG_SOURCES})
add_library(DEMRPG ${DEM_L3_RPG_HEADERS} ${DEM_L3_RPG_SOURCES})
target_include_directories(DEMRPG PUBLIC DEM/RPG/src)
target_link_libraries(DEMRPG DEMGame DEMLow)
list(APPEND DEM_TARGETS DEMRPG)
# Processing common settings for all DEM targets
# HACK: empty generator expressions are used for config suffix suppression
set(DEM_LIB_DIR "${CMAKE_CURRENT_BINARY_DIR}/lib/$<$<BOOL:FALSE>:>")
set(DEM_BIN_DIR "${CMAKE_CURRENT_BINARY_DIR}/bin/$<$<BOOL:FALSE>:>")
if(MSVC)
foreach(_TARGET_NAME IN LISTS DEM_DEPS_TARGETS)
get_target_property(type ${_TARGET_NAME} TYPE)
if (NOT ${type} STREQUAL "INTERFACE_LIBRARY")
set_target_properties(${_TARGET_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
endforeach()
endif()
foreach(_TARGET_NAME IN LISTS DEM_TARGETS)
set_target_properties(${_TARGET_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${DEM_LIB_DIR}
LIBRARY_OUTPUT_DIRECTORY ${DEM_LIB_DIR}
RUNTIME_OUTPUT_DIRECTORY ${DEM_BIN_DIR}
DEBUG_POSTFIX "_d"
CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON
)
foreach(_CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER "${_CONFIG}" _CONFIG)
set_target_properties(${_TARGET_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY_${_CONFIG} ${DEM_LIB_DIR}
LIBRARY_OUTPUT_DIRECTORY_${_CONFIG} ${DEM_LIB_DIR}
RUNTIME_OUTPUT_DIRECTORY_${_CONFIG} ${DEM_BIN_DIR}
)
endforeach()
if(MSVC)
set_target_properties(${_TARGET_NAME} PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
if(DEM_DISABLE_CXX_RTTI)
target_compile_options(${_TARGET_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/GR->)
endif()
if(DEM_ASAN)
target_compile_options(${_TARGET_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/fsanitize=address>)
#!!!DBG TMP! Need to build CEGUI deps with /fsanitize=address
target_compile_definitions(${_TARGET_NAME} PRIVATE _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION)
endif()
target_compile_options(${_TARGET_NAME} PRIVATE
"/Zc:__cplusplus"
"$<$<CONFIG:RelWithDebInfo>:/Ob2>" # CMake sets /Ob1 by default for RelWithDebInfo, preventing inlining in critical code like std::atomic, making profiling not representative
)
endif()
endforeach()