Skip to content

Commit a1bfc61

Browse files
authored
Merge pull request #2232 from DARMA-tasking/1891-switch-to-default-find_package-behavior
1891: Update find_package_local to work with package_ROOT
2 parents 265b63c + 8229144 commit a1bfc61

4 files changed

+18
-123
lines changed

ci/build_cpp.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ cmake -G "${CMAKE_GENERATOR:-Ninja}" \
120120
-DCMAKE_CXX_COMPILER="${CXX:-c++}" \
121121
-DCMAKE_C_COMPILER="${CC:-cc}" \
122122
-DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS:-}" \
123-
-Dcheckpoint_DIR="$CHECKPOINT_BUILD/install" \
123+
-Dcheckpoint_ROOT="$CHECKPOINT_BUILD/install" \
124124
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:-}" \
125125
-DCMAKE_INSTALL_PREFIX="$VT_BUILD/install" \
126126
-Dvt_ci_build="${VT_CI_BUILD:-0}" \

ci/ctest_job_script.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ set(configureOpts
148148
"-DCMAKE_CXX_COMPILER=$ENV{CXX}"
149149
"-DCMAKE_C_COMPILER=$ENV{CC}"
150150
"-DCMAKE_EXE_LINKER_FLAGS=$ENV{CMAKE_EXE_LINKER_FLAGS}"
151-
"-Dcheckpoint_DIR=$ENV{CHECKPOINT_BUILD}/install"
151+
"-Dcheckpoint_ROOT=$ENV{CHECKPOINT_BUILD}/install"
152152
"-DCMAKE_PREFIX_PATH=$ENV{CMAKE_PREFIX_PATH}"
153153
"-DCMAKE_INSTALL_PREFIX=$ENV{VT_BUILD}/install"
154154
"-Dvt_ci_build=$ENV{VT_CI_BUILD}"

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

+14-117
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
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()
1+
macro(find_package_local pkg_name pkg_other_name)
262
set(${pkg_name}_PACKAGE_LOADED 0)
27-
283
if(hasParent)
294
# Skip this logic when this macro was not invoked from the
305
# top-level CMakeLists.txt file under the assumption that this
@@ -34,97 +9,19 @@ macro(find_package_local pkg_name pkg_directory pkg_other_name)
349

3510
# message(STATUS "skipping find_package for ${pkg_name}")
3611
else()
37-
message(
38-
STATUS "find_package_local: pkg name=\"${pkg_name}\", "
39-
"directory=\"${pkg_directory}\""
12+
message(STATUS "find_package_local: pkg name=\"${pkg_name}\"")
13+
14+
find_package(
15+
${pkg_name}
16+
NAMES ${pkg_name} ${pkg_other_name}
17+
NO_CMAKE_PACKAGE_REGISTRY
18+
NO_CMAKE_BUILDS_PATH
19+
NO_CMAKE_SYSTEM_PATH
20+
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
21+
NO_SYSTEM_ENVIRONMENT_PATH
22+
QUIET
23+
REQUIRED
4024
)
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()
25+
set(${pkg_name}_PACKAGE_LOADED 1)
9226
endif()
9327
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)