-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
125 lines (105 loc) · 3.81 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
# 2021-∞ (c) blurryroots innovation qanat OÜ. All rights reserved.
# See license.md for details.
# Version 3.2 and upwards.
CMAKE_MINIMUM_REQUIRED (VERSION 3.2)
# Setup versioning.
set(BUILD_MAJOR 0)
set(BUILD_MINOR 3)
set(BUILD_PATCH 1)
set(BUILD_VERSION "${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_PATCH}")
# Expose version information to config.
set(VERSION_NAME_BUFFER_SIZE 16)
set(VERSION_MAJOR ${BUILD_MAJOR})
set(VERISON_MINOR ${BUILD_MINOR})
set(VERSION_PATCH ${BUILD_PATCH})
set(VERSION_FORMAT "v%d.%d.%d")
# Specify version for this project.
project (kaji-sdl-example VERSION ${BUILD_VERSION})
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE PATH "" FORCE)
endif()
if (USE_GEDANKEN)
ADD_DEFINITIONS(-DUSE_GEDANKEN=1)
endif()
string(
COMPARE EQUAL
"${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}"
IS_STANDALON_PROJECT
)
# .
option(BUILD_SHARED_LIBS "Build using shared libraries" OFF)
option(SDL_SHARED "Build sdl2 as shared library" ON)
# Make sure libraries will be places beside executable.
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
if (MSVC)
# warning level 4 and all warnings as errors
#add_compile_options(/W4 /WX)
# Add crt dll dynamically (in either release or debug variant)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(/MD)
else ()
add_compile_options(/MDd)
endif ()
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
else()
# lots of warnings and all warnings as errors
add_compile_options(-Wunused-result)
endif()
# Setup git submodules.
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Update submodules ...")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update \
--init --recursive failed with ${GIT_SUBMOD_RESULT}, \
please checkout submodules")
endif()
endif()
endif()
#
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/deps/SDL/CMakeLists.txt")
message(FATAL_ERROR "The submodule 'SDL' could not be fetched! /
GIT_SUBMODULE was turned off or failed. \
Please update submodules and try again.")
endif()
# Tell find_package where to find SDL sources.
set(SDL2_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/deps/SDL")
find_package(SDL2 REQUIRED)
#
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/deps/kaji/CMakeLists.txt")
message(FATAL_ERROR "The submodule 'kaji' could not be fetched! \
GIT_SUBMODULE was turned off or failed. \
Please update submodules and try again.")
endif()
add_subdirectory(deps/kaji)
# .
include_directories(inc)
# .
add_library(kaji-sdl-common SHARED
${PROJECT_SOURCE_DIR}/src/common.c
)
set_property(TARGET kaji-sdl-common PROPERTY C_STANDARD 17)
# .
add_executable(kaji-sdl-gui
${PROJECT_SOURCE_DIR}/src/main-sdl.c
)
set_property(TARGET kaji-sdl-gui PROPERTY C_STANDARD 17)
add_dependencies(kaji-sdl-gui kaji-sdl-common kaji)
target_include_directories(kaji-sdl-gui PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_options(kaji-sdl-gui PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/FORCE:MULTIPLE>)
target_link_libraries(kaji-sdl-gui kaji-sdl-common kaji ${SDL2_LIBRARIES})
# .
add_executable(kaji-sdl-cli
${PROJECT_SOURCE_DIR}/src/main-cli.c
)
set_property(TARGET kaji-sdl-cli PROPERTY C_STANDARD 17)
add_dependencies(kaji-sdl-cli kaji-sdl-common kaji)
target_link_options(kaji-sdl-cli PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/FORCE:MULTIPLE>)
target_link_libraries(kaji-sdl-cli kaji-sdl-common kaji)