forked from sakura-editor/sakura
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
248 lines (217 loc) · 5.68 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
cmake_minimum_required (VERSION 3.12)
#
# ソリューション単位のトップレベル設定
#
project (sakura
LANGUAGES CXX
)
set_directory_properties (PROPERTIES
VS_STARTUP_PROJECT sakura
)
set (CMAKE_CONFIGURATION_TYPES
"Release;Debug"
)
set (CMAKE_SUPPRESS_REGENERATION
"ON"
)
# undefined this var causes an error on gcc's compiling a resource-only dll.
set (CMAKE_RC_CREATE_SHARED_LIBRARY
${CMAKE_CXX_CREATE_SHARED_LIBRARY}
)
# remove "lib" prefix on MinGW build.
set (CMAKE_SHARED_LIBRARY_PREFIX
""
)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}$<0:Cancel INT_DIR>"
)
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}"
)
set (SRC
"${CMAKE_CURRENT_LIST_DIR}"
)
set (DST
"${CMAKE_BINARY_DIR}"
)
# 1. Define _DEBUG even when compiling with g++
# because Sakura's codebase use it.
# 2. Define NDEBUG here since CMake's default definition
# will be overwritten in CMakeLists.{GCC|MSVC}.txt.
# 3. Defined by add_compile_definitions, so that
# the definitions also affect .rc compilation.
add_compile_definitions (
$<IF:$<CONFIG:Debug>,_,N>DEBUG
)
#
# トップレベルターゲットの宣言(定義はあとで)
#
add_executable (HeaderMake)
add_executable (MakefileMake)
add_library (sakura_core STATIC)
add_executable (sakura WIN32)
add_executable (sakura_test)
add_library (sakura_lang_en_US SHARED)
add_custom_command (
OUTPUT "${SRC}/sakura_core/Funccode_define.h"
"${SRC}/sakura_core/Funccode_enum.h"
DEPENDS "${SRC}/sakura_core/Funccode_x.hsrc"
HeaderMake
COMMENT "HeaderMake makes Funccode_define.h and Funccode_enum.h out of Funccode_x.hsrc."
COMMAND HeaderMake -in=Funccode_x.hsrc -out=Funccode_define.h -mode=define
COMMAND HeaderMake -in=Funccode_x.hsrc -out=Funccode_enum.h -mode=enum -enum=EFunctionCode
WORKING_DIRECTORY "${SRC}/sakura_core"
)
add_custom_command (
OUTPUT "${SRC}/sakura_core/githash.h"
COMMENT "Update sakura_core/githash.h if needed."
COMMAND "${SRC}/sakura/githash.bat"
WORKING_DIRECTORY "${SRC}/sakura_core"
)
add_custom_target (githash.h
DEPENDS "${SRC}/sakura_core/githash.h"
COMMENT "Always try to update sakura_core/githash.h."
COMMAND "${SRC}/sakura/githash.bat"
WORKING_DIRECTORY "${SRC}/sakura_core"
)
add_custom_target (sakura_autogenerated_files ALL
DEPENDS "${SRC}/sakura_core/Funccode_define.h"
SOURCES "${SRC}/sakura_core/Funccode_define.h"
DEPENDS "${SRC}/sakura_core/Funccode_enum.h"
SOURCES "${SRC}/sakura_core/Funccode_enum.h"
DEPENDS "${SRC}/sakura_core/githash.h"
SOURCES "${SRC}/sakura_core/githash.h"
# DEPENDS "${SRC}/sakura_core/Makefile"
# SOURCES "${SRC}/sakura_core/Makefile"
)
add_dependencies (sakura_autogenerated_files
githash.h
)
add_custom_command (
OUTPUT "${SRC}/sakura_core/StdAfx.h"
"${SRC}/sakura_core/StdAfx.cpp"
DEPENDS "${SRC}/sakura_core/Funccode_enum.h"
COMMENT "StdAfx depends on Funccode_enum.h"
)
add_custom_command (
OUTPUT "${SRC}/sakura_core/Makefile"
DEPENDS MakefileMake
COMMENT "MakefileMake makes sakura_core/Makefile."
COMMAND MakefileMake -file=Makefile -dir=.
WORKING_DIRECTORY "${SRC}/sakura_core"
)
set(INSTALL_GTEST OFF CACHE BOOL "set the option off.")
set(INSTALL_GMOCK OFF CACHE BOOL "set the option off.")
add_subdirectory("${SRC}/tests/googletest" EXCLUDE_FROM_ALL)
#
# コンパイラ固有
#
set (SAKURA_CXX_FLAGS_UTF8_SOURCE "")
function (target_resource_only_dll target)
endfunction()
include ("./CMakeLists.${CMAKE_CXX_COMPILER_ID}.txt" OPTIONAL)
include ("./tools/CMake/PrecompiledHeader.cmake")
#
# ターゲット: HeaderMake
#
target_sources (HeaderMake
PUBLIC "${SRC}/HeaderMake/HeaderMake.cpp"
)
#
# ターゲット: MakefileMake
#
target_sources (MakefileMake PUBLIC
"${SRC}/MakefileMake/MakefileMake.cpp"
)
#
# ターゲット: sakura_core
#
add_dependencies (sakura_core
sakura_autogenerated_files
)
file (GLOB_RECURSE CORE_CPP "${SRC}/sakura_core/*.cpp")
file (GLOB_RECURSE CORE_H "${SRC}/sakura_core/*.h")
target_sources (sakura_core
PRIVATE ${CORE_CPP}
${CORE_H}
)
target_compile_definitions (sakura_core
PUBLIC WIN32 _WINDOWS _WIN32_WINNT=_WIN32_WINNT_WIN7
UNICODE _UNICODE
SAKURA_NO_DLL
)
target_link_libraries (sakura_core
PRIVATE comctl32
imm32
mpr
imagehlp
shlwapi
winmm
)
target_include_directories (sakura_core
PUBLIC "${SRC}/sakura_core"
)
add_precompiled_header (sakura_core
"sakura_core/StdAfx.h" FORCEINCLUDE
SOURCE_CXX "${SRC}/sakura_core/StdAfx.cpp"
)
#
# ターゲット: sakura
#
file (GLOB_RECURSE SAKURA_RC "${SRC}/sakura_core/*.rc")
target_sources (sakura
PRIVATE ${SRC}/sakura_core/_main/WinMain.cpp
${SAKURA_RC}
)
target_link_libraries (sakura
PRIVATE sakura_core
)
#
# ターゲット: sakura_test
#
file (GLOB_RECURSE TEST_CPP
"${SRC}/tests/unittests/test*.cpp"
"${SRC}/tests/unittests/code*.cpp"
)
file (GLOB_RECURSE TEST_H
"${SRC}/tests/unittests/*.h"
)
target_sources (sakura_test
PRIVATE ${TEST_CPP}
${TEST_H}
)
target_link_libraries (sakura_test
PRIVATE sakura_core
gtest_main
gtest
)
#
# ターゲット: sakura_lang_en_US
#
add_dependencies (sakura_lang_en_US
sakura_autogenerated_files
)
file (GLOB_RECURSE ENUS_SRC
"${SRC}/sakura_lang_en_US/*.h"
"${SRC}/sakura_lang_en_US/*.rc"
)
target_sources (sakura_lang_en_US
PRIVATE ${ENUS_SRC}
)
target_compile_definitions (sakura_lang_en_US
PRIVATE SAKURA_LANG_EN_US_EXPORTS
)
target_resource_only_dll (sakura_lang_en_US)
#
# ソリューション単位のボトムレベル設定
#
file (GLOB_RECURSE ALL_CPP
"${SRC}/HeaderMake/*.cpp"
"${SRC}/MakefileMake/*.cpp"
"${SRC}/sakura_core/*.cpp"
"${SRC}/tests/unittests/*.cpp"
)
set_property (SOURCE ${ALL_CPP}
APPEND PROPERTY COMPILE_OPTIONS
${SAKURA_CXX_FLAGS_UTF8_SOURCE}
)