Skip to content

Commit 83b21c4

Browse files
committed
Declare USE_VCPKG as a proper cache variable
Set up USE_VCPKG with a description, valid set of values, and a default. Moves options declarations, and the toolchain logic dependent upon them, up to the top of the file so that they occur before the project() declaration - this is required for correct toolchain usage.
1 parent ab9e0b1 commit 83b21c4

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

CMakeLists.txt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
cmake_minimum_required(VERSION 3.20) # For using CMAKE_<LANG>_BYTE_ORDER
22

3-
if(NOT DEFINED USE_VCPKG OR USE_VCPKG)
3+
# set default cmake build type to Debug (None Debug Release RelWithDebInfo MinSizeRel)
4+
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED ENV{CMAKE_BUILD_TYPE})
5+
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "default build type")
6+
endif()
7+
8+
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja)." OFF)
9+
option(FORCE_PORTABLE_INSTALL "Install all files into local directory defined by CMAKE_INSTALL_PREFIX" ON)
10+
option(ENABLE_LOGGER "Enable logging to the terminal" OFF)
11+
option(ENABLE_MEM_RTL "Enable Real-time library memory management functions (disable to verbose memory allocations)" ON)
12+
option(BUILD_TESTING "Enable testing. Requires GTest." OFF)
13+
set(USE_VCPKG "DEFAULT" CACHE STRING "Use vcpkg for dependency management. DEFAULT defers to existence of $VCPKG_ROOT environment variable.")
14+
set_property(CACHE USE_VCPKG PROPERTY STRINGS "DEFAULT" "ON" "OFF")
15+
16+
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
17+
option(BUILD_EDITOR "Build internal editor" OFF)
18+
endif()
19+
20+
if(USE_VCPKG)
421
if(DEFINED ENV{VCPKG_ROOT})
522
if (CMAKE_TOOLCHAIN_FILE)
623
cmake_path(ABSOLUTE_PATH CMAKE_TOOLCHAIN_FILE NORMALIZE OUTPUT_VARIABLE VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
@@ -13,31 +30,16 @@ if(NOT DEFINED USE_VCPKG OR USE_VCPKG)
1330
# prevent endless recursion
1431
unset(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
1532
endif()
16-
elseif(USE_VCPKG)
33+
elseif(NOT USE_VCPKG STREQUAL "DEFAULT")
1734
message(WARNING "USE_VCPKG=${USE_VCPKG} but ENV{VCPKG_ROOT} not set; will use system-provided libraries. Did you forget to set VCPKG_ROOT in your environment?")
1835
endif()
1936
endif()
2037

21-
# set default cmake build type to Debug (None Debug Release RelWithDebInfo MinSizeRel)
22-
if(NOT CMAKE_BUILD_TYPE AND NOT DEFINED ENV{CMAKE_BUILD_TYPE})
23-
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "default build type")
24-
endif()
25-
2638
project(Descent3
2739
LANGUAGES C CXX
2840
VERSION 1.5.0
2941
)
3042

31-
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with Ninja)." OFF)
32-
option(FORCE_PORTABLE_INSTALL "Install all files into local directory defined by CMAKE_INSTALL_PREFIX" ON)
33-
option(ENABLE_LOGGER "Enable logging to the terminal" OFF)
34-
option(ENABLE_MEM_RTL "Enable Real-time library memory management functions (disable to verbose memory allocations)" ON)
35-
option(BUILD_TESTING "Enable testing. Requires GTest." OFF)
36-
37-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
38-
option(BUILD_EDITOR "Build internal editor" OFF)
39-
endif()
40-
4143
set(CMAKE_CXX_STANDARD 17)
4244
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4345
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

0 commit comments

Comments
 (0)