Skip to content

Commit

Permalink
#1512: cmake: check for when find_package exits early when part of pa…
Browse files Browse the repository at this point in the history
…rent
  • Loading branch information
lifflander committed Aug 10, 2021
1 parent 204a8dc commit 670a498
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
4 changes: 0 additions & 4 deletions cmake/load_local_packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ include(cmake/local_package.cmake)

if (EXISTS "${PROJECT_LIB_DIR}/detector")
add_subdirectory(${PROJECT_LIB_DIR}/detector)
set(vt_find_detector_dep 0)
else()
# require directories for these packages
require_pkg_directory(detector "VT detector library")
# find these required packages locally
find_package_local(detector "${detector_DIR}" detector)
set(vt_find_detector_dep 1)
endif()

if (EXISTS "${PROJECT_LIB_DIR}/checkpoint")
add_subdirectory(${PROJECT_LIB_DIR}/checkpoint)
set(vt_find_checkpoint_dep 0)
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)
set(vt_find_checkpoint_dep 1)
endif()

set(CHECKPOINT_LIBRARY vt::lib::checkpoint)
9 changes: 5 additions & 4 deletions cmake/local_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ endmacro(require_pkg_directory)

macro(find_package_local pkg_name pkg_directory pkg_other_name)
get_directory_property(hasParent PARENT_DIRECTORY)

# Whether we loaded the package in the following loop with find_package()
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
# 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 find_package for ${pkg_name}")
# message(STATUS "skipping find_package for ${pkg_name}")
else()
message(
STATUS "find_package_local: pkg name=\"${pkg_name}\", "
Expand All @@ -45,9 +49,6 @@ macro(find_package_local pkg_name pkg_directory pkg_other_name)
# Default search paths: root, /cmake and /CMake subdirectories
list(APPEND prefix_args "/" "/cmake" "/CMake")

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

foreach(prefix ${prefix_args})
set(potential_path ${pkg_directory}/${prefix})
# message("prefix: ${potential_path}")
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,12 @@ if (vt_libfort_enabled)
install(TARGETS ${FORT_LIBRARY} EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
endif()

if (vt_find_detector_dep EQUAL 0)
if (NOT detector_PACKAGE_LOADED)
install(TARGETS detector EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
set(DETECTOR_EXPORT detector)
endif()

if (vt_find_checkpoint_dep EQUAL 0)
if (NOT checkpoint_PACKAGE_LOADED)
install(TARGETS checkpoint EXPORT ${VIRTUAL_TRANSPORT_LIBRARY})
set(CHECKPOINT_EXPORT checkpoint)
endif()
Expand Down

0 comments on commit 670a498

Please sign in to comment.