-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
134 lines (115 loc) · 4.17 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
# 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 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)
# 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 (WIN32)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
ADD_DEFINITIONS(-DUCRTBASEDLL_NAME="ucrtbase.dll")
else ()
ADD_DEFINITIONS(-DUCRTBASEDLL_NAME="ucrtbased.dll")
endif ()
file(GLOB_RECURSE KAJI_PLATFORM_SRC
${PROJECT_SOURCE_DIR}/src/kaji/win/*.c
)
elseif (UNIX)
file(GLOB_RECURSE KAJI_PLATFORM_SRC
${PROJECT_SOURCE_DIR}/src/kaji/nix/*.c
)
else ()
message (FATAL_ERROR "Operating system not supported!")
endif()
if (MSVC)
# warning level 4 and all warnings as errors
#add_compile_options(/W4 /WX)
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_compile_options(/MD)
else ()
add_compile_options(/MDd)
endif ()
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE=1)
add_definitions(-Dstrdup=_strdup)
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/tempora/CMakeLists.txt")
message(FATAL_ERROR "The submodule 'tempora' could not be fetched! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
add_subdirectory(deps/tempora)
# .
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/deps/spirits/CMakeLists.txt")
message(FATAL_ERROR "The submodule 'spirits' could not be fetched! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
add_subdirectory(deps/spirits)
# Collect source and header files.
file(GLOB KAJI_SRC
${PROJECT_SOURCE_DIR}/src/kaji/*.c
)
add_library(kaji ${KAJI_SRC} ${KAJI_PLATFORM_SRC})
target_include_directories(kaji PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/inc/>
)
set_property(TARGET kaji PROPERTY C_STANDARD 11)
add_dependencies(kaji tempora spirits)
target_link_libraries(kaji tempora spirits)
# .
add_executable(kaji-example-counter EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/examples/counter.c
)
set_property(TARGET kaji-example-counter PROPERTY C_STANDARD 17)
add_dependencies(kaji-example-counter kaji)
target_link_libraries(kaji-example-counter kaji)
# .
add_executable(kaji-example-gedanken EXCLUDE_FROM_ALL
${PROJECT_SOURCE_DIR}/examples/use_gedanken.c
)
set_property(TARGET kaji-example-gedanken PROPERTY C_STANDARD 17)
add_dependencies(kaji-example-gedanken kaji)
target_link_options(kaji-example-gedanken PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/FORCE:MULTIPLE>)
target_link_libraries(kaji-example-gedanken kaji)