Skip to content

Commit 55d7f3b

Browse files
committed
Taken from endless-sky/endless-sky
1 parent 5cd02c1 commit 55d7f3b

File tree

4 files changed

+138
-12
lines changed

4 files changed

+138
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ resources/editor.icns
1010
# dlls needed to run the binary
1111
*.dll
1212

13+
vcpkg/
14+
1315
# Build Directories and toolchain-generated files
1416
build/
1517
install/

CMakeLists.txt

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,60 @@
11
cmake_minimum_required(VERSION 3.13)
22

33
include(CMakeDependentOption)
4+
if(UNIX AND NOT APPLE)
5+
option(ES_USE_VCPKG "Use vcpkg to get dependencies." OFF)
6+
else()
7+
option(ES_USE_VCPKG "Use vcpkg to get dependencies." ON)
8+
endif()
49
cmake_dependent_option(ES_GLES "Build the game with OpenGL ES" OFF UNIX OFF)
10+
cmake_dependent_option(ES_USE_SYSTEM_LIBRARIES "Use system libraries instead of the vcpkg ones." ON APPLE OFF)
511

612
# Support Debug and Release configurations.
713
set(CMAKE_CONFIGURATION_TYPES "Debug" "Release" CACHE STRING "" FORCE)
814

9-
# Use C++17 without any compiler specific extensions.
15+
# Use C++20 without any compiler specific extensions.
1016
set(CMAKE_CXX_STANDARD 20 CACHE STRING "")
1117
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1218
set(CMAKE_CXX_EXTENSIONS OFF)
19+
# We don't use modules, so avoid using unrecognised compiler-specific commands that cmake produces when they are enabled.
20+
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
1321
# Use LTO for Release builds only.
1422
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_DEBUG FALSE)
1523
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
1624
# On Linux use relative RPATH.
1725
set(CMAKE_BUILD_RPATH_USE_ORIGIN ON)
1826

19-
# Add our overlays for vcpkg and setup vcpkg.
20-
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/overlays")
21-
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_SOURCE_DIR}/overlays")
22-
set(VCPKG_BOOTSTRAP_OPTIONS "-disableMetrics")
23-
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
24-
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
25-
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake"
26-
CACHE STRING "Vcpkg toolchain file" FORCE)
27+
# Setup vcpkg.
28+
if(ES_USE_VCPKG)
29+
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake"
30+
CACHE STRING "Vcpkg toolchain file")
31+
# No need to bootstrap vcpkg if the toolchain file is explictly provided.
32+
if(CMAKE_TOOLCHAIN_FILE STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
33+
include(utils/vcpkg_bootstrap.cmake)
34+
x_vcpkg_bootstrap()
35+
endif()
36+
37+
set(VCPKG_OVERLAY_TRIPLETS "${CMAKE_CURRENT_SOURCE_DIR}/overlays")
38+
set(VCPKG_OVERLAY_PORTS "${CMAKE_CURRENT_SOURCE_DIR}/overlays")
39+
set(VCPKG_BOOTSTRAP_OPTIONS "-disableMetrics")
40+
set(VCPKG_INSTALL_OPTIONS "--no-print-usage")
41+
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
42+
set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON)
43+
endif()
44+
45+
if(NOT ES_USE_SYSTEM_LIBRARIES)
46+
# Tell vcpkg to use the required system libraries.
47+
list(APPEND VCPKG_MANIFEST_FEATURES "system-libs")
48+
endif()
49+
50+
# Various helpful options for IDEs.
51+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
52+
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Editor)
53+
set(CMAKE_VS_JUST_MY_CODE_DEBUGGING ON)
2754

2855
project("Editor" VERSION 0.9.15
2956
DESCRIPTION "Unofficial plugin editor for Endless Sky"
30-
HOMEPAGE_URL https://github.com/quyykk/plugin-editor
57+
HOMEPAGE_URL https://github.com/warp-core/endless-sky-plugin-editor
3158
LANGUAGES CXX)
3259

3360
string(TIMESTAMP EDITOR_CURRENT_DATE "%d %b %Y")
@@ -72,8 +99,8 @@ if(APPLE)
7299
target_sources(Editor PRIVATE ${RESOURCES})
73100

74101
foreach(FILE ${RESOURCES})
75-
# Get the relative path from the root folder to the current file.
76-
file(RELATIVE_PATH NEW_FILE "${CMAKE_CURRENT_SOURCE_DIR}/endless-sky" ${FILE})
102+
# Get the relative path from the root folder to the current file.
103+
file(RELATIVE_PATH NEW_FILE "${CMAKE_CURRENT_SOURCE_DIR}/endless-sky" ${FILE})
77104
# Get the parent directory for the new location.
78105
get_filename_component(FILE_PATH ${NEW_FILE} DIRECTORY)
79106

utils/vcpkg_bootstrap.cmake

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright (c) 2022 by Osyotr
2+
# https://gist.github.com/Osyotr/e2d415312a10183bc7c614013494bf21
3+
# Boost Software License
4+
# Permission is hereby granted, free of charge, to any person or organization
5+
# obtaining a copy of the software and accompanying documentation covered by
6+
# this license (the "Software") to use, reproduce, display, distribute,
7+
# execute, and transmit the Software, and to prepare derivative works of the
8+
# Software, and to permit third-parties to whom the Software is furnished to
9+
# do so, all subject to the following:
10+
#
11+
# The copyright notices in the Software and this entire statement, including
12+
# the above license grant, this restriction and the following disclaimer,
13+
# must be included in all copies of the Software, in whole or in part, and
14+
# all derivative works of the Software, unless such copies or derivative
15+
# works are solely in the form of machine-executable object code generated by
16+
# a source language processor.
17+
#
18+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
# FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21+
# SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22+
# FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23+
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24+
# DEALINGS IN THE SOFTWARE.
25+
26+
include_guard(GLOBAL)
27+
28+
function(x_vcpkg_bootstrap)
29+
if(NOT GIT_EXECUTABLE)
30+
find_package(Git REQUIRED)
31+
endif()
32+
33+
set(X_VCPKG_GIT_REPOSITORY_URL "https://github.com/Microsoft/vcpkg" CACHE STRING "Vcpkg git repository")
34+
set(X_VCPKG_CLONE_DIR "${CMAKE_SOURCE_DIR}/vcpkg" CACHE PATH "Vcpkg clone directory")
35+
36+
if(NOT EXISTS "${X_VCPKG_CLONE_DIR}/.git")
37+
message(STATUS "Cloning vcpkg into ${X_VCPKG_CLONE_DIR}")
38+
execute_process(
39+
COMMAND "${GIT_EXECUTABLE}" clone --quiet "${X_VCPKG_GIT_REPOSITORY_URL}" "${X_VCPKG_CLONE_DIR}"
40+
ERROR_VARIABLE _vcpkg_git_clone_error
41+
)
42+
if(_vcpkg_git_clone_error)
43+
message(FATAL_ERROR "Could not clone vcpkg repository from ${X_VCPKG_GIT_REPOSITORY_URL}\nMake sure you have access rights and the URL is valid.")
44+
endif()
45+
message(STATUS "Cloning vcpkg into ${X_VCPKG_CLONE_DIR} - done")
46+
endif()
47+
48+
execute_process(
49+
COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD
50+
WORKING_DIRECTORY "${X_VCPKG_CLONE_DIR}"
51+
OUTPUT_VARIABLE _vcpkg_current_head_sha
52+
OUTPUT_STRIP_TRAILING_WHITESPACE
53+
COMMAND_ERROR_IS_FATAL ANY
54+
)
55+
set(_baseline_sha "${_vcpkg_current_head_sha}")
56+
57+
file(READ "${CMAKE_SOURCE_DIR}/vcpkg-configuration.json" _vcpkg_configuration_json_contents)
58+
string(JSON _baseline_sha ERROR_VARIABLE _get_baseline_err GET "${_vcpkg_configuration_json_contents}" "default-registry" "baseline")
59+
60+
set(_should_update_vcpkg FALSE)
61+
if(NOT "${_vcpkg_current_head_sha}" STREQUAL "${_baseline_sha}")
62+
set(_should_update_vcpkg TRUE)
63+
endif()
64+
65+
if(_should_update_vcpkg)
66+
message(STATUS "Fetching changes from vcpkg upstream")
67+
execute_process(
68+
COMMAND "${GIT_EXECUTABLE}" fetch --quiet --prune
69+
WORKING_DIRECTORY "${X_VCPKG_CLONE_DIR}"
70+
# No error checking here to allow offline usage
71+
)
72+
message(STATUS "Fetching changes from vcpkg upstream - done")
73+
74+
message(STATUS "Switching vcpkg HEAD to ${_baseline_sha}")
75+
execute_process(
76+
COMMAND "${GIT_EXECUTABLE}" reset --quiet --hard "${_baseline_sha}"
77+
COMMAND "${GIT_EXECUTABLE}" clean -qfd
78+
WORKING_DIRECTORY "${X_VCPKG_CLONE_DIR}"
79+
COMMAND_ERROR_IS_FATAL ANY
80+
)
81+
message(STATUS "Switching vcpkg HEAD to ${_baseline_sha} - done")
82+
83+
# Remove vcpkg executable to trigger bootstrap
84+
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
85+
file(REMOVE "${X_VCPKG_CLONE_DIR}/vcpkg.exe")
86+
else()
87+
file(REMOVE "${X_VCPKG_CLONE_DIR}/vcpkg")
88+
endif()
89+
endif()
90+
endfunction()

vcpkg-configuration.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"default-registry": {
3+
"kind": "builtin",
4+
"baseline": "c82f74667287d3dc386bce81e44964370c91a289"
5+
},
6+
"overlay-triplets": [ "./overlays" ]
7+
}

0 commit comments

Comments
 (0)