Skip to content

Commit

Permalink
fixed configuration bug when invoked for the first time after a clone
Browse files Browse the repository at this point in the history
  • Loading branch information
vorlac committed Sep 1, 2023
1 parent b73c2a1 commit 7ca4369
Showing 1 changed file with 52 additions and 44 deletions.
96 changes: 52 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,38 @@
## Uncomment to output a dump of every CMake variable
# set(CMAKE_MESSAGE_LOG_LEVEL DEBUG)

# =======================================================================
# VCPKG submodule init/update. Needs to happen before anything else
# because this submodule contains a toolchain file needed for the
# main project configuration, which must set before project() is called
# =======================================================================

# confirm we found the vcpkg submodule ports dir.
# if the sources list is empty, the submodule probably
# hasn't been initialized or updated yet.
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/ports")
message(NOTICE "VCPKG package manager sources not found")
message(NOTICE "initializing/updating the vcpkg submodule...")

# update the vcpkg submodule to populate it with the code necessary
# to grab all dependencies needed for the gdextension library build
execute_process(
COMMAND git submodule update --init extern/vcpkg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()

# define toolchain file early for vcpkg. only set the variable if the file exists.
# if this is the first configuration after a clean clone of this repo, this file
# won't exist until the submodule is initialized below. configuration will fail if this
# is set to a path that doesn't exist, so only set it after the first pass of configuration
if(NOT CMAKE_TOOLCHAIN_FILE)
# define toolchain file early for vcpkg. only set the variable if the file exists.
# if this is the first configuration after a clean clone of this repo, this file
# won't exist until the submodule is initialized below. configuration will fail if this
# is set to a path that doesn't exist, so only set it after the first pass of configuration
set(toolchain_file_path "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/scripts/buildsystems/vcpkg.cmake")
if (EXISTS "${toolchain_file_path}")
set(CMAKE_TOOLCHAIN_FILE "${toolchain_file_path}")
else()
message(WARNING "VCPKG toolchain file not found: ${toolchain_file_path}")
endif()
endif()

Expand Down Expand Up @@ -38,26 +62,6 @@ set(CMAKE_COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/project/bin"
# postfix debug binaries with "d"
set(CMAKE_DEBUG_POSTFIX "d")

# =======================================================================
# Godot Engine and C++ bindings submodule management
# =======================================================================

# confirm we found the godot engine source files.
# if the sources list is empty, the submodule probably
# hasn't been initialized or updated yet.
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/src")
message(NOTICE "godot-cpp bingings source not found")
message(NOTICE "initializing/updating the godot-cpp submodule...")

# update the c++ bingings submodule to populate it with
# the necessary source for the gdextension library
execute_process(
COMMAND git submodule update --init extern/godot-cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()

# confirm we found the godot engine source files.
# if the sources list is empty, the submodule probably
# hasn't been initialized or updated yet.
Expand All @@ -70,30 +74,14 @@ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-engine/core")
# can be easily debugged along with the gdextension library
execute_process(
COMMAND git submodule update --init extern/godot-engine
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()

# confirm we found the vcpkg submodule ports dir.
# if the sources list is empty, the submodule probably
# hasn't been initialized or updated yet.
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/ports")
message(NOTICE "VCPKG package manager sources not found")
message(NOTICE "initializing/updating the vcpkg submodule...")

# update the vcpkg submodule to populate it with the code necessary
# to grab all dependencies needed for the gdextension library build
execute_process(
COMMAND git submodule update --init extern/vcpkg
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
endif()

# =======================================================================
# VCPKG bootstrap / initialization.
# Only happens once, when vcpkg.exe is missing.
# Only happens once, when vcpkg executable is missing.
# =======================================================================

set(vcpkg_executable "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/vcpkg${CMAKE_EXECUTABLE_SUFFIX}")
Expand All @@ -107,13 +95,13 @@ else()

if(WIN32)
execute_process(
COMMAND ps -c "./extern/vcpkg/bootstrap-vcpkg.bat"
COMMAND ps -c "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/bootstrap-vcpkg.bat"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
elseif(UNIX)
execute_process(
COMMAND bash "./extern/vcpkg/bootstrap-vcpkg.sh"
COMMAND bash "${CMAKE_CURRENT_SOURCE_DIR}/extern/vcpkg/bootstrap-vcpkg.sh"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND_ERROR_IS_FATAL ANY
)
Expand All @@ -125,6 +113,26 @@ else()
endif()
endif()

# =======================================================================
# Godot Engine and C++ bindings submodule management
# =======================================================================

# confirm we found the godot engine source files.
# if the sources list is empty, the submodule probably
# hasn't been initialized or updated yet.
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/godot-cpp/src")
message(NOTICE "godot-cpp bingings source not found")
message(NOTICE "initializing/updating the godot-cpp submodule...")

# update the c++ bingings submodule to populate it with
# the necessary source for the gdextension library
execute_process(
COMMAND git submodule update --init extern/godot-cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()

# =======================================================================
# Godot editor/engine debug build
# =======================================================================
Expand Down

0 comments on commit 7ca4369

Please sign in to comment.