This repository has been archived by the owner on May 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
242 lines (162 loc) · 6.25 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
cmake_minimum_required(VERSION 3.13.0)
project(ocore)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_SUPPRESS_REGENERATION true)
file(GLOB_RECURSE ocoreHpp "include/*.hpp")
file(GLOB_RECURSE ocoreCpp "src/*.cpp")
if(WIN32)
set(platform windows CACHE STRING "Platform")
else()
set(platform linux CACHE STRING "Platform")
endif()
set(platforms windows linux osx android ios web)
set_property(CACHE platform PROPERTY STRINGS ${platforms})
message("-- Targeting platform ${platform}")
# TODO: On lost focus just reset all input
file(GLOB_RECURSE platformHpp "platform/${platform}/include/*.hpp")
file(GLOB_RECURSE platformCpp "platform/${platform}/src/*.cpp")
add_library(
ocore
STATIC
${ocoreHpp}
${ocoreCpp}
${platformHpp}
${platformCpp}
CMakeLists.txt
)
target_include_directories(ocore PRIVATE include)
target_include_directories(ocore PRIVATE platform/${platform}/include)
source_group("Header Files" FILES ${ocoreHpp})
source_group("Source Files" FILES ${ocoreCpp})
source_group("Platform Header Files" FILES ${platformHpp})
source_group("Platform Source Files" FILES ${platformCpp})
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
set(ARM true)
endif()
if(MSVC)
target_compile_options(ocore PRIVATE /W4 /WX /MD /MP /wd4201 /EHsc /GR)
else()
target_compile_options(ocore PRIVATE -Wall -Wextra -Werror -fms-extensions)
endif()
if(NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
if(MSVC)
target_compile_options(ocore PUBLIC /arch:AVX2)
else()
target_compile_options(ocore PUBLIC -mavx2)
endif()
endif()
# Ways to add virtual files
set_property(GLOBAL PROPERTY virtualFiles "")
include(CMakeParseArguments)
# Add virtual files into the executable
# Example:
# addVirtualFiles(
# DIRECTORY
# ${CMAKE_CURRENT_SOURCE_DIR}/res/test_shaders
# NAME
# shaders
# FILES
# ${shaderTestBinaries}
# )
macro(add_virtual_files)
set(_OPTIONS)
set(_ONE_VALUE DIRECTORY NAME)
set(_MULTI_VALUE FILES)
cmake_parse_arguments(_VFILES "${_OPTIONS}" "${_ONE_VALUE}" "${_MULTI_VALUE}" ${ARGN})
string(LENGTH "${_VFILES_DIRECTORY}/" dirLen)
get_property(vfileList GLOBAL PROPERTY virtualFileDescription)
get_property(vfileRoot GLOBAL PROPERTY virtualFileRoot)
get_property(fileCount GLOBAL PROPERTY virtualFileCounter)
if("${fileCount}" STREQUAL "")
set(fileCount 1)
endif()
if(_VFILES_FILES)
foreach(file ${_VFILES_FILES})
string(FIND "${file}" "${_VFILES_DIRECTORY}/" rootIndex)
if(rootIndex EQUAL 0)
string(SUBSTRING "${file}" ${dirLen} -1 file)
endif()
# For windows, add file to RES file
if(WIN32)
# Split by / and make sure all subdirs exist
set(fullName "${_VFILES_NAME}/${file}")
set(currentIndex "~/")
set(parent 0)
set(currPath ${fullName})
string(FIND ${currPath} / subPath)
set(offset ${subPath})
while(${subPath} GREATER -1)
MATH(EXPR subPath "${subPath}+1")
string(SUBSTRING ${currPath} ${subPath} -1 currPath)
string(SUBSTRING ${fullName} 0 ${offset} current)
# TODO: Hash ~/${current} for release and use it normally otherwise
# Add folder if required
set(currentNoEscape ${current})
string(REPLACE / \\/ current "${current}" )
set(doMakeFolder 1)
if(NOT vfileRoot STREQUAL "")
# Grab the parent id if it exists
string(REGEX MATCH "[0-9]+ [0-9]+ ~\\/${current}\n" fileMatch "${vfileRoot}")
if(NOT fileMatch STREQUAL "")
set(doMakeFolder 0)
string(REGEX MATCH "[0-9]+" parentMatch "${fileMatch}")
set(parent ${parentMatch})
endif()
endif()
if(doMakeFolder)
# Create new file if doesn't exist
set(vfileRoot ${vfileRoot}${fileCount}\ ${parent}\ ~/${currentNoEscape}\n)
set(parent ${fileCount})
MATH(EXPR fileCount "${fileCount}+1")
endif()
# Find next subpath
string(FIND ${currPath} / subPath)
MATH(EXPR offset "${offset}+${subPath}+1")
endwhile()
# Add to file dir
set(vfileList ${vfileList}_${fileCount}\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ RCDATA\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"${_VFILES_DIRECTORY}/${file}\"\n)
set(vfileRoot ${vfileRoot}${fileCount}\ ${parent}\ ~/${_VFILES_NAME}/${file}|\n)
MATH(EXPR fileCount "${fileCount}+1")
else()
message(FATAL_ERROR "Unsupported call to add_virtual_files")
endif()
endforeach()
else()
message(FATAL_ERROR "add_virtual_files: 'FILES' argument required.")
endif()
set_property(GLOBAL PROPERTY virtualFileDescription ${vfileList})
set_property(GLOBAL PROPERTY virtualFileRoot ${vfileRoot})
set_property(GLOBAL PROPERTY virtualFileCounter ${fileCount})
endmacro()
# Setting the icon of the app
# Call this immediately before configure_virtual_files with the executable
function(configure_icon target icon)
set_property(GLOBAL PROPERTY CURRENT_EXECUTABLE_ICON ${icon})
set_property(GLOBAL PROPERTY CURRENT_EXECUTABLE_ICON_TARGET ${target})
endfunction()
# Configure virtual files for a target
function(configure_virtual_files target)
get_property(vfileList GLOBAL PROPERTY virtualFileDescription)
get_property(vfileRoot GLOBAL PROPERTY virtualFileRoot)
get_property(iconTarget GLOBAL PROPERTY CURRENT_EXECUTABLE_ICON_TARGET)
get_property(icon GLOBAL PROPERTY CURRENT_EXECUTABLE_ICON)
if(WIN32)
# Configure icon for this target, if igx_test's the specified target
if("${iconTarget}" STREQUAL "${target}")
set(vfileList LOGO\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ICON\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"${icon}\"\n${vfileList})
target_sources(${target} PRIVATE ${icon})
endif()
# Prepare root file
file(WRITE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.root" ${vfileRoot})
set(vfileList ${vfileList}0\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ RCDATA\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.root\"\r\n)
file(WRITE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.rc" ${vfileList})
target_sources(${target} PRIVATE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.rc")
endif()
endfunction()