forked from alaingalvan/CrossWindow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
248 lines (217 loc) · 8.41 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
# Project Info
cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
cmake_policy(VERSION 3.18)
project(CrossWindow)
enable_language(C)
enable_language(CXX)
# CMake Settings
set(CMAKE_SUPPRESS_REGENERATION true)
set(DCMAKE_GENERATOR_PLATFORM "x64")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# =============================================================
# Options
set(XWIN_API AUTO CACHE STRING "A more specific platform selector to choose from, choose the exact OS API to use, can be WIN32, UWP, COCOA, UIKIT, XCB, XLIB, MIR, WAYLAND, ANDROID, WASM, NOOP.")
set_property(
CACHE
XWIN_API PROPERTY
STRINGS AUTO WIN32 UWP COCOA UIKIT XCB XLIB MIR WAYLAND ANDROID WASM NOOP
)
set(XWIN_OS AUTO CACHE STRING "Optional: Choose the OS to build for, defaults to AUTO, but can be WINDOWS, MACOS, LINUX, ANDROID, IOS, WASM.")
set_property(
CACHE
XWIN_OS PROPERTY
STRINGS AUTO WINDOWS MACOS LINUX ANDROID IOS WASM NOOP
)
if( NOT (XWIN_OS STREQUAL "AUTO") AND XWIN_API STREQUAL "AUTO")
if(XWIN_OS STREQUAL "WINDOWS")
set(XWIN_API "WIN32")
elseif(XWIN_OS STREQUAL "MACOS")
set(XWIN_API "COCOA")
elseif(XWIN_OS STREQUAL "LINUX")
set(XWIN_API "XLIB")
elseif(XWIN_OS STREQUAL "ANDROID")
set(XWIN_API "ANDROID")
elseif(XWIN_OS STREQUAL "IOS")
set(XWIN_API "UIKIT")
elseif(XWIN_OS STREQUAL "WASM")
set(XWIN_API "WASM")
elseif(XWIN_OS STREQUAL "NOOP")
set(XWIN_API "NOOP")
else()
message( SEND_ERROR "XWIN_OS can only be either AUTO, NOOP, WINDOWS, MACOS, LINUX, ANDROID, IOS, or WASM.")
endif()
endif()
if(XWIN_API STREQUAL "AUTO")
if (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
set(XWIN_API "WIN32" CACHE STRING "A more specific platform selector to choose from, choose the exact OS protocol to use, can be WIN32, UWP, COCOA, UIKIT, XCB, XLIB, MIR, WAYLAND, ANDROID, WASM, NOOP." FORCE)
elseif (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(XWIN_API "COCOA" CACHE STRING "A more specific platform selector to choose from, choose the exact OS protocol to use, can be WIN32, UWP, COCOA, UIKIT, XCB, XLIB, MIR, WAYLAND, ANDROID, WASM, NOOP." FORCE)
elseif (${CMAKE_HOST_SYSTEM_NAME} MATCHES "Linux")
set(XWIN_API "XCB" CACHE STRING "A more specific platform selector to choose from, choose the exact OS protocol to use, can be WIN32, UWP, COCOA, UIKIT, XCB, XLIB, MIR, WAYLAND, ANDROID, WASM, NOOP." FORCE)
endif()
endif()
set(XWIN_API_PATH "Noop")
if(XWIN_API STREQUAL "WIN32")
set(XWIN_API_PATH "Win32")
elseif(XWIN_API STREQUAL "UWP")
set(XWIN_API_PATH "UWP")
elseif(XWIN_API STREQUAL "COCOA")
set(XWIN_API_PATH "Cocoa")
elseif(XWIN_API STREQUAL "UIKIT")
set(XWIN_API_PATH "UIKit")
elseif(XWIN_API STREQUAL "XCB")
set(XWIN_API_PATH "XCB")
elseif(XWIN_API STREQUAL "XLIB")
set(XWIN_API_PATH "XLIB")
elseif(XWIN_API STREQUAL "ANDROID")
set(XWIN_API_PATH "Android")
elseif(XWIN_API STREQUAL "UIKIT")
set(XWIN_API_PATH "UIKit")
elseif(XWIN_API STREQUAL "WASM")
set(XWIN_API_PATH "WASM")
elseif(XWIN_API STREQUAL "NOOP")
set(XWIN_API_PATH "Noop")
else()
message( SEND_ERROR "XWIN_API can only be either AUTO, NOOP, WIN32, UWP, COCOA, UIKIT, XCB, XLIB, MIR, WAYLAND, ANDROID, or WASM.")
endif()
message( STATUS "Building CrossWindow for " ${XWIN_API_PATH} )
# =============================================================
# Sources
file(GLOB_RECURSE FILE_SOURCES RELATIVE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/CrossWindow.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/CrossWindow.h
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/Common/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/Common/*.mm
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/Common/*.h
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/Main/Main.h
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/${XWIN_API_PATH}/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/${XWIN_API_PATH}/*.mm
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/${XWIN_API_PATH}/*.h
)
# Solution Filters
foreach(source IN LISTS FILE_SOURCES)
get_filename_component(source_path "${source}" PATH)
string(REPLACE "/" "\\" source_path_msvc "${source_path}")
string(REPLACE "src" "" source_path_final "${source_path_msvc}")
source_group("${source_path_final}" FILES "${source}")
endforeach()
# Main files
file(GLOB_RECURSE MAIN_SOURCES RELATIVE
${CMAKE_HOME_DIRECTORY}
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/Main/${XWIN_API_PATH}Main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/CrossWindow/Main/${XWIN_API_PATH}Main.mm
)
set(XMAIN_SOURCES ${MAIN_SOURCES} CACHE STRING "Global Variable - The source files for the currently active protocol.")
# =============================================================
# CrossWindow Functions
function(xwin_setup versionMajor versionMinor versionPatch versionRevision companyName iconPath)
# @TODO - implement
message("Warning: xwin_setup has not yet been implemented.")
endfunction()
function(xwin_add_executable targetProject targetSources)
message("Creating CrossWindow executable:")
foreach(source IN LISTS XMAIN_SOURCES)
source_group("" FILES "${source}")
endforeach()
set(XWIN_FILES "${XMAIN_SOURCES}" "${targetSources}")
if(XWIN_API STREQUAL "WIN32" OR XWIN_API STREQUAL "UWP")
add_executable(
${targetProject}
WIN32
"${XWIN_FILES}"
)
elseif(XWIN_API STREQUAL "COCOA" OR XWIN_API STREQUAL "UIKIT")
add_executable(
${targetProject}
MACOSX_BUNDLE
${XWIN_FILES}
)
elseif(XWIN_API STREQUAL "XCB" OR XWIN_API STREQUAL "XLIB")
add_executable(
${targetProject}
${XWIN_FILES}
)
elseif(XWIN_API STREQUAL "ANDROID")
add_executable(
${targetProject}
${XWIN_FILES}
)
elseif(XWIN_API STREQUAL "WASM")
add_executable(
${targetProject}
${XWIN_FILES}
)
elseif(XWIN_API STREQUAL "NOOP")
add_executable(
${targetProject}
${XWIN_FILES}
)
endif()
target_compile_definitions(${targetProject} PRIVATE XWIN_${XWIN_API}=1)
endfunction()
# =============================================================
# Finalize Library
add_library(
${PROJECT_NAME}
${FILE_SOURCES}
)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src/)
# =============================================================
# CrossWindow Dependencies
if(XWIN_API STREQUAL "COCOA")
add_definitions("-x objective-c++")
find_library(COCOA_LIBRARY Cocoa)
find_library(QUARTZ_LIBRARY QuartzCore)
target_link_libraries(
${PROJECT_NAME}
${COCOA_LIBRARY}
${QUARTZ_LIBRARY}
)
set_target_properties(
${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "2"
)
elseif(XWIN_API STREQUAL "UIKIT")
add_definitions("-x objective-c++")
# Locate system libraries on iOS
find_library(UIKIT UIKit)
find_library(METALKIT_LIBRARY MetalKit)
find_library(FOUNDATION Foundation)
find_library(MOBILECORESERVICES MobileCoreServices)
find_library(CFNETWORK CFNetwork)
find_library(SYSTEMCONFIGURATION SystemConfiguration)
target_link_libraries(
${PROJECT_NAME}
${UIKIT}
${METALKIT_LIBRARY}
${FOUNDATION}
${CFNETWORK}
${SYSTEMCONFIGURATION}
)
set_target_properties(
${PROJECT_NAME} PROPERTIES XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY "2"
)
# Turn on ARC
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc")
elseif(XWIN_API STREQUAL "XLIB")
find_package(X11 REQUIRED)
if(X11_FOUND)
message("Found X11 Libraries.")
message("X11 includes = ${X11_INCLUDE_DIR}")
message("X11 Libraries = ${X11_LIBRARIES}")
target_link_libraries(${PROJECT_NAME} ${X11_LIBRARIES})
target_include_directories(${PROJECT_NAME} PUBLIC ${X11_INCLUDE_DIR})
endif()
elseif(XWIN_API STREQUAL "XCB")
find_package(X11 REQUIRED)
message("Found XCB Libraries.")
message("XCB Include Path = ${X11_xcb_INCLUDE_PATH}")
message("XCB Lib = ${X11_xcb_LIB}")
target_link_libraries(${PROJECT_NAME} ${X11_xcb_LIB})
target_include_directories(${PROJECT_NAME} PUBLIC ${X11_xcb_INCLUDE_PATH})
endif()
# =============================================================
# Preprocessor Definitions
target_compile_definitions(${PROJECT_NAME} PUBLIC XWIN_${XWIN_API}=1)