Skip to content

Commit 0ce0475

Browse files
committedFeb 20, 2024
#1891: Update find_package_local to work with package_ROOT
1 parent 265b63c commit 0ce0475

File tree

2 files changed

+15
-122
lines changed

2 files changed

+15
-122
lines changed
 

‎cmake/load_local_packages.cmake

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ include(cmake/local_package.cmake)
88
if (EXISTS "${PROJECT_LIB_DIR}/checkpoint")
99
add_subdirectory(${PROJECT_LIB_DIR}/checkpoint)
1010
else()
11-
# require directories for these packages
12-
require_pkg_directory(checkpoint "VT checkpoint library")
1311
# find these required packages locally
14-
find_package_local(checkpoint "${checkpoint_DIR}" checkpoint)
15-
endif()
12+
find_package_local(checkpoint checkpoint)
13+
endif()
1614

1715
set(CHECKPOINT_LIBRARY vt::lib::checkpoint)

‎cmake/local_package.cmake

+13-118
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,4 @@
1-
2-
macro(require_pkg_directory pkg_name pkg_user_name)
3-
if(hasParent)
4-
# Skip this logic when this macro was not invoked from the
5-
# top-level CMakeLists.txt file under the assumption that this
6-
# package was dropped into another build system using add_subdirectory().
7-
# Note that this will also skip if you call this macro from
8-
# a subdirectory in your own package, so just don't do it!
9-
10-
#message(STATUS "skipping require_pkg_directory for ${pkg_name}")
11-
else()
12-
#message(STATUS "require_directory: name=${pkg_name}")
13-
option(${pkg_name}_DIR "Root folder for ${pkg_user_name} installation" OFF)
14-
if (NOT ${pkg_name}_DIR)
15-
message(
16-
FATAL_ERROR
17-
"Please specify ${pkg_user_name} library installation root"
18-
" with -D${pkg_name}_DIR="
19-
)
20-
endif()
21-
endif()
22-
endmacro(require_pkg_directory)
23-
24-
macro(find_package_local pkg_name pkg_directory pkg_other_name)
25-
# Whether we loaded the package in the following loop with find_package()
26-
set(${pkg_name}_PACKAGE_LOADED 0)
27-
1+
macro(find_package_local pkg_name pkg_other_name)
282
if(hasParent)
293
# Skip this logic when this macro was not invoked from the
304
# top-level CMakeLists.txt file under the assumption that this
@@ -34,97 +8,18 @@ macro(find_package_local pkg_name pkg_directory pkg_other_name)
348

359
# message(STATUS "skipping find_package for ${pkg_name}")
3610
else()
37-
message(
38-
STATUS "find_package_local: pkg name=\"${pkg_name}\", "
39-
"directory=\"${pkg_directory}\""
11+
message(STATUS "find_package_local: pkg name=\"${pkg_name}\"")
12+
13+
find_package(
14+
${pkg_name}
15+
NAMES ${pkg_name} ${pkg_other_name}
16+
NO_CMAKE_PACKAGE_REGISTRY
17+
NO_CMAKE_BUILDS_PATH
18+
NO_CMAKE_SYSTEM_PATH
19+
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
20+
NO_SYSTEM_ENVIRONMENT_PATH
21+
QUIET
22+
REQUIRED
4023
)
41-
42-
# Rest of the arguments are potential relative search paths wrt the
43-
# ${pkg_directory}
44-
set(prefix_args ${ARGN})
45-
46-
# Default search paths: root, /cmake and /CMake subdirectories
47-
list(APPEND prefix_args "/" "/cmake" "/CMake")
48-
49-
foreach(prefix ${prefix_args})
50-
set(potential_path ${pkg_directory}/${prefix})
51-
# message("prefix: ${potential_path}")
52-
if (EXISTS "${potential_path}")
53-
# message(STATUS "find_package_local: trying path: ${potential_path}")
54-
55-
# Search locally only for package based on the user's supplied path; if
56-
# this fails try to next one. Even if the directory exists (tested above)
57-
# this might fail if a directory does not have the config file
58-
find_package(
59-
${pkg_name}
60-
PATHS ${potential_path}
61-
NAMES ${pkg_name} ${pkg_other_name}
62-
NO_CMAKE_PACKAGE_REGISTRY
63-
NO_CMAKE_BUILDS_PATH
64-
NO_CMAKE_SYSTEM_PATH
65-
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
66-
NO_SYSTEM_ENVIRONMENT_PATH
67-
QUIET
68-
)
69-
70-
# Break out of the search loop now that we have found the path
71-
if (${${pkg_name}_FOUND})
72-
message(STATUS "find_package_local: found with prefix: ${prefix}")
73-
set(${pkg_name}_PACKAGE_LOADED 1)
74-
break()
75-
endif()
76-
endif()
77-
endforeach()
78-
79-
if (NOT ${${pkg_name}_PACKAGE_LOADED})
80-
message(STATUS "find_package_local: can not find package: ${pkg_name}")
81-
82-
foreach(prefix ${prefix_args})
83-
set(path ${${pkg_name}_DIR}/${prefix})
84-
message(STATUS "find_package_local: searched: ${path}")
85-
endforeach()
86-
87-
message(
88-
FATAL_ERROR "find_package_local: can not find package: ${pkg_name}"
89-
" tried to find_package(..) with above search paths"
90-
)
91-
endif()
9224
endif()
9325
endmacro(find_package_local)
94-
95-
macro(optional_pkg_directory pkg_name pkg_user_name assume_found_if_hasparent)
96-
if(hasParent)
97-
# Skip MOST of this logic when this macro was not invoked from the
98-
# top-level CMakeLists.txt file under the assumption that this
99-
# package was dropped into another build system using add_subdirectory().
100-
# Note that this will also skip if you call this macro from
101-
# a subdirectory in your own package, so just don't do it!
102-
103-
if(${assume_found_if_hasparent})
104-
# Assume that the package is available even if the directory wasn't specified
105-
set(${pkg_name}_DIR_FOUND 1)
106-
endif()
107-
else()
108-
#message(STATUS "optional_pkg_directory: name=${pkg_name}")
109-
option(${pkg_name}_DIR "Root folder for ${pkg_user_name} installation" OFF)
110-
if (NOT ${pkg_name}_DIR)
111-
message(
112-
STATUS
113-
"Path for ${pkg_user_name} library (optional) not specified "
114-
"with -D${pkg_name}_DIR="
115-
)
116-
message(
117-
STATUS
118-
"Building without ${pkg_user_name} library"
119-
)
120-
set(${pkg_name}_DIR_FOUND 0)
121-
else()
122-
message(
123-
STATUS
124-
"Path for ${pkg_user_name} library (optional) specified "
125-
"with -D${pkg_name}_DIR=${${pkg_name}_DIR}"
126-
)
127-
set(${pkg_name}_DIR_FOUND 1)
128-
endif()
129-
endif()
130-
endmacro(optional_pkg_directory)

0 commit comments

Comments
 (0)
Please sign in to comment.