From f9f5dbd1d46c31ffc89c9b2f9f812da47fa2fba1 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 8 Sep 2026 18:08:09 +0200 Subject: [PATCH 1/2] Move project to use vcpkg --- .gitignore | 12 +- .gitmodules | 4 +- CMakeLists.txt | 71 ++++++- CMakePresets.json | 119 ++++++++++++ LICENSE.md | 21 ++ README.md | 22 +++ lib/CMakeLists.txt | 39 +++- support/cmake/codegenConfig.cmake.in | 6 + .../cmake}/common-compile-settings | 0 support/consumer-test/CMakeLists.txt | 51 +++++ support/consumer-test/main.cpp | 47 +++++ support/consumer-test/vcpkg.json | 18 ++ support/vcpkg/check-manifest-sync.cmake | 181 ++++++++++++++++++ support/vcpkg/ports/codegen/portfile.cmake | 60 ++++++ support/vcpkg/ports/codegen/usage | 10 + support/vcpkg/ports/codegen/vcpkg.json | 22 +++ vcpkg.json | 22 +++ 17 files changed, 688 insertions(+), 17 deletions(-) create mode 100644 CMakePresets.json create mode 100644 LICENSE.md create mode 100644 support/cmake/codegenConfig.cmake.in rename {cmake => support/cmake}/common-compile-settings (100%) create mode 100644 support/consumer-test/CMakeLists.txt create mode 100644 support/consumer-test/main.cpp create mode 100644 support/consumer-test/vcpkg.json create mode 100644 support/vcpkg/check-manifest-sync.cmake create mode 100644 support/vcpkg/ports/codegen/portfile.cmake create mode 100644 support/vcpkg/ports/codegen/usage create mode 100644 support/vcpkg/ports/codegen/vcpkg.json create mode 100644 vcpkg.json diff --git a/.gitignore b/.gitignore index 36e6b49..867ea04 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,14 @@ -build +build/ +out/ +.vs/ +.cache/ + +# vcpkg manifest-mode install tree +vcpkg_installed/ + +# Per-user CMake presets +CMakeUserPresets.json + tests/execution/*_codegen.cpp tests/execution_enums/*_codegen.cpp tests/execution_luawrapper/*_codegen.cpp diff --git a/.gitmodules b/.gitmodules index 6dcfd57..6e9a9c1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "cmake/common-compile-settings"] - path = cmake/common-compile-settings +[submodule "support/cmake/common-compile-settings"] + path = support/cmake/common-compile-settings url = https://github.com/OpenSpace/common-compile-settings diff --git a/CMakeLists.txt b/CMakeLists.txt index 5139b67..6b81b29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,12 +22,75 @@ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ########################################################################################## -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/common-compile-settings") -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/common-compile-settings/common-compile-settings.cmake) +cmake_minimum_required(VERSION 4.0) + +# The tests link openspace-core / openspace-module-collection and include +# , none of which exist outside the OpenSpace tree, so +# a standalone codegen checkout cannot build them yet. The option is kept (default OFF) for +# a future decoupling; OpenSpace's own CMakeLists adds support/coding/codegen/tests +# directly and does not consult this option. +option(CODEGEN_BUILD_TESTS "Build the codegen unit tests (requires the OpenSpace tree)" OFF) + +project(codegen VERSION 1.0.0 LANGUAGES CXX) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/support/cmake/common-compile-settings") +include(${CMAKE_CURRENT_SOURCE_DIR}/support/cmake/common-compile-settings/common-compile-settings.cmake) + +# Redirecting the output would leak into a surrounding project that vendors codegen +if (PROJECT_IS_TOP_LEVEL) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +endif () add_subdirectory(lib) add_executable(codegen-tool main.cpp) -target_link_libraries(codegen-tool PUBLIC codegen-lib) - +target_link_libraries(codegen-tool PRIVATE codegen-lib) set_compile_settings(codegen-tool) + +if (CODEGEN_BUILD_TESTS AND CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + enable_testing() + add_subdirectory(tests) +endif () + +# Install and export rules that make codegen consumable through +# `find_package(codegen CONFIG REQUIRED)`, both the `codegen::codegen-lib` library and the +# `codegen::codegen-tool` executable that a consumer runs as a build step +if (PROJECT_IS_TOP_LEVEL) + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) + + set(CODEGEN_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/codegen") + + install(TARGETS codegen-lib codegen-tool + EXPORT codegenTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + install( + EXPORT codegenTargets + FILE codegenTargets.cmake + NAMESPACE codegen:: + DESTINATION ${CODEGEN_INSTALL_CMAKEDIR} + ) + + configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/support/cmake/codegenConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/codegenConfig.cmake + INSTALL_DESTINATION ${CODEGEN_INSTALL_CMAKEDIR} + ) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/codegenConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion + ) + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/codegenConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/codegenConfigVersion.cmake + DESTINATION ${CODEGEN_INSTALL_CMAKEDIR} + ) +endif () diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..b151745 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,119 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 4, + "minor": 0, + "patch": 0 + }, + "configurePresets": [ + { + "name": "vcpkg", + "hidden": true, + "binaryDir": "${sourceDir}/build/${presetName}", + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" + }, + { + "name": "windows-base", + "hidden": true, + "inherits": "vcpkg", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + }, + "architecture": { + "value": "x64", + "strategy": "set" + } + }, + { + "name": "windows", + "inherits": "windows-base", + "displayName": "Windows x64", + "description": "Multi-config build against the dynamic vcpkg triplet", + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-windows" + } + }, + { + "name": "windows-static", + "inherits": "windows-base", + "displayName": "Windows x64 (static dependencies)", + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-windows-static" + } + }, + { + "name": "linux-base", + "hidden": true, + "inherits": "vcpkg", + "generator": "Ninja", + "cacheVariables": { + "VCPKG_TARGET_TRIPLET": "x64-linux" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "linux", + "inherits": "linux-base", + "displayName": "Linux x64 RelWithDebInfo", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "linux-debug", + "inherits": "linux-base", + "displayName": "Linux x64 Debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "linux-release", + "inherits": "linux-base", + "displayName": "Linux x64 Release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ], + "buildPresets": [ + { + "name": "windows", + "configurePreset": "windows", + "configuration": "RelWithDebInfo" + }, + { + "name": "windows-debug", + "configurePreset": "windows", + "configuration": "Debug" + }, + { + "name": "windows-release", + "configurePreset": "windows", + "configuration": "Release" + }, + { + "name": "windows-static", + "configurePreset": "windows-static", + "configuration": "RelWithDebInfo" + }, + { + "name": "linux", + "configurePreset": "linux" + }, + { + "name": "linux-debug", + "configurePreset": "linux-debug" + }, + { + "name": "linux-release", + "configurePreset": "linux-release" + } + ] +} diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..f0c15b2 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +# License +OpenSpace Codegen + +Copyright (c) 2021-2026 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this +software and associated documentation files (the "Software"), to deal in the Software +without restriction, including without limitation the rights to use, copy, modify, +merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be included in all copies +or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index a179ae3..6cda691 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,28 @@ Execution: Additionally, passing the `--verbose` parameter will cause CodeGen to emit extra information, including which files are currently being processed. +## Building +codegen configures through the [vcpkg](https://vcpkg.io) toolchain like Ghoul and SGCT, driven by `CMakePresets.json`. It has no third-party runtime dependencies; the only submodule is the shared `common-compile-settings` CMake helper. + +``` +git clone --recursive https://github.com/OpenSpace/codegen +cd codegen +cmake --preset windows # or: linux +cmake --build --preset windows +``` + +The unit tests under `tests/` link `openspace-core` and are only built from within the OpenSpace tree, not by this standalone build (`CODEGEN_BUILD_TESTS` stays `OFF`). + +### Consuming codegen +A superproject can pull codegen in as a vcpkg overlay port (`support/vcpkg/ports`) instead of `add_subdirectory`: + +```cmake +find_package(codegen CONFIG REQUIRED) +target_link_libraries(main PRIVATE codegen::codegen-lib) # and run codegen::codegen-tool as a build step +``` + +`support/vcpkg/check-manifest-sync.cmake` verifies the port's dependency list stays in sync with the root `vcpkg.json`, and `support/consumer-test/` is a minimal project that builds against the installed port. + ## Generated functions Running the codegen will create a number of functions in the generated `_codegen.cpp` file that can be used by including the file in the main `.cpp` file. diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 449abbe..1999cd8 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -22,26 +22,45 @@ # OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ########################################################################################## -add_library(codegen-lib) +# codegen-lib carries no symbol-export annotations, so it is always a static library +# regardless of BUILD_SHARED_LIBS (a vcpkg dynamic triplet would otherwise try to build it +# as a DLL with an empty export table) +add_library(codegen-lib STATIC) target_sources( codegen-lib PRIVATE - codegen.h codegen.cpp - keywords.h - parsing.h parsing.cpp - settings.h - snippets.h snippets.cpp - types.h types.cpp - util.h util.cpp - verifier.h verifier.cpp + PUBLIC + FILE_SET HEADERS + BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + codegen.h + keywords.h + parsing.h + settings.h + snippets.h + types.h + util.h + verifier.h ) -target_include_directories(codegen-lib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_include_directories(codegen-lib + PUBLIC + $ + $ +) set_compile_settings(codegen-lib) +# set_compile_settings links the interface-only compile_settings target PRIVATE, which for +# a static library would otherwise leave a dangling $ in the +# exported interface. Keep it for the in-tree build only, and carry the language-standard +# requirement (needed to compile the public headers: std::format, , ...) in +# the exported interface explicitly. +set_property(TARGET codegen-lib PROPERTY LINK_LIBRARIES "$") +set_property(TARGET codegen-lib PROPERTY INTERFACE_LINK_LIBRARIES "") +target_compile_features(codegen-lib PUBLIC cxx_std_23) diff --git a/support/cmake/codegenConfig.cmake.in b/support/cmake/codegenConfig.cmake.in new file mode 100644 index 0000000..12ac6ae --- /dev/null +++ b/support/cmake/codegenConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +# codegen has no third-party dependencies, so there is nothing to find_dependency() here. +include("${CMAKE_CURRENT_LIST_DIR}/codegenTargets.cmake") + +check_required_components(codegen) diff --git a/cmake/common-compile-settings b/support/cmake/common-compile-settings similarity index 100% rename from cmake/common-compile-settings rename to support/cmake/common-compile-settings diff --git a/support/consumer-test/CMakeLists.txt b/support/consumer-test/CMakeLists.txt new file mode 100644 index 0000000..5d88e5a --- /dev/null +++ b/support/consumer-test/CMakeLists.txt @@ -0,0 +1,51 @@ +########################################################################################## +# # +# OpenSpace Codegen # +# # +# Copyright (c) 2021-2026 # +# # +# Permission is hereby granted, free of charge, to any person obtaining a copy of this # +# software and associated documentation files (the "Software"), to deal in the Software # +# without restriction, including without limitation the rights to use, copy, modify, # +# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the following # +# conditions: # +# # +# The above copyright notice and this permission notice shall be included in all copies # +# or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # +# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # +# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE # +# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +########################################################################################## + +# Minimal stand-in for a third-party project. It consumes codegen the same way an external +# developer would - through the `codegen` overlay port and `find_package` - and therefore +# catches breakage in the port, the install rules, and the exported targets that building +# codegen in-tree cannot catch. +# +# cmake -S support/consumer-test -B build/consumer-test +# --toolchain $env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake +# -DVCPKG_TARGET_TRIPLET=x64-windows +# cmake --build build/consumer-test +# ctest --test-dir build/consumer-test + +cmake_minimum_required(VERSION 3.25) +project(CodegenConsumerTest LANGUAGES CXX) + +find_package(codegen CONFIG REQUIRED) + +add_executable(CodegenConsumerTest main.cpp) +target_compile_features(CodegenConsumerTest PRIVATE cxx_std_23) +target_link_libraries(CodegenConsumerTest PRIVATE codegen::codegen-lib) + +enable_testing() +add_test(NAME CodegenConsumerTest COMMAND CodegenConsumerTest) + +# The exported executable target has to be runnable for a superproject that drives codegen +# as a build step. Point it at an empty directory so it does a clean no-op run (exit 0) +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/emptyscan) +add_test(NAME CodegenTool COMMAND codegen::codegen-tool ${CMAKE_CURRENT_BINARY_DIR}/emptyscan) diff --git a/support/consumer-test/main.cpp b/support/consumer-test/main.cpp new file mode 100644 index 0000000..660971b --- /dev/null +++ b/support/consumer-test/main.cpp @@ -0,0 +1,47 @@ +/***************************************************************************************** + * * + * OpenSpace Codegen * + * * + * Copyright (c) 2021-2026 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +// Touches headers from the installed codegen-lib so that a missing installed header, a +// broken include directory in the exported target, or a missing language-standard +// requirement shows up as a compile or link error. + +#include "util.h" +#include "keywords.h" + +#include +#include + +int main() { + if (strip(" value ") != "value") { + std::puts("codegen-lib strip() did not round-trip"); + return 1; + } + if (!startsWith("codegen::Dictionary", "codegen::")) { + std::puts("codegen-lib startsWith() failed"); + return 1; + } + + std::puts("codegen consumer test succeeded"); + return 0; +} diff --git a/support/consumer-test/vcpkg.json b/support/consumer-test/vcpkg.json new file mode 100644 index 0000000..fe12d6e --- /dev/null +++ b/support/consumer-test/vcpkg.json @@ -0,0 +1,18 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "codegen-consumer-test", + "version-string": "0.0.1", + "description": "Regression project that links against an installed codegen", + "vcpkg-configuration": { + "default-registry": { + "kind": "builtin", + "baseline": "04a9d8e5212d01ee1dd9478eadd9caade4f8b0d4" + }, + "overlay-ports": [ + "../vcpkg/ports" + ] + }, + "dependencies": [ + "codegen" + ] +} diff --git a/support/vcpkg/check-manifest-sync.cmake b/support/vcpkg/check-manifest-sync.cmake new file mode 100644 index 0000000..0f610c3 --- /dev/null +++ b/support/vcpkg/check-manifest-sync.cmake @@ -0,0 +1,181 @@ +########################################################################################## +# # +# OpenSpace Codegen # +# # +# Copyright (c) 2021-2026 # +# # +# Permission is hereby granted, free of charge, to any person obtaining a copy of this # +# software and associated documentation files (the "Software"), to deal in the Software # +# without restriction, including without limitation the rights to use, copy, modify, # +# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the following # +# conditions: # +# # +# The above copyright notice and this permission notice shall be included in all copies # +# or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # +# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # +# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE # +# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +########################################################################################## + +# Verifies that the `codegen` overlay port under support/vcpkg/ports declares the same +# runtime dependencies and optional features as the root vcpkg.json. A superproject that +# adds codegen through the port (instead of add_subdirectory) cannot use codegen's own +# manifest, since vcpkg only reads the manifest of the top-level project, so the two lists +# have to stay identical apart from the intentional differences listed below. +# +# Intentional differences (a mismatch in these is allowed, anything else is an error): +# - the port additionally depends on the vcpkg-cmake / vcpkg-cmake-config host tools, +# which the standalone manifest gets from vcpkg itself +# +# Run with: cmake -P support/vcpkg/check-manifest-sync.cmake + +cmake_minimum_required(VERSION 3.19) + +get_filename_component(CODEGEN_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE) +set(MANIFEST "${CODEGEN_ROOT_DIR}/vcpkg.json") +set(PORT "${CMAKE_CURRENT_LIST_DIR}/ports/codegen/vcpkg.json") + +# Dependencies that are allowed to appear only in the port +set(PORT_ONLY_DEPENDENCIES "vcpkg-cmake" "vcpkg-cmake-config") +# Features that are allowed to appear only in the manifest +set(MANIFEST_ONLY_FEATURES "") + +function (flatten_dependencies outVar dependencies) + set(result "") + string(JSON count LENGTH "${dependencies}") + if (count GREATER 0) + math(EXPR lastIndex "${count} - 1") + foreach (i RANGE ${lastIndex}) + string(JSON entryType TYPE "${dependencies}" ${i}) + string(JSON entry GET "${dependencies}" ${i}) + + if (entryType STREQUAL "STRING") + list(APPEND result "${entry}") + continue () + endif () + + string(JSON name GET "${entry}" "name") + + string(JSON features ERROR_VARIABLE featuresError GET "${entry}" "features") + set(featureList "") + if (featuresError STREQUAL "NOTFOUND") + string(JSON featureCount LENGTH "${features}") + if (featureCount GREATER 0) + math(EXPR lastFeature "${featureCount} - 1") + foreach (j RANGE ${lastFeature}) + string(JSON feature GET "${features}" ${j}) + list(APPEND featureList "${feature}") + endforeach () + list(SORT featureList) + endif () + endif () + list(JOIN featureList "+" featureText) + + string(JSON defaults ERROR_VARIABLE defaultsError GET "${entry}" "default-features") + if (NOT defaultsError STREQUAL "NOTFOUND") + set(defaults "ON") + endif () + + list(APPEND result "${name}[${featureText}](default-features=${defaults})") + endforeach () + endif () + + list(SORT result) + set(${outVar} "${result}" PARENT_SCOPE) +endfunction () + +# Removes every flattened entry whose dependency name is in `excluded` from `list` +function (drop_dependencies outVar list excluded) + set(result "") + foreach (entry IN LISTS list) + string(REGEX REPLACE "\\[.*$" "" entryName "${entry}") + if (NOT entryName IN_LIST excluded) + list(APPEND result "${entry}") + endif () + endforeach () + set(${outVar} "${result}" PARENT_SCOPE) +endfunction () + +function (feature_names outVar features) + string(JSON count LENGTH "${features}") + set(result "") + if (count GREATER 0) + math(EXPR lastIndex "${count} - 1") + foreach (i RANGE ${lastIndex}) + string(JSON name MEMBER "${features}" ${i}) + list(APPEND result "${name}") + endforeach () + list(SORT result) + endif () + set(${outVar} "${result}" PARENT_SCOPE) +endfunction () + +# Returns the "dependencies" array of `feature`, or "[]" if the feature declares none +function (feature_dependencies outVar features feature) + string(JSON deps ERROR_VARIABLE depsError GET "${features}" "${feature}" "dependencies") + if (NOT depsError STREQUAL "NOTFOUND") + set(deps "[]") + endif () + set(${outVar} "${deps}" PARENT_SCOPE) +endfunction () + +file(READ "${MANIFEST}" manifestJson) +file(READ "${PORT}" portJson) + +set(errors "") + +string(JSON manifestDependencies ERROR_VARIABLE manifestDepsError GET "${manifestJson}" "dependencies") +if (NOT manifestDepsError STREQUAL "NOTFOUND") + set(manifestDependencies "[]") +endif () +string(JSON portDependencies ERROR_VARIABLE portDepsError GET "${portJson}" "dependencies") +if (NOT portDepsError STREQUAL "NOTFOUND") + set(portDependencies "[]") +endif () +flatten_dependencies(manifestDeps "${manifestDependencies}") +flatten_dependencies(portDeps "${portDependencies}") +drop_dependencies(portDeps "${portDeps}" "${PORT_ONLY_DEPENDENCIES}") +if (NOT manifestDeps STREQUAL portDeps) + list(APPEND errors " dependencies\n vcpkg.json: ${manifestDeps}\n port: ${portDeps}") +endif () + +string(JSON manifestFeatures ERROR_VARIABLE manifestFeaturesError GET "${manifestJson}" "features") +if (NOT manifestFeaturesError STREQUAL "NOTFOUND") + set(manifestFeatures "{}") +endif () +string(JSON portFeatures ERROR_VARIABLE portFeaturesError GET "${portJson}" "features") +if (NOT portFeaturesError STREQUAL "NOTFOUND") + set(portFeatures "{}") +endif () +feature_names(manifestFeatureNames "${manifestFeatures}") +feature_names(portFeatureNames "${portFeatures}") +if (manifestFeatureNames AND MANIFEST_ONLY_FEATURES) + list(REMOVE_ITEM manifestFeatureNames ${MANIFEST_ONLY_FEATURES}) +endif () +if (NOT manifestFeatureNames STREQUAL portFeatureNames) + list(APPEND errors " feature names\n vcpkg.json: ${manifestFeatureNames}\n port: ${portFeatureNames}") +else () + foreach (feature ${manifestFeatureNames}) + feature_dependencies(manifestFeatureDependencies "${manifestFeatures}" "${feature}") + feature_dependencies(portFeatureDependencies "${portFeatures}" "${feature}") + flatten_dependencies(manifestFeatureDeps "${manifestFeatureDependencies}") + flatten_dependencies(portFeatureDeps "${portFeatureDependencies}") + if (NOT manifestFeatureDeps STREQUAL portFeatureDeps) + list(APPEND errors " feature '${feature}'\n vcpkg.json: ${manifestFeatureDeps}\n port: ${portFeatureDeps}") + endif () + endforeach () +endif () + +if (errors) + list(JOIN errors "\n" errorText) + message(FATAL_ERROR + "vcpkg.json and support/vcpkg/ports/codegen/vcpkg.json have diverged:\n${errorText}\n" + ) +endif () + +message(STATUS "vcpkg.json and the codegen port are in sync") diff --git a/support/vcpkg/ports/codegen/portfile.cmake b/support/vcpkg/ports/codegen/portfile.cmake new file mode 100644 index 0000000..6879053 --- /dev/null +++ b/support/vcpkg/ports/codegen/portfile.cmake @@ -0,0 +1,60 @@ +########################################################################################## +# # +# OpenSpace Codegen # +# # +# Copyright (c) 2021-2026 # +# # +# Permission is hereby granted, free of charge, to any person obtaining a copy of this # +# software and associated documentation files (the "Software"), to deal in the Software # +# without restriction, including without limitation the rights to use, copy, modify, # +# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the following # +# conditions: # +# # +# The above copyright notice and this permission notice shall be included in all copies # +# or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # +# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # +# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE # +# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +########################################################################################## + +# This port lives inside the codegen repository and builds the enclosing checkout. When +# publishing codegen to a registry, replace this with vcpkg_from_github(REPO OpenSpace/codegen +# REF SHA512 ) so that the port is reproducible and content-addressed. +get_filename_component(SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../.." ABSOLUTE) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + # The tests only exercise this checkout and need the OpenSpace tree, which a consumer + # of the port does not have + -DCODEGEN_BUILD_TESTS=OFF +) + +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(CONFIG_PATH share/codegen) + +# codegen's public headers (types.h, util.h, ...) install flat into /include and +# have generic names that vcpkg flags as "restricted". codegen is consumed only by +# OpenSpace through this in-repo overlay port (never the curated registry), and the same +# flat layout is what the in-tree build uses, so the layout is kept and the check relaxed. +# If codegen is ever published, move the headers into an include/codegen/ subdirectory +# instead of enabling this policy. +set(VCPKG_POLICY_ALLOW_RESTRICTED_HEADERS enabled) + +# codegen-tool is a build-time helper: move it out of bin/ into tools/ so it does not land +# in a consumer's runtime directory +vcpkg_copy_tools(TOOL_NAMES codegen-tool AUTO_CLEAN) +vcpkg_copy_pdbs() + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md") diff --git a/support/vcpkg/ports/codegen/usage b/support/vcpkg/ports/codegen/usage new file mode 100644 index 0000000..8de53dd --- /dev/null +++ b/support/vcpkg/ports/codegen/usage @@ -0,0 +1,10 @@ +codegen provides CMake targets: + + find_package(codegen CONFIG REQUIRED) + target_link_libraries(main PRIVATE codegen::codegen-lib) + +and the code generator executable as an imported target: + + codegen::codegen-tool + +which is installed under tools/codegen and is on the PATH during a vcpkg build. diff --git a/support/vcpkg/ports/codegen/vcpkg.json b/support/vcpkg/ports/codegen/vcpkg.json new file mode 100644 index 0000000..d8f7390 --- /dev/null +++ b/support/vcpkg/ports/codegen/vcpkg.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "codegen", + "version": "1.0.0", + "description": [ + "OpenSpace code generator.", + "This port lives inside the codegen repository and builds the enclosing checkout. It ships the codegen::codegen-lib library and the codegen-tool executable that a consumer runs as a build step. The dependency list is kept in sync with the manifest at the root of the repository by support/vcpkg/check-manifest-sync.cmake, except that this port depends on the vcpkg-cmake host tools explicitly." + ], + "homepage": "https://github.com/OpenSpace/codegen", + "license": "MIT", + "supports": "!(osx | uwp | android)", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..118d770 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "name": "codegen", + "version": "1.0.0", + "description": [ + "OpenSpace code generator.", + "codegen has no third-party runtime dependencies. This manifest exists so the repository configures through the vcpkg toolchain like Ghoul and SGCT, and so support/vcpkg/check-manifest-sync.cmake can verify that the overlay port under support/vcpkg/ports/codegen stays in sync with it. The only intentional difference is that the port depends on the vcpkg-cmake host tools explicitly." + ], + "homepage": "https://github.com/OpenSpace/codegen", + "license": "MIT", + "supports": "!(osx | uwp | android)", + "vcpkg-configuration": { + "default-registry": { + "kind": "builtin", + "baseline": "04a9d8e5212d01ee1dd9478eadd9caade4f8b0d4" + }, + "overlay-ports": [ + "./support/vcpkg/ports" + ] + }, + "dependencies": [] +} From 7d15ae22c53de3e3d7ad193a8b610aa18c80ef30 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Tue, 8 Sep 2026 21:58:33 +0200 Subject: [PATCH 2/2] Correctly require Catch2 --- tests/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e9d9cd6..5ddcd64 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -206,7 +206,8 @@ target_sources( parsing_structs/parsing_structs_variant_fail.cpp ) -target_link_libraries(codegentest PRIVATE Catch2 codegen-lib openspace-core openspace-module-collection) +find_package(Catch2 CONFIG REQUIRED) +target_link_libraries(codegentest PRIVATE Catch2::Catch2 codegen-lib openspace-core openspace-module-collection) set_compile_settings(codegentest)