Skip to content

Commit

Permalink
Merge pull request #2232 from DARMA-tasking/1891-switch-to-default-fi…
Browse files Browse the repository at this point in the history
…nd_package-behavior

1891: Update find_package_local to work with package_ROOT
  • Loading branch information
lifflander authored Feb 20, 2024
2 parents 265b63c + 8229144 commit a1bfc61
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 123 deletions.
2 changes: 1 addition & 1 deletion ci/build_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ cmake -G "${CMAKE_GENERATOR:-Ninja}" \
-DCMAKE_CXX_COMPILER="${CXX:-c++}" \
-DCMAKE_C_COMPILER="${CC:-cc}" \
-DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS:-}" \
-Dcheckpoint_DIR="$CHECKPOINT_BUILD/install" \
-Dcheckpoint_ROOT="$CHECKPOINT_BUILD/install" \
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH:-}" \
-DCMAKE_INSTALL_PREFIX="$VT_BUILD/install" \
-Dvt_ci_build="${VT_CI_BUILD:-0}" \
Expand Down
2 changes: 1 addition & 1 deletion ci/ctest_job_script.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ set(configureOpts
"-DCMAKE_CXX_COMPILER=$ENV{CXX}"
"-DCMAKE_C_COMPILER=$ENV{CC}"
"-DCMAKE_EXE_LINKER_FLAGS=$ENV{CMAKE_EXE_LINKER_FLAGS}"
"-Dcheckpoint_DIR=$ENV{CHECKPOINT_BUILD}/install"
"-Dcheckpoint_ROOT=$ENV{CHECKPOINT_BUILD}/install"
"-DCMAKE_PREFIX_PATH=$ENV{CMAKE_PREFIX_PATH}"
"-DCMAKE_INSTALL_PREFIX=$ENV{VT_BUILD}/install"
"-Dvt_ci_build=$ENV{VT_CI_BUILD}"
Expand Down
6 changes: 2 additions & 4 deletions cmake/load_local_packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ include(cmake/local_package.cmake)
if (EXISTS "${PROJECT_LIB_DIR}/checkpoint")
add_subdirectory(${PROJECT_LIB_DIR}/checkpoint)
else()
# require directories for these packages
require_pkg_directory(checkpoint "VT checkpoint library")
# find these required packages locally
find_package_local(checkpoint "${checkpoint_DIR}" checkpoint)
endif()
find_package_local(checkpoint checkpoint)
endif()

set(CHECKPOINT_LIBRARY vt::lib::checkpoint)
131 changes: 14 additions & 117 deletions cmake/local_package.cmake
Original file line number Diff line number Diff line change
@@ -1,30 +1,5 @@

macro(require_pkg_directory pkg_name pkg_user_name)
if(hasParent)
# Skip this logic when this macro was not invoked from the
# top-level CMakeLists.txt file under the assumption that this
# package was dropped into another build system using add_subdirectory().
# Note that this will also skip if you call this macro from
# a subdirectory in your own package, so just don't do it!

#message(STATUS "skipping require_pkg_directory for ${pkg_name}")
else()
#message(STATUS "require_directory: name=${pkg_name}")
option(${pkg_name}_DIR "Root folder for ${pkg_user_name} installation" OFF)
if (NOT ${pkg_name}_DIR)
message(
FATAL_ERROR
"Please specify ${pkg_user_name} library installation root"
" with -D${pkg_name}_DIR="
)
endif()
endif()
endmacro(require_pkg_directory)

macro(find_package_local pkg_name pkg_directory pkg_other_name)
# Whether we loaded the package in the following loop with find_package()
macro(find_package_local pkg_name pkg_other_name)
set(${pkg_name}_PACKAGE_LOADED 0)

if(hasParent)
# Skip this logic when this macro was not invoked from the
# top-level CMakeLists.txt file under the assumption that this
Expand All @@ -34,97 +9,19 @@ macro(find_package_local pkg_name pkg_directory pkg_other_name)

# message(STATUS "skipping find_package for ${pkg_name}")
else()
message(
STATUS "find_package_local: pkg name=\"${pkg_name}\", "
"directory=\"${pkg_directory}\""
message(STATUS "find_package_local: pkg name=\"${pkg_name}\"")

find_package(
${pkg_name}
NAMES ${pkg_name} ${pkg_other_name}
NO_CMAKE_PACKAGE_REGISTRY
NO_CMAKE_BUILDS_PATH
NO_CMAKE_SYSTEM_PATH
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
NO_SYSTEM_ENVIRONMENT_PATH
QUIET
REQUIRED
)

# Rest of the arguments are potential relative search paths wrt the
# ${pkg_directory}
set(prefix_args ${ARGN})

# Default search paths: root, /cmake and /CMake subdirectories
list(APPEND prefix_args "/" "/cmake" "/CMake")

foreach(prefix ${prefix_args})
set(potential_path ${pkg_directory}/${prefix})
# message("prefix: ${potential_path}")
if (EXISTS "${potential_path}")
# message(STATUS "find_package_local: trying path: ${potential_path}")

# Search locally only for package based on the user's supplied path; if
# this fails try to next one. Even if the directory exists (tested above)
# this might fail if a directory does not have the config file
find_package(
${pkg_name}
PATHS ${potential_path}
NAMES ${pkg_name} ${pkg_other_name}
NO_CMAKE_PACKAGE_REGISTRY
NO_CMAKE_BUILDS_PATH
NO_CMAKE_SYSTEM_PATH
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY
NO_SYSTEM_ENVIRONMENT_PATH
QUIET
)

# Break out of the search loop now that we have found the path
if (${${pkg_name}_FOUND})
message(STATUS "find_package_local: found with prefix: ${prefix}")
set(${pkg_name}_PACKAGE_LOADED 1)
break()
endif()
endif()
endforeach()

if (NOT ${${pkg_name}_PACKAGE_LOADED})
message(STATUS "find_package_local: can not find package: ${pkg_name}")

foreach(prefix ${prefix_args})
set(path ${${pkg_name}_DIR}/${prefix})
message(STATUS "find_package_local: searched: ${path}")
endforeach()

message(
FATAL_ERROR "find_package_local: can not find package: ${pkg_name}"
" tried to find_package(..) with above search paths"
)
endif()
set(${pkg_name}_PACKAGE_LOADED 1)
endif()
endmacro(find_package_local)

macro(optional_pkg_directory pkg_name pkg_user_name assume_found_if_hasparent)
if(hasParent)
# Skip MOST of this logic when this macro was not invoked from the
# top-level CMakeLists.txt file under the assumption that this
# package was dropped into another build system using add_subdirectory().
# Note that this will also skip if you call this macro from
# a subdirectory in your own package, so just don't do it!

if(${assume_found_if_hasparent})
# Assume that the package is available even if the directory wasn't specified
set(${pkg_name}_DIR_FOUND 1)
endif()
else()
#message(STATUS "optional_pkg_directory: name=${pkg_name}")
option(${pkg_name}_DIR "Root folder for ${pkg_user_name} installation" OFF)
if (NOT ${pkg_name}_DIR)
message(
STATUS
"Path for ${pkg_user_name} library (optional) not specified "
"with -D${pkg_name}_DIR="
)
message(
STATUS
"Building without ${pkg_user_name} library"
)
set(${pkg_name}_DIR_FOUND 0)
else()
message(
STATUS
"Path for ${pkg_user_name} library (optional) specified "
"with -D${pkg_name}_DIR=${${pkg_name}_DIR}"
)
set(${pkg_name}_DIR_FOUND 1)
endif()
endif()
endmacro(optional_pkg_directory)

0 comments on commit a1bfc61

Please sign in to comment.