Skip to content

Commit

Permalink
autobuild.cmake to handle cmake < 3.19 which has no preset support
Browse files Browse the repository at this point in the history
  • Loading branch information
tamasmeszaros committed Oct 27, 2023
1 parent ca0ca6d commit df911a7
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
7 changes: 4 additions & 3 deletions deps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ include(${PROJECT_SOURCE_DIR}/../cmake/modules/AddCMakeProject.cmake)
set(supported_packages Boost heatshrink Catch2 ZLIB pybind11)

include(CMakeDependentOption)
option(${PROJECT_NAME}_SELECT_ALL "Choose all external projects to be built." ON)
option(${PROJECT_NAME}_SELECT_ALL "Choose all external projects to be selected (create build target for them)." ON)
option(${PROJECT_NAME}_BUILD_ALL "Choose all external projects to be built." ON)

find_package(Git REQUIRED)

# The default command line for patching. Only works for newer
set(PATCH_CMD ${GIT_EXECUTABLE} apply --verbose --ignore-space-change --whitespace=fix)

foreach (pkg ${supported_packages})
option(${PROJECT_NAME}_SELECT_${pkg} "Select package ${pkg} to be built." OFF)
if (${PROJECT_NAME}_SELECT_ALL OR ${PROJECT_NAME}_SELECT_${pkg})
option(${PROJECT_NAME}_BUILD_${pkg} "Select package ${pkg} to be built." OFF)
if (${PROJECT_NAME}_SELECT_ALL OR ${PROJECT_NAME}_BUILD_ALL OR ${PROJECT_NAME}_BUILD_${pkg})
include(${pkg}/${pkg}.cmake)
endif ()
endforeach()
Expand Down
4 changes: 2 additions & 2 deletions deps/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"description": "Python module dependencies",
"binaryDir": "${sourceDir}/build-python-module",
"cacheVariables": {
"LibBGCode_Deps_SELECT_pybind11": true
"LibBGCode_Deps_BUILD_pybind11": true
}
},
{
Expand All @@ -30,7 +30,7 @@
"binaryDir": "${sourceDir}/build-wasm",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "MinSizeRel",
"LibBGCode_Deps_SELECT_ZLIB": {
"LibBGCode_Deps_BUILD_ZLIB": {
"type": "BOOL",
"value": "ON"
}
Expand Down
2 changes: 1 addition & 1 deletion deps/ZLIB/ZLIB.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

set(_exclude_from_all OFF)

if (UNIX AND NOT ${PROJECT_NAME}_SELECT_ZLIB AND NOT EMSCRIPTEN)
if (UNIX AND NOT ${PROJECT_NAME}_BUILD_ZLIB AND NOT EMSCRIPTEN AND NOT ${PROJECT_NAME}_BUILD_ALL)
set(_exclude_from_all ON)
endif ()

Expand Down
9 changes: 8 additions & 1 deletion deps/autobuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ endif ()

message(STATUS "build dir = ${_build_dir}")

set(_preset_arg "--preset ${${PROJECT_NAME}_DEPS_PRESET}")
if (CMAKE_VERSION VERSION_LESS 3.19)
message(WARNING "CMake presets are not supported with this version of CMake. Building all dependency packages!")
set(_preset_arg "." )
list(APPEND _build_args "-DLibBGCode_Deps_BUILD_ALL:BOOL=ON")
endif ()

execute_process(
COMMAND ${CMAKE_COMMAND} --preset ${${PROJECT_NAME}_DEPS_PRESET} "${_gen_arg}" -B ${_build_dir} ${_build_args}
COMMAND ${CMAKE_COMMAND} "${_preset_arg}" "${_gen_arg}" -B ${_build_dir} ${_build_args}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
${_output_quiet}
ERROR_VARIABLE _deps_configure_output
Expand Down
4 changes: 2 additions & 2 deletions deps/pybind11/pybind11.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set(_exclude_from_all OFF)

if (NOT ${PROJECT_NAME}_SELECT_pybind11)
if (NOT ${PROJECT_NAME}_BUILD_pybind11 AND NOT ${PROJECT_NAME}_BUILD_ALL)
set(_exclude_from_all ON)
endif ()

Expand All @@ -10,4 +10,4 @@ add_cmake_project(pybind11
URL_HASH SHA256=b011a730c8845bfc265f0f81ee4e5e9e1d354df390836d2a25880e123d021f89
CMAKE_ARGS
-DPYBIND11_TEST:BOOL=OFF
)
)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ install_components = ["python_modules"]
build_args = ["--target", "build_and_test"]
# preset = "python-module"
# build_presets = ["python-module"]
# build_path = "build"
# build_path = "build"

0 comments on commit df911a7

Please sign in to comment.