-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
163 lines (137 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
cmake_minimum_required(VERSION 3.25 FATAL_ERROR)
# Create project
project(sdk_launcher
DESCRIPTION "A minimal SDK launcher for Strata Source engine games"
VERSION "0.4.1"
HOMEPAGE_URL "https://github.com/StrataSource/sdk-launcher")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Include CMake libraries
include(CheckIPOSupported)
include(GNUInstallDirs)
# Set up variables
set(PROJECT_NAME_PRETTY "SDK Launcher" CACHE STRING "" FORCE)
set(PROJECT_TARGET_NAME "SDKLauncher" CACHE STRING "" FORCE)
# Helper for creating enum options (pick between certain strings)
macro(option_enum)
cmake_parse_arguments(IN "" "NAME;DEFAULT;DESCRIPTION" "OPTIONS" ${ARGN})
set(${IN_NAME}_OPTIONS ${IN_OPTIONS})
set(${IN_NAME} ${IN_DEFAULT} CACHE STRING ${IN_DESCRIPTION})
set_property(CACHE ${IN_NAME} PROPERTY STRINGS ${IN_NAME}_OPTIONS)
if(NOT ${IN_NAME} IN_LIST ${IN_NAME}_OPTIONS)
message(FATAL_ERROR "${IN_NAME} (currently ${${IN_NAME}}) must be one of the following values: ${${IN_NAME}_OPTIONS}")
endif()
endmacro()
# Options
option(SDK_LAUNCHER_USE_LTO "Build SDK Launcher with link-time optimization enabled" OFF)
option_enum(
NAME "SDK_LAUNCHER_DEFAULT_MOD"
DESCRIPTION "The default game folder to use"
DEFAULT "p2ce"
OPTIONS "p2ce" "revolution" "momentum")
# Global CMake options
if(PROJECT_IS_TOP_LEVEL)
# Set proper runpath
set(CMAKE_SKIP_BUILD_RPATH OFF)
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
set(CMAKE_INSTALL_RPATH $ORIGIN)
# Compile with PIC
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Compile with LTO if supported
set(SDK_LAUNCHER_USE_LTO_INTERNAL OFF)
if(SDK_LAUNCHER_USE_LTO)
check_ipo_supported(RESULT SDK_LAUNCHER_USE_LTO_INTERNAL)
endif()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${SDK_LAUNCHER_USE_LTO_INTERNAL})
# Set default install directory permissions
set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
endif()
# Macro to set up many things at once for a given target
function(sdk_launcher_configure_target TARGET)
# Define DEBUG macro
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:DEBUG>")
# Set optimization flags
if(CMAKE_BUILD_TYPE MATCHES "Debug")
# Build with debug friendly optimizations and debug symbols (MSVC defaults are fine)
if(UNIX OR MINGW)
target_compile_options(${TARGET} PRIVATE -Og -g)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT MSVC)
target_compile_options(${TARGET} PRIVATE -fno-limit-debug-info)
endif()
else()
# Build with optimizations and don't omit stack pointer for debugging (MSVC defaults are fine)
if(UNIX OR MINGW)
target_compile_options(${TARGET} PRIVATE -O2 -fno-omit-frame-pointer)
endif()
endif()
if(WIN32 AND MSVC)
get_target_property(TARGET_TYPE ${TARGET} TYPE)
get_target_property(TARGET_IS_GUI ${TARGET} WIN32_EXECUTABLE)
# Create PDBs in release
if(MSVC AND ((TARGET_TYPE STREQUAL "SHARED_LIBRARY") OR (TARGET_TYPE STREQUAL "EXECUTABLE")))
target_compile_options(
${TARGET} PRIVATE
"$<$<CONFIG:Release>:/Zi>")
target_link_options(
${TARGET} PRIVATE
"$<$<CONFIG:Release>:/DEBUG>"
"$<$<CONFIG:Release>:/OPT:REF>"
"$<$<CONFIG:Release>:/OPT:ICF>")
endif()
# Don't show the console when running the executable
if(MSVC AND TARGET_IS_GUI)
target_link_options(
${TARGET} PRIVATE
"/ENTRY:mainCRTStartup")
endif()
endif()
endfunction()
# miniz
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/ext/miniz")
# Qt
if(WIN32 AND NOT DEFINED QT_BASEDIR)
message(FATAL_ERROR "Please define your QT install dir with -DQT_BASEDIR=\"C:/your/qt6/here\"")
endif()
if(DEFINED QT_BASEDIR)
string(REPLACE "\\" "/" QT_BASEDIR "${QT_BASEDIR}")
# Add it to the prefix path so find_package can find it
list(APPEND CMAKE_PREFIX_PATH "${QT_BASEDIR}")
set(QT_INCLUDE "${QT_BASEDIR}/include")
message(STATUS "Using ${QT_INCLUDE} as the Qt include directory")
endif()
# CMake has an odd policy that links a special link lib for Qt on newer versions of CMake
cmake_policy(SET CMP0020 NEW)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets Network)
# Generate config header
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/Config.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/Config.h")
# Create executable
add_executable(${PROJECT_TARGET_NAME} WIN32
"${CMAKE_CURRENT_SOURCE_DIR}/res/res.qrc"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Config.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/GameConfig.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/LaunchButton.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Main.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/NewModDialog.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Window.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/Window.h")
sdk_launcher_configure_target(${PROJECT_TARGET_NAME})
target_link_libraries(
${PROJECT_TARGET_NAME} PRIVATE
miniz
Qt::Core
Qt::Gui
Qt::Widgets
Qt::Network)
target_include_directories(
${PROJECT_TARGET_NAME} PRIVATE
"${QT_INCLUDE}"
"${QT_INCLUDE}/QtCore"
"${QT_INCLUDE}/QtGui"
"${QT_INCLUDE}/QtWidgets"
"${QT_INCLUDE}/QtNetwork")