Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build as an installable package and use vcpkg manifest mode to build standalone #1026

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 62 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,38 @@ if (NOT VCPKG_LIBRARY_LINKAGE)
set(VCPKG_LIBRARY_LINKAGE static)
endif()

if(NOT VCPKG_MANIFEST_MODE)
# Don't use ezvcpkg if it appears that this configuration is using
# vcpkg already, either by building cesium-native directly,
# or via a higher level project that has added cesium-native as a
# subdirectory and using vcpkg to statisfy its dependencies,
# presumably in manifest mode.

set(CESIUM_USE_EZVCPKG_DEFAULT ON)
if (VCPKG_MANIFEST_MODE)
set(CESIUM_USE_EZVCPKG_DEFAULT OFF)
elseif (CMAKE_TOOLCHAIN_FILE)
get_filename_component(toolchainFile "${CMAKE_TOOLCHAIN_FILE}" NAME)
if(toolchainFile STREQUAL "vcpkg.cmake")
set(CESIUM_USE_EZVCPKG_DEFAULT OFF)
endif()
endif()

option(CESIUM_USE_EZVCPKG "use ezvcpkg helper" ${CESIUM_USE_EZVCPKG_DEFAULT})

if(CESIUM_USE_EZVCPKG)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/ezvcpkg/ezvcpkg.cmake)
endif()

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/detect-vcpkg-triplet.cmake)

# Note: VCPKG_TRIPLET is not used by vcpkg! The relevant variables are
# VCPKG_TARGET_TRIPLET and VCPKG_HOST_TRIPLET. ezvcpkg and our custom
# installation code use VCPKG_TRIPLET, so we initialize it.

if (VCPKG_TARGET_TRIPLET)
set(VCPKG_TRIPLET "${VCPKG_TARGET_TRIPLET}")
endif()

if (NOT VCPKG_TRIPLET)
if (DEFINED ENV{VCPKG_TRIPLET})
set(VCPKG_TRIPLET "$ENV{VCPKG_TRIPLET}")
Expand All @@ -21,9 +47,13 @@ if (NOT VCPKG_TRIPLET)
else()
set(VCPKG_TRIPLET "${DETECTED_VCPKG_TRIPLET}")
endif()
if (NOT CESIUM_USE_EZVCPKG)
set(VCPKG_TARGET_TRIPLET "${VCPKG_TRIPLET}")
endif()
endif()

message(STATUS "VCPKG_TRIPLET ${VCPKG_TRIPLET}")
message(STATUS "VCPKG_TARGET_TRIPLET ${VCPKG_TARGET_TRIPLET}")

if (NOT VCPKG_OVERLAY_PORTS)
if (DEFINED ENV{VCPKG_OVERLAY_PORTS})
Expand Down Expand Up @@ -58,7 +88,7 @@ set(PACKAGES_PRIVATE
# Packages only used for testing
set(PACKAGES_TEST catch2)

if(NOT VCPKG_MANIFEST_MODE)
if(CESIUM_USE_EZVCPKG)
set(PACKAGES_ALL ${PACKAGES_PUBLIC})
list(APPEND PACKAGES_ALL ${PACKAGES_PRIVATE})
list(APPEND PACKAGES_ALL ${PACKAGES_TEST})
Expand Down Expand Up @@ -95,7 +125,7 @@ include(CMakeDependentOption)
set(PACKAGE_BASE_DIR "${EZVCPKG_PACKAGES_DIR}")
set(PACKAGE_BUILD_DIR "${EZVCPKG_DIR}")

if(VCPKG_MANIFEST_MODE)
if(NOT EZVCPKG_PACKAGES_DIR)
set(PACKAGE_BUILD_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TRIPLET}/")
set(PACKAGE_BASE_DIR "$ENV{VCPKG_ROOT}/packages")
endif()
Expand All @@ -116,7 +146,7 @@ cmake_dependent_option(
OFF
)

if(CESIUM_INSTALL_STATIC_LIBS OR CESIUM_INSTALL_HEADERS)
if(CESIUM_INSTALL_STATIC_LIBS OR CESIUM_INSTALL_HEADERS AND EZVCPKG_PACKAGES_DIR)
foreach(PACKAGE ${PACKAGES_PUBLIC})
string(REGEX REPLACE "\[.*\]" "" PACKAGE ${PACKAGE})
set(PACKAGE_DIR ${PACKAGE_BASE_DIR}/${PACKAGE}_${VCPKG_TRIPLET})
Expand All @@ -138,7 +168,7 @@ if(CESIUM_INSTALL_STATIC_LIBS OR CESIUM_INSTALL_HEADERS)
endforeach()
endif()

if(CESIUM_INSTALL_STATIC_LIBS)
if(CESIUM_INSTALL_STATIC_LIBS AND NOT VCPKG_MANIFEST_MODE)
foreach(PACKAGE ${PACKAGES_PRIVATE})
set(PACKAGE_DIR ${PACKAGE_BASE_DIR}/${PACKAGE}_${VCPKG_TRIPLET})
message(DEBUG "PACKAGE_DIR ${PACKAGE_DIR}")
Expand Down Expand Up @@ -205,6 +235,7 @@ if(CESIUM_ENABLE_CLANG_TIDY)
endif()

# Add Modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/extern/cmake-modules/")
if (CESIUM_COVERAGE_ENABLED AND NOT MSVC)
include(CodeCoverage)
Expand Down Expand Up @@ -238,6 +269,14 @@ list(APPEND CMAKE_PREFIX_PATH "${PACKAGE_BUILD_DIR}")
# However, for some of the vcpkg built libraries where they don't provide a prope cmake config file, we have to declare
# and imporeted library target ourselves. This is the case for modp_b64::modp_b64, picosha2::picosha2 and earcut. In
# these cases, we *do* have the somewhat ugly and verbose details in the extern/CMakeLists.txt file.
#
# XXX Above comment should be obsoleted by these first calls to
# find_package, which resolve to our own modules that provide
# targets. If needed, they can be installed with CMake config files
# etc.
find_package(zlib-ng REQUIRED)
find_package(modp_b64 REQUIRED)

find_package(Async++ CONFIG REQUIRED)
find_package(Catch2 CONFIG REQUIRED)
find_package(draco CONFIG REQUIRED)
Expand Down Expand Up @@ -290,3 +329,21 @@ endif()


add_subdirectory(doc)

include(CMakePackageConfigHelpers)

install(EXPORT CesiumExports
FILE cesium-nativeTargets.cmake
DESTINATION ${CMAKE_INSTALL_DATADIR}/cesium-native/cmake)

install(FILES
"${CMAKE_CURRENT_LIST_DIR}/cmake/modules/Findzlib-ng.cmake"
"${CMAKE_CURRENT_LIST_DIR}/cmake/modules/Findmodp_b64.cmake"
DESTINATION ${CMAKE_INSTALL_DATADIR}/cesium-native/cmake)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/cesium-nativeConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/cesium-native/cmake)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cesium-nativeConfig.cmake
DESTINATION ${CMAKE_INSTALL_DATADIR}/cesium-native/cmake)
25 changes: 25 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 3,
"configurePresets": [
{
"name": "vcpkg",
"binaryDir": "${sourceDir}/build",
"generator": "Ninja",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "Release",
"CESIUM_USE_EZVCPKG": "OFF"
}
},
{
"name": "vcpkg-ninja-multi",
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"CMAKE_BUILD_TYPE": "Release",
"CESIUM_USE_EZVCPKG": "OFF"
}
}
]
}
6 changes: 3 additions & 3 deletions Cesium3DTiles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ target_sources(
PRIVATE
${CESIUM_3DTILES_SOURCES}
${CESIUM_3DTILES_HEADERS}
PUBLIC
${CESIUM_3DTILES_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
Cesium3DTiles
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/generated/include
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/generated/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/generated/src
Expand Down
1 change: 0 additions & 1 deletion Cesium3DTilesContent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ target_sources(
PRIVATE
${CESIUM_3DTILES_CONTENT_SOURCES}
${CESIUM_3DTILES_CONTENT_HEADERS}
PUBLIC
${CESIUM_3DTILES_CONTENT_PUBLIC_HEADERS}
)

Expand Down
6 changes: 3 additions & 3 deletions Cesium3DTilesReader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ target_sources(
PRIVATE
${CESIUM_3DTILES_READER_SOURCES}
${CESIUM_3DTILES_READER_HEADERS}
PUBLIC
${CESIUM_3DTILES_READER_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
Cesium3DTilesReader
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/generated/include
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/generated/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/generated/src
Expand Down
9 changes: 6 additions & 3 deletions Cesium3DTilesSelection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ target_sources(
PRIVATE
${CESIUM_3DTILES_SELECTION_SOURCES}
${CESIUM_3DTILES_SELECTION_HEADERS}
PUBLIC
${CESIUM_3DTILES_SELECTION_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
Cesium3DTilesSelection
PUBLIC
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_LIST_DIR}/include
$<BUILD_INTERFACE:${CESIUM_NATIVE_RAPIDJSON_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CESIUM_NATIVE_DRACO_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CESIUM_NATIVE_LIBMORTON_INCUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
)
Expand Down
8 changes: 4 additions & 4 deletions Cesium3DTilesSelection/src/TileID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ TileIdUtilities::createTileIdString(const TileID& tileId) {
std::string
operator()(const CesiumGeometry::QuadtreeTileID& quadtreeTileId) {
// Strings of the form "L10-X23-Y144"
return "L" + std::to_string(quadtreeTileId.level) + "-" + "X" +
std::to_string(quadtreeTileId.x) + "-" + "Y" +
return std::string("L") + std::to_string(quadtreeTileId.level) + "-" +
"X" + std::to_string(quadtreeTileId.x) + "-" + "Y" +
std::to_string(quadtreeTileId.y);
}

std::string operator()(const CesiumGeometry::OctreeTileID& octreeTileId) {
// Strings of the form "L10-X23-Y144-Z42"
return "L" + std::to_string(octreeTileId.level) + "-" + "X" +
return std::string("L") + std::to_string(octreeTileId.level) + "-" + "X" +
std::to_string(octreeTileId.x) + "-" + "Y" +
std::to_string(octreeTileId.y) + "-" + "Z" +
std::to_string(octreeTileId.z);
Expand All @@ -31,7 +31,7 @@ TileIdUtilities::createTileIdString(const TileID& tileId) {
std::string operator()(
const CesiumGeometry::UpsampledQuadtreeNode& upsampledQuadtreeNode) {
// Strings of the form "upsampled-L10-X23-Y144"
return "upsampled-L" +
return std::string("upsampled-L") +
std::to_string(upsampledQuadtreeNode.tileID.level) + "-" + "X" +
std::to_string(upsampledQuadtreeNode.tileID.x) + "-" + "Y" +
std::to_string(upsampledQuadtreeNode.tileID.y);
Expand Down
6 changes: 3 additions & 3 deletions Cesium3DTilesWriter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ target_sources(
PRIVATE
${CESIUM_3DTILES_WRITER_SOURCES}
${CESIUM_3DTILES_WRITER_HEADERS}
PUBLIC
${CESIUM_3DTILES_WRITER_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
Cesium3DTilesWriter
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/generated/include
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/generated/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/generated/src
Expand Down
7 changes: 4 additions & 3 deletions CesiumAsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ target_sources(
PRIVATE
${CESIUM_ASYNC_SOURCES}
${CESIUM_ASYNC_HEADERS}
PUBLIC
${CESIUM_ASYNC_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
TARGET
CesiumAsync
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
$<BUILD_INTERFACE:${CESIUM_NATIVE_RAPIDJSON_INCLUDE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src/
)
Expand Down
4 changes: 2 additions & 2 deletions CesiumGeometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ target_sources(
PRIVATE
${CESIUM_GEOMETRY_SOURCES}
${CESIUM_GEOMETRY_HEADERS}
PUBLIC
${CESIUM_GEOMETRY_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
CesiumGeometry
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(CesiumGeometry PUBLIC
Expand Down
6 changes: 3 additions & 3 deletions CesiumGeospatial/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ target_sources(
PRIVATE
${CESIUM_GEOSPATIAL_SOURCES}
${CESIUM_GEOSPATIAL_HEADERS}
PUBLIC
${CESIUM_GEOSPATIAL_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
CesiumGeospatial
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
)

target_link_libraries(CesiumGeospatial
PUBLIC
CesiumGeometry
CesiumUtility
earcut
PRIVATE
$<BUILD_INTERFACE:earcut>
s2::s2
)

Expand Down
6 changes: 3 additions & 3 deletions CesiumGltf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ target_sources(
PRIVATE
${CESIUM_GLTF_SOURCES}
${CESIUM_GLTF_HEADERS}
PUBLIC
${CESIUM_GLTF_PUBLIC_HEADERS}
)

target_include_directories(
CesiumGltf
SYSTEM PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include/
${CMAKE_CURRENT_LIST_DIR}/generated/include
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/generated/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/generated/src
Expand Down
6 changes: 3 additions & 3 deletions CesiumGltfContent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ target_sources(
PRIVATE
${CESIUM_GLTF_CONTENT_SOURCES}
${CESIUM_GLTF_CONTENT_HEADERS}
PUBLIC
${CESIUM_GLTF_CONTENT_PUBLIC_HEADERS}
)

cesium_target_include_directories(
TARGET
CesiumGltfContent
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/generated/include
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/generated/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/src
${CMAKE_CURRENT_LIST_DIR}/generated/src
Expand Down
Loading