-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
193 lines (165 loc) · 7.62 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
cmake_minimum_required(VERSION 3.10)
# ccache can speed up program compilation, especially if you wipe and regenerate
# your build directory.
if (CN_ENABLE_CCACHE)
find_program(CCACHE_PROGRAM ccache)
if (CCACHE_PROGRAM)
message(STATUS "Using ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
endif()
project(calendon C)
# Using basic C99 for this engine until reaching technical and complexity
# limits with the language. C11 was also considered, but C99 should be
# readily supported by the most number of compilers.
# Why not C++ (or Rust, or Nim, or Go)? Using C99 aims to use a low level
# language, which readily maps to the generated assembly and generates consistent
# simple binary symbols. C99 limits overdesign and simplifies design choices by
# providing a subset of functionality of other languages, and hopes to boost
# productivity by providing clear compile errors.
# As the lingua franca of programming, bindings to other languages should able
# to be auto-generated or readily written by hand when appropriate.
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
# For sourcetrail and other tools
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Debug: Include debugging symbols and most warnings.
# Release: No debugging symbol and optimized for release.
# Coverage: Flags for generated code coverage under GCC.
# Future: Release mode which omits deprecated functionality.
#
# Future configurations:
# Profile: Add -pg flag for GCC to use with gprof
# RelWIthDebugInfo: Optimized build with debug symbols included.
if (UNIX)
set(CMAKE_CONFIGURATION_TYPES Debug;Release;RelWithDebInfo;Coverage;Future)
elseif (WIN32)
# Coverage is not supported on Windows.
set(CMAKE_CONFIGURATION_TYPES Debug;Release;RelWithDebInfo)
endif()
if(NOT CMAKE_BUILD_TYPE)
# Visual studio might not correctly set CMAKEBUILD_TYPE
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build Type: ${CMAKE_CONFIGURATION_TYPES}." FORCE)
endif()
message("Configuration types: ${CMAKE_CONFIGURATION_TYPES}")
# Provide standardized output locations. This particularly
# helps when dealing with additional directories such as for
# assets to ensure they are placed correctly relative to
# executables.
#
# https://stackoverflow.com/questions/543203/cmake-runtime-output-directory-on-windows
set(OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(BINARY_DIR ${OUTPUT_DIRECTORY})
set(DEMO_DIR ${OUTPUT_DIRECTORY}/demos)
message("Output directory: ${OUTPUT_DIRECTORY}")
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} CONFIG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG} "${OUTPUT_DIRECTORY}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIG} "${OUTPUT_DIRECTORY}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIG} "${OUTPUT_DIRECTORY}")
endforeach()
# CALENDON_LIBS is the list of all libraries to link with the Calendon lib itself.
# Client should be required to do minimum linking themselves.
set(CALENDON_LIBS "")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Set the CN_DEBUG symbol to 1 at the top level within the build system
# so no header needs to be included (or possibly forgotten) to get this
# value.
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
add_definitions(-DCN_DEBUG=1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
add_definitions(-DCN_ENABLE_CORE_DUMPS=1)
# Enabling this prevents core dumps from working.
#set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} -fsanitize=address -fsanitize=undefined")
elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
add_definitions(-DCN_DEBUG=1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
add_definitions(-DCN_ENABLE_CORE_DUMPS=1)
# Enabling this prevents core dumps from working.
#set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} -fsanitize=address -fsanitize=undefined")
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
# Allow symbol resolution when querying for symbols.
add_definitions(/DPSAPI_VERSION=1)
add_definitions(/DCN_DEBUG=1)
set(CALENDON_LIBS ${CALENDON_LIBS} psapi)
# Adds MiniDump reporting.
add_definitions(/DCN_ENABLE_CORE_DUMPS=1)
set(CALENDON_LIBS ${CALENDON_LIBS} dbghelp)
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "Coverage is not available in Clang.")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CALENDON_LIBS ${CALENDON_LIBS} gcov)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif()
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Future")
# Omit deprecated functionality, causing build breakages.
add_definitions(-DCN_DEPRECATION_BREAK=0)
add_definitions(-DCN_DEPRECATION_OMIT=1)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
# Make a breakpoint on deprecated behavior.
add_definitions(-DCN_DEPRECATION_BREAK=1)
add_definitions(-DCN_DEPRECATION_OMIT=0)
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
# Release may need to ship with deprecated features to make a ship date.
add_definitions(-DCN_DEPRECATION_BREAK=0)
add_definitions(-DCN_DEPRECATION_OMIT=0)
endif()
# Bring in extra warnings to prevent errors.
# https://caiorss.github.io/C-Cpp-Notes/compiler-flags-options.html
set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} -Wall -Wextra")
#set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} -Wpedantic")
set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} -Wshadow -Wdouble-promotion -Wundef -Wconversion -fno-common")
set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} -fvisibility=hidden")
# Temporary workaround until strcpy, strlen, usages get replaced.
if (WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} /W4")
set(CALENDON_COMMON_C_FLAGS "${CALENDON_COMMON_C_FLAGS} /MP") # Enable parallel build
endif (WIN32)
if (UNIX)
set(CALENDON_LIBS ${CALENDON_LIBS} m)
endif (UNIX)
# Eliminate extra dead code
#set(CALENDON_COMMON_C_FLAGS "-ffunction-sections -fdata-sections")
# https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# TODO: It'd be nice to use -Weverything, but it generates pointer sign
# errors on uint8_t* <-> char* and I don't have time to investigate.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CALENDON_COMMON_C_FLAGS}")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CALENDON_COMMON_C_FLAGS}")
endif()
# Introduce the vendorize(platform library semantic_version) syntax for
# providing libraries from known local sources (vendoring).
include(vendor/common/vendorize-cmake-0.1/vendorize.cmake)
# libspng provides extremely simplified PNG loading.
vendorize(common libspng 0.6.3)
include_directories(SYSTEM ${VENDOR_LIBSPNG_ROOT}/spng)
if (WIN32)
vendorize(windows sdl2 2.0.10)
include_directories(SYSTEM "${VENDOR_SDL2_ROOT}/include")
link_directories(SYSTEM "${VENDOR_SDL2_ROOT}/lib/x64")
# glew (GL Extension Wranger) is used to load OpenGL extension functions so we
# don't need to manually load function pointers.
vendorize(windows glew 2.1.0)
include_directories(SYSTEM "${VENDOR_GLEW_ROOT}/include")
link_directories(SYSTEM "${VENDOR_GLEW_ROOT}/lib/Release/x64")
set(CALENDON_LIBS
glew32.lib
${CALENDON_LIBS})
# zlib is required by libspng
vendorize(windows zlib 1.2.11)
include_directories(SYSTEM ${VENDOR_ZLIB_ROOT}/include)
link_directories(${VENDOR_ZLIB_ROOT}/Release/x64)
set(CALENDON_LIBS ${CALENDON_LIBS} zlibwapi.dll)
# dbghelp.dll isn't provided normally, it's part of the Debugging tools in
# the SDK, so an x64 version is included for creating minidumps.
vendorize(windows windows_sdk 10)
endif (WIN32)
add_subdirectory(src)