Skip to content

Commit de6f1ad

Browse files
committed
Add vcpkg CONFIG mode support to Find modules and prioritize custom CMake module path
Try to find packages using CONFIG mode first (e.g., from vcpkg) before falling back to pkg-config or manual search. Create alias targets when needed to ensure compatibility. Change CMAKE_MODULE_PATH from APPEND to PREPEND to prioritize custom find modules. Downgrade KTX version to v4.3.1 for stability. Remove trailing whitespace.
1 parent b4074b0 commit de6f1ad

File tree

12 files changed

+109
-7
lines changed

12 files changed

+109
-7
lines changed

attachments/CMake/FindKTX.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
# KTX::ktx
1414
#
1515

16+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
17+
find_package(ktx CONFIG QUIET)
18+
19+
if(ktx_FOUND)
20+
if(NOT TARGET KTX::ktx AND TARGET ktx::ktx)
21+
add_library(KTX::ktx ALIAS ktx::ktx)
22+
endif()
23+
set(KTX_FOUND TRUE)
24+
return()
25+
endif()
26+
1627
# Check if we're on Linux - if so, we'll skip the search and directly use FetchContent
1728
if(UNIX AND NOT APPLE)
1829
# On Linux, we assume KTX is not installed and proceed directly to fetching it

attachments/CMake/Findglm.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# glm::glm
1313
#
1414

15+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
16+
find_package(glm CONFIG QUIET)
17+
18+
if(glm_FOUND)
19+
if(NOT TARGET glm::glm AND TARGET glm)
20+
add_library(glm::glm ALIAS glm)
21+
endif()
22+
return()
23+
endif()
24+
1525
# Try to find the package using pkg-config first
1626
find_package(PkgConfig QUIET)
1727
if(PKG_CONFIG_FOUND)
@@ -94,7 +104,7 @@ endif()
94104

95105
# Set the variables
96106
include(FindPackageHandleStandardArgs)
97-
find_package_handle_standard_args(glm
107+
find_package_handle_standard_args(glm
98108
REQUIRED_VARS glm_INCLUDE_DIR
99109
)
100110

attachments/CMake/Findnlohmann_json.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# nlohmann_json::nlohmann_json
1313
#
1414

15+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
16+
find_package(nlohmann_json CONFIG QUIET)
17+
18+
if(nlohmann_json_FOUND)
19+
if(NOT TARGET nlohmann_json::nlohmann_json AND TARGET nlohmann_json)
20+
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
21+
endif()
22+
return()
23+
endif()
24+
1525
# Try to find the package using pkg-config first
1626
find_package(PkgConfig QUIET)
1727
if(PKG_CONFIG_FOUND)

attachments/CMake/Findtinygltf.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# tinygltf::tinygltf
1313
#
1414

15+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
16+
find_package(tinygltf CONFIG QUIET)
17+
18+
if(tinygltf_FOUND)
19+
if(NOT TARGET tinygltf::tinygltf AND TARGET tinygltf)
20+
add_library(tinygltf::tinygltf ALIAS tinygltf)
21+
endif()
22+
return()
23+
endif()
24+
1525
# First, try to find nlohmann_json
1626
find_package(nlohmann_json QUIET)
1727
if(NOT nlohmann_json_FOUND)

attachments/CMake/Findtinyobjloader.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
# It also defines the following targets:
1010
# tinyobjloader::tinyobjloader
1111

12+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
13+
find_package(tinyobjloader CONFIG QUIET)
14+
15+
if(tinyobjloader_FOUND)
16+
if(NOT TARGET tinyobjloader::tinyobjloader AND TARGET tinyobjloader)
17+
add_library(tinyobjloader::tinyobjloader ALIAS tinyobjloader)
18+
endif()
19+
return()
20+
endif()
21+
1222
# Try to find the package using pkg-config first
1323
find_package(PkgConfig QUIET)
1424
if(PKG_CONFIG_FOUND)
@@ -109,7 +119,7 @@ endif()
109119

110120
# Set the variables
111121
include(FindPackageHandleStandardArgs)
112-
find_package_handle_standard_args(tinyobjloader
122+
find_package_handle_standard_args(tinyobjloader
113123
REQUIRED_VARS tinyobjloader_INCLUDE_DIR
114124
)
115125

attachments/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ endif()
1111

1212
project (VulkanTutorial)
1313

14-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
14+
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
1515

1616
# Add option to enable/disable C++ 20 module
1717
option(ENABLE_CPP20_MODULE "Enable C++ 20 module support for Vulkan" OFF)

attachments/simple_engine/CMake/FindKTX.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@
1313
# KTX::ktx
1414
#
1515

16+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
17+
find_package(ktx CONFIG QUIET)
18+
19+
if(ktx_FOUND)
20+
if(NOT TARGET KTX::ktx AND TARGET ktx::ktx)
21+
add_library(KTX::ktx ALIAS ktx::ktx)
22+
endif()
23+
set(KTX_FOUND TRUE)
24+
return()
25+
endif()
26+
1627
# Check if we're on Linux - if so, we'll skip the search and directly use FetchContent
1728
if(UNIX AND NOT APPLE)
1829
# On Linux, we assume KTX is not installed and proceed directly to fetching it
@@ -70,7 +81,7 @@ if(NOT KTX_FOUND)
7081
FetchContent_Declare(
7182
ktx
7283
GIT_REPOSITORY https://github.com/KhronosGroup/KTX-Software.git
73-
GIT_TAG v4.4.2 # Use a specific tag for stability
84+
GIT_TAG v4.3.1 # Use a specific tag for stability
7485
)
7586

7687
# Set options to minimize build time and dependencies

attachments/simple_engine/CMake/Findglm.cmake

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# glm::glm
1313
#
1414

15+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
16+
find_package(glm CONFIG QUIET)
17+
18+
if(glm_FOUND)
19+
if(NOT TARGET glm::glm AND TARGET glm)
20+
add_library(glm::glm ALIAS glm)
21+
endif()
22+
return()
23+
endif()
24+
1525
# Try to find the package using pkg-config first
1626
find_package(PkgConfig QUIET)
1727
if(PKG_CONFIG_FOUND)
@@ -94,7 +104,7 @@ endif()
94104

95105
# Set the variables
96106
include(FindPackageHandleStandardArgs)
97-
find_package_handle_standard_args(glm
107+
find_package_handle_standard_args(glm
98108
REQUIRED_VARS glm_INCLUDE_DIR
99109
)
100110

attachments/simple_engine/CMake/Findnlohmann_json.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# nlohmann_json::nlohmann_json
1313
#
1414

15+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
16+
find_package(nlohmann_json CONFIG QUIET)
17+
18+
if(nlohmann_json_FOUND)
19+
if(NOT TARGET nlohmann_json::nlohmann_json AND TARGET nlohmann_json)
20+
add_library(nlohmann_json::nlohmann_json ALIAS nlohmann_json)
21+
endif()
22+
return()
23+
endif()
24+
1525
# Try to find the package using pkg-config first
1626
find_package(PkgConfig QUIET)
1727
if(PKG_CONFIG_FOUND)

attachments/simple_engine/CMake/Findtinygltf.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212
# tinygltf::tinygltf
1313
#
1414

15+
# Try to find the package using CONFIG mode first (e.g., from vcpkg)
16+
find_package(tinygltf CONFIG QUIET)
17+
18+
if(tinygltf_FOUND)
19+
if(NOT TARGET tinygltf::tinygltf AND TARGET tinygltf)
20+
add_library(tinygltf::tinygltf ALIAS tinygltf)
21+
endif()
22+
return()
23+
endif()
24+
1525
# First, try to find nlohmann_json
1626
find_package(nlohmann_json QUIET)
1727
if(NOT nlohmann_json_FOUND)

0 commit comments

Comments
 (0)