-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
142 lines (124 loc) · 4.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
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
cmake_policy(VERSION 3.16)
project(
dwarfworks
DESCRIPTION "Dwarfworks Game Engine"
LANGUAGES C CXX OBJC OBJCXX ASM)
message(STATUS "Building Dwarfworks...")
# Detect build (host) platform. NOTE this is incomplete.
if(WIN32) # Windows
set(PLATFORM_WINDOWS
True
CACHE INTERNAL "")
add_compile_definitions(PLATFORM_WINDOWS)
elseif(UNIX AND NOT APPLE) # Linux
set(PLATFORM_LINUX
True
CACHE INTERNAL "")
add_compile_definitions(PLATFORM_LINUX)
elseif(APPLE) # MacOs
set(PLATFORM_MACOS
True
CACHE INTERNAL "")
add_compile_definitions(PLATFORM_MACOS)
else()
message(FATAL_ERROR "Platform NOT supported!")
endif()
# Print the platform
if(PLATFORM_WINDOWS)
message(STATUS "Platform: Windows")
elseif(PLATFORM_LINUX)
message(STATUS "Platform: Linux")
elseif(PLATFORM_MACOS)
message(STATUS "Platform: MacOS")
endif()
# build configuration
set(CMAKE_BUILD_TYPE
"Debug"
CACHE STRING "" FORCE)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_compile_definitions(DW_DEBUG)
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
add_compile_definitions(DW_RELEASE)
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Dist")
add_compile_definitions(DW_DIST)
else()
message(FATAL_ERROR "The requested build configuration is not supported")
endif()
# export compile commands for use with clang tools
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
set(CMAKE_EXPORT_COMPILE_COMMANDS
True
CACHE BOOL "" FORCE)
endif()
# configure a header file to pass the version number only
# configure_file(DwarfworksConfig.h.in DwarfworksConfig.h)
# control where the static and shared libraries are built so that on Windows we
# don't need to tinker with the path to run the executable
# set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
# set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
#
# Binaries (/Debug/Mac) ; Intermediates (/Debug/Mac)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# CCache
option(ENABLE_CCACHE "Use ccache to speed up iterative builds" OFF)
if (ENABLE_CCACHE)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
endif()
# clang-tidy
find_program(
CLANG_TIDY_PROGRAM
NAMES "clang-tidy"
DOC "$(which clang-tidy)")
if(CLANG_TIDY_PROGRAM)
message(STATUS "Found clang-tidy.")
endif()
# todo add description
add_library(project_options INTERFACE)
target_compile_features(project_options INTERFACE cxx_std_17)
# todo add description
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
option(ENABLE_BUILD_WITH_TIME_TRACE
"Enable -ftime-trace to generate time tracing .json files on clang"
OFF)
if(ENABLE_BUILD_WITH_TIME_TRACE)
target_compile_options(project_options INTERFACE -ftime-trace)
endif()
endif()
# build as shared library
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
# NOTE need PIC(POSITION_INDEPENDENT_CODE) with shared libs.
# user-specified option for whether to build the sandbox application
option(BUILD_SANDBOX "Build the Sandbox example of using Dwarfworks" ON)
# The default Dwarfworks root directory (keep internal for now)
set(Dwarfworks_Dir
"${CMAKE_CURRENT_SOURCE_DIR}/Dwarfworks"
CACHE PATH "")
# mark_as_advanced(Dwarfworks_Dir)
# The Dwarfworks include directories
set(Dwarfworks_Include_Directories_Public
${Dwarfworks_Dir}
CACHE INTERNAL "")
set(Dwarfworks_Include_Directories_Internal
${Dwarfworks_Dir}
CACHE INTERNAL "")
# Some IDEs, like Xcode, support folders. We nhave to manually enable the
# property to allow CMake to organize the files by folders.
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# build Dwarfworks
if(BUILD_SHARED_LIBS)
message(
FATAL_ERROR "Building Dwarfworks as shared library is not supported yet.")
endif()
add_subdirectory(Dwarfworks)
# build Sandbox
if(BUILD_SANDBOX)
add_subdirectory(Sandbox)
endif()