Skip to content

Commit 518c888

Browse files
committed
Increase config file compat w.r.t different capitalization
The config file will now detect wrong capitalization of the package name and emit a warning about it. Furthermore, it will try its best to subsequently use the package name in the capitalization as used in the respective find_package call. This should minimize the issues that can arise from wrong capitalization (such as mismatched capitalization in the resulting variables). Nonetheless, there are likely some issues remaining, which is why the warning requests fixing the capitalization of the package name.
1 parent 434ac4c commit 518c888

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

Config.cmake.in

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
include(CMakeFindDependencyMacro)
22

3+
# ##################################################################################################
4+
# Handle potential capitalization differences in the project's name
5+
# ##################################################################################################
6+
7+
set(PROJECT_NAME "@PROJECT_NAME@")
8+
string(TOLOWER "${PROJECT_NAME}" PROJECT_NAME_LOWER)
9+
string(TOLOWER "${CMAKE_FIND_PACKAGE_NAME}" CMAKE_FIND_PACKAGE_NAME_LOWER)
10+
11+
if("${PROJECT_NAME_LOWER}" STREQUAL "${CMAKE_FIND_PACKAGE_NAME_LOWER}")
12+
if(NOT ("${PROJECT_NAME}" STREQUAL "${CMAKE_FIND_PACKAGE_NAME}"))
13+
# The find_package call used a different capitalization of '@PROJECT_NAME@' This can lead to
14+
# issues like the config file being found on a platform with a case-insensitive file system but
15+
# not on a platform with a case-sensitive filesystem (in case the config file uses the
16+
# NameConfig.cmake naming convention rather than name-config.cmake (all-lowercase)). Additional
17+
# issues can arise if the caller expects variables such as Name_* to be defined where the
18+
# capitalization of Name is important as well.
19+
#
20+
# We try to circumvent such issues by adapting the capitalization used in the find_package call
21+
# but ultimately, the caller should switch to using the proper capitalization.
22+
message(
23+
AUTHOR_WARNING
24+
"Incorrect capitalization in '${CMAKE_FIND_PACKAGE_NAME}'. It should be changed to '@PROJECT_NAME@' to avoid issues."
25+
)
26+
set(PROJECT_NAME "${CMAKE_FIND_PACKAGE_NAME}")
27+
endif()
28+
endif()
29+
30+
# ##################################################################################################
31+
# Look up all required dependencies
32+
# ##################################################################################################
33+
334
string(REGEX MATCHALL "[^;]+" SEPARATE_DEPENDENCIES "@PROJECT_DEPENDENCIES@")
435

536
foreach(dependency ${SEPARATE_DEPENDENCIES})

test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ project(
99
)
1010

1111
if(TEST_INSTALLED_VERSION)
12-
find_package(dependency 1.2 REQUIRED)
12+
# Note: Wrong capitalization. The project really is called "dependency". However, PackageProject
13+
# should have installed workarounds to make this work nonetheless (even on case-sensitive
14+
# filesystems)
15+
find_package(Dependency 1.2 REQUIRED)
1316
find_package(header_only 1.0 REQUIRED)
1417
find_package(namespaced_dependency 4.5.6 REQUIRED)
1518
find_package(transitive_dependency 7.8.9 REQUIRED)

0 commit comments

Comments
 (0)