-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
91 lines (75 loc) · 3.5 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
cmake_minimum_required(VERSION 3.16)
# set the output directory for built objects.
# This makes sure that the dynamic library goes into the build directory automatically.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
# prevent installing to system directories.
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}" CACHE INTERNAL "")
# Declare the project
project(Starlit)
# Set the name of the executable
set(EXECUTABLE_NAME ${PROJECT_NAME})
# Create an executable or a shared library based on the platform and add our sources to it
if (ANDROID)
# The SDL java code is hardcoded to load libmain.so on android, so we need to change EXECUTABLE_NAME
set(EXECUTABLE_NAME main)
add_library(${EXECUTABLE_NAME} SHARED)
else()
add_executable(${EXECUTABLE_NAME})
endif()
# Add your sources to the target
target_sources(${EXECUTABLE_NAME}
PRIVATE
src/main.cpp
)
# What is iosLaunchScreen.storyboard? This file describes what Apple's mobile platforms
# should show the user while the application is starting up. If you don't include one,
# then you get placed in a compatibility mode that does not allow HighDPI.
# This file is referenced inside Info.plist.in, where it is marked as the launch screen file.
# It is also ignored on non-Apple platforms.
# To get an app icon on Apple platforms, add it to your executable.
# Afterward, the image file in Info.plist.in.
if(APPLE)
target_sources("${EXECUTABLE_NAME}" PRIVATE "src/logo.png")
endif()
# Set C++ version
target_compile_features(${EXECUTABLE_NAME} PUBLIC cxx_std_20)
# on Web targets, we need CMake to generate a HTML webpage.
if(CMAKE_SYSTEM_NAME MATCHES Emscripten)
set(CMAKE_EXECUTABLE_SUFFIX ".html" CACHE INTERNAL "")
endif()
# Configure SDL by calling its CMake file.
# we use EXCLUDE_FROM_ALL so that its install targets and configs don't
# pollute upwards into our configuration.
add_subdirectory(SDL EXCLUDE_FROM_ALL)
# Link SDL to our executable. This also makes its include directory available to us.
target_link_libraries(${EXECUTABLE_NAME} PUBLIC SDL3::SDL3)
target_compile_definitions(${EXECUTABLE_NAME} PUBLIC SDL_MAIN_USE_CALLBACKS)
# set some extra configs for each platform
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
# On macOS, make a proper .app bundle instead of a bare executable
MACOSX_BUNDLE TRUE
# Set the Info.plist file for Apple Mobile platforms. Without this file, your app
# will not launch.
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/src/Info.plist.in"
# in Xcode, create a Scheme in the schemes dropdown for the app.
XCODE_GENERATE_SCHEME TRUE
# Identification for Xcode
XCODE_ATTRIBUTE_BUNDLE_IDENTIFIER "com.ravbug.sdl3-sample"
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "com.ravbug.sdl3-sample"
XCODE_ATTRIBUTE_CURRENTYEAR "${CURRENTYEAR}"
)
# on Visual Studio, set our app as the default project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT "${EXECUTABLE_NAME}")
# On macOS Platforms, ensure that the bundle is valid for distribution by calling fixup_bundle.
# note that fixup_bundle does not work on iOS, so you will want to use static libraries
# or manually copy dylibs and set rpaths
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
INSTALL(CODE
"include(BundleUtilities)
fixup_bundle(\"$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>\" \"\" \"\")
"
COMPONENT Runtime
)
endif()
install(TARGETS ${EXECUTABLE_NAME} BUNDLE DESTINATION ./install)