Skip to content

Commit

Permalink
Remove special raw CMake package logic for lib install dir (#582)
Browse files Browse the repository at this point in the history
This avoids the special logic in the file package1/CMakeLists.txt by having
TribitsExampleProject2/CMakeLists.txt set the var
${PROJECT_NAME}_USE_GNUINSTALLDIRS=ON.  This resulted in everything being
installed under <prefix>/lib64/ on my current machine automatically.

However, to get this to work I had to set:

  -DCMAKE_INSTALL_LIBDIR:STRING=lib

or the find_package(...) command with CMake 3.23.1 would no longer find
<Package>Config.cmake files under:

  <prefix>/lib64/

This seems inconsistent with CMake documentation for find_package() as of
CMake 3.23.1 that suggests that it will look under the location:

  <prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/

Well that should pick up the directory:

  <prefix>/lib*/cmake/<name>*/

But that was not the case :-(

Perhaps this is fixed in the latest CMake?  In any case, we get around this by
by setting CMAKE_INSTALL_LIBDIR=lib.

Other changes made in this commit:

* Fixed the 'TribitsExampleApp2' tests to correctly switch between searching
  for the top project-level package-config file or the individual
  package-config files.  (This required passing in
  -DTribitsExApp2_FIND_INDIVIDUAL_PACKAGES=ON and updating the regex.)
  • Loading branch information
bartlettroscoe committed Aug 4, 2023
1 parent 9015a58 commit 62d632c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
5 changes: 4 additions & 1 deletion test/core/ExamplesUnitTests/TribitsExampleApp2_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase

if (fullOrComponents STREQUAL "FULL")
set(tribitsExProjUseComponentsArg "")
set(packageListRegex "TribitsExProj2_PACKAGE_LIST = Package3[;]Package2[;]Package1")
elseif (fullOrComponents STREQUAL "COMPONENTS")
set(tribitsExProjUseComponentsArg
-DTribitsExApp2_FIND_INDIVIDUAL_PACKAGES=ON
-DTribitsExApp2_USE_COMPONENTS="Package1,Package2,Package3")
set(packageListRegex "Found Package1;Found Package2;Found Package3")
else()
message(FATAL_ERROR "Invalid value of fullOrComponents='${fullOrComponents}'!")
endif()
Expand Down Expand Up @@ -146,7 +149,7 @@ function(TribitsExampleApp2 tribitsExProj2TestNameBaseBase
${tribitsExProjUseComponentsArg}
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleApp2
PASS_REGULAR_EXPRESSION_ALL
"TribitsExProj2_PACKAGE_LIST = Package3[;]Package2[;]Package1"
"${packageListRegex}"
"-- Configuring done"
"-- Generating done"
"-- Build files have been written to: .*/${testName}/app_build"
Expand Down
12 changes: 12 additions & 0 deletions test/core/ExamplesUnitTests/TribitsExampleProject2_Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ function(TribitsExampleProject2_find_tpl_parts sharedOrStatic findingTplsMetho
${tplLibAndIncDirsArgs}
${cmakePrefixPathCacheArg}
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=${testDir}/install
-DTribitsExProj2_ENABLE_ALL_PACKAGES=ON
../TribitsExampleProject2
Expand Down Expand Up @@ -352,6 +353,7 @@ function(TribitsExampleProject2_find_tpl_parts_no_optional_packages_tpls shared
-DTribitsExProj2_ENABLE_ALL_OPTIONAL_PACKAGES=OFF
-DPackage3_ENABLE_Package2=OFF
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=install
-DTribitsExProj2_ENABLE_ALL_PACKAGES=ON
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2
Expand Down Expand Up @@ -469,6 +471,7 @@ function(TribitsExampleProject2_explicit_tpl_vars sharedOrStatic)
-DCMAKE_BUILD_TYPE=DEBUG
-DTribitsExProj2_ENABLE_ALL_PACKAGES=ON
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=install
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2
PASS_REGULAR_EXPRESSION_ALL
Expand Down Expand Up @@ -596,6 +599,7 @@ function(TribitsExampleProject2_find_package sharedOrStatic package1TribitsOrR
${package1UseRawCMakeArgs}
-DTribitsExProj2_ENABLE_ALL_PACKAGES=ON
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=${testDir}/install
-D CMAKE_PREFIX_PATH="${tplInstallBaseDir}/install_tpl1<semicolon>${tplInstallBaseDir}/install_tpl2<semicolon>${tplInstallBaseDir}/install_tpl3<semicolon>${tplInstallBaseDir}/install_tpl4"
../TribitsExampleProject2
Expand Down Expand Up @@ -702,6 +706,7 @@ tribits_add_advanced_test( ${testNameBase}
-DCMAKE_BUILD_TYPE=DEBUG
-DTpl1_EXTRACT_INFO_AFTER_FIND_PACKAGE=ON
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=install
-DTribitsExProj2_ENABLE_Package1=ON
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2
Expand Down Expand Up @@ -748,6 +753,7 @@ tribits_add_advanced_test( ${testNameBase}
-DTpl1_EXTRACT_INFO_AFTER_FIND_PACKAGE=ON
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_PREFIX_PATH="${testDir}/install"
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=install
-DTribitsExProj2_ENABLE_Package1=ON
${${PROJECT_NAME}_TRIBITS_DIR}/examples/TribitsExampleProject2
Expand Down Expand Up @@ -905,6 +911,7 @@ function(TribitsExampleProject2_External_Package_by_Package
-DTribitsExProj2_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj2_ENABLE_Package1=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=../install_package1
-DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE
-DTPL_ENABLE_Tpl1=ON
Expand Down Expand Up @@ -941,6 +948,7 @@ function(TribitsExampleProject2_External_Package_by_Package
-DTribitsExProj2_TRIBITS_DIR=${${PROJECT_NAME}_TRIBITS_DIR}
-DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj2_ENABLE_Package2=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=../install_package2
-DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE
-DTPL_ENABLE_Package1=ON # Pull in already installed Package!
Expand Down Expand Up @@ -1002,6 +1010,7 @@ function(TribitsExampleProject2_External_Package_by_Package
-DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj2_ENABLE_ALL_PACKAGES=ON
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=../install
-DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE
-DTPL_ENABLE_Package2=ON # Pull in already installed Package!
Expand Down Expand Up @@ -1200,6 +1209,7 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package
ARGS
${TribitsExampleProject2_COMMON_CONFIG_ARGS}
-DCMAKE_PREFIX_PATH=${tplInstallBaseDir}/install_tpl1
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=../install_package1
../TribitsExampleProject2/packages/package1
PASS_REGULAR_EXPRESSION_ALL
Expand All @@ -1226,6 +1236,7 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package
-DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj2_ENABLE_TESTS=ON
-DTribitsExProj2_ENABLE_Package2=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=../install_package2
-DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE
-DTPL_ENABLE_Package1=ON # Pull in already installed Package1!
Expand Down Expand Up @@ -1296,6 +1307,7 @@ function(TribitsExampleProject2_External_RawPackage1_then_Package_by_Package
-DTribitsExProj2_ENABLE_SECONDARY_TESTED_CODE=ON
-DTribitsExProj2_ENABLE_ALL_PACKAGES=ON
-DTribitsExProj2_ENABLE_TESTS=ON
-DCMAKE_INSTALL_LIBDIR:STRING=lib
-DCMAKE_INSTALL_PREFIX=../install
-DTribitsExProj2_SKIP_INSTALL_PROJECT_CMAKE_CONFIG_FILES=TRUE
-DTPL_ENABLE_Package2=ON # Pull in already installed Package!
Expand Down
5 changes: 3 additions & 2 deletions tribits/examples/TribitsExampleApp2/AppHelperFuncs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro(getTribitsExProj2StuffForAppByPackage)
# Find each package and gather up all the <Package>::all_libs targets
set(APP_DEPS_LIB_TARGETS "")
foreach (packageName IN LISTS ${PROJECT_NAME}_USE_COMPONENTS)
find_package(${packageName} REQUIRED)
find_package(${packageName} CONFIG REQUIRED)
message("Found ${packageName}!")
list(APPEND APP_DEPS_LIB_TARGETS ${packageName}::all_libs)
endforeach()
Expand All @@ -59,7 +59,8 @@ endmacro()
#
macro(getTribitsExProj2StuffForAppByProject)

find_package(TribitsExProj2 REQUIRED COMPONENTS ${${PROJECT_NAME}_USE_COMPONENTS})
find_package(TribitsExProj2 CONFIG REQUIRED
COMPONENTS ${${PROJECT_NAME}_USE_COMPONENTS})

message("\nFound TribitsExProj2! Here are the details: ")
message(" TribitsExProj2_DIR = ${TribitsExProj2_DIR}")
Expand Down
1 change: 1 addition & 0 deletions tribits/examples/TribitsExampleProject2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.23.0 FATAL_ERROR)
include("${CMAKE_CURRENT_SOURCE_DIR}/ProjectName.cmake")
project(${PROJECT_NAME} LANGUAGES NONE)
set(TRIBITS_HIDE_DEPRECATED_INCLUDE_DIRECTORIES_OVERRIDE TRUE)
set(${PROJECT_NAME}_USE_GNUINSTALLDIRS ON)
set(${PROJECT_NAME}_TRIBITS_DIR
"${CMAKE_CURRENT_LIST_DIR}/../.." CACHE STRING
"TriBITS base directory (default assumes in TriBITS source tree)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ else()
@ONLY )

# Generate and install the Package1Config.cmake file for the install tree
if (COMMAND tribits_package)
set(pkgConfigInstallDir
"${${CMAKE_PROJECT_NAME}_INSTALL_LIB_DIR}/cmake/${PACKAGE_NAME}")
else()
set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
endif()
set(pkgConfigInstallDir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
install(EXPORT ${PROJECT_NAME}
DESTINATION "${pkgConfigInstallDir}"
NAMESPACE ${PROJECT_NAME}::
Expand All @@ -75,11 +70,3 @@ else()
DESTINATION "${pkgConfigInstallDir}" )

endif()


# NOTE: Above, the variable CMAKE_INSTALL_LIBDIR set by
# include(GNUInstallDirs) is different that what is used by TriBITS by default
# in at least some cases. That is very irritating and this is something that
# needs to be fixed (see TriBITSPub/TriBITS#411). But note that the location
# of the libraries does not have to be the same as the installed
# `<Package>Config.cmake`.

0 comments on commit 62d632c

Please sign in to comment.