From 76992b7dc672aa41109a7e78b1c169e6e4c3fe82 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Tue, 30 Aug 2022 15:41:57 -0400 Subject: [PATCH 01/10] add the test for pkgconfig --- .gitlab/scripts.yml | 2 ++ CMakeLists.txt | 22 +++++++++++++++++++ .../test_exportbuild_pkgconfig/CMakeLists.txt | 14 ++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 test/test_exportbuild_pkgconfig/CMakeLists.txt diff --git a/.gitlab/scripts.yml b/.gitlab/scripts.yml index b08d925d0b5..f8da2265072 100644 --- a/.gitlab/scripts.yml +++ b/.gitlab/scripts.yml @@ -52,6 +52,7 @@ -DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR} - ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi + - ninja test_exportbuild_pkgconfig dependencies: [] .build_and_test_template: @@ -123,6 +124,7 @@ - if [ -n "${SYCL_DEVICE_TYPE}" ]; then unset SYCL_DEVICE_TYPE; fi - if [ -n "${SYCL_DEVICE_FILTER}" ]; then unset SYCL_DEVICE_FILTER; fi - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi + - ninja test_exportbuild_pkgconfig dependencies: [] diff --git a/CMakeLists.txt b/CMakeLists.txt index 23cac48d3c8..101c29810b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -361,15 +361,19 @@ set(GINKGO_TEST_INSTALL_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_install/") set(GINKGO_TEST_INSTALL_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_install/") set(GINKGO_TEST_EXPORTBUILD_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_exportbuild/") set(GINKGO_TEST_EXPORTBUILD_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_exportbuild/") +set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_exportbuild_pkgconfig/") +set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_exportbuild_pkgconfig/") if(MSVC) set(GINKGO_TEST_INSTALL_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/$/test_install) set(GINKGO_TEST_EXPORTBUILD_CMD ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}/$/test_exportbuild) + set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR}/$/test_exportbuild_pkgconfig) if(GINKGO_BUILD_CUDA) set(GINKGO_TEST_INSTALL_CUDA_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/$/test_install_cuda) endif() else() set(GINKGO_TEST_INSTALL_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/test_install) set(GINKGO_TEST_EXPORTBUILD_CMD ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}/test_exportbuild) + set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR}/test_exportbuild_pkgconfig) if(GINKGO_BUILD_CUDA) set(GINKGO_TEST_INSTALL_CUDA_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/test_install_cuda) endif() @@ -425,6 +429,24 @@ add_custom_target(test_exportbuild COMMENT "Running a test on Ginkgo's exported build directory. " "This requires compiling Ginkgo with `-DGINKGO_EXPORT_BUILD_DIR=ON` first.") +add_custom_target(test_exportbuild_pkgconfig + COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${TOOLSET} + -H${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_SRC_DIR} + -B${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER} + -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} + # `--config cfg` is ignored by single-configuration generator. + # `$` is always be the same as `CMAKE_BUILD_TYPE` in + # single-configuration generator. + COMMAND ${CMAKE_COMMAND} + --build ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR} + --config $ + COMMAND ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD} + COMMENT "Running a test on Ginkgo's PkgConfig" + "This requires installing Ginkgo first") + # Setup CPack set(CPACK_PACKAGE_DESCRIPTION_FILE "${Ginkgo_SOURCE_DIR}/README.md") diff --git a/test/test_exportbuild_pkgconfig/CMakeLists.txt b/test/test_exportbuild_pkgconfig/CMakeLists.txt new file mode 100644 index 00000000000..611829c0a25 --- /dev/null +++ b/test/test_exportbuild_pkgconfig/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.9) +project(GinkgoExportBuildWithPkgConfigTest LANGUAGES CXX) + +find_package(PkgConfig REQUIRED) +# find_package(Ginkgo REQUIRED) +pkg_check_modules(GINKGO REQUIRED ginkgo) + +# Here, we use test install without any data. We instantiate the +# interface only. +add_executable(test_exportbuild_pkgconfig ../test_install/test_install.cpp) +target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LIBRARIES}) +target_include_directories(test_exportbuild_pkgconfig PRIVATE ${GINKGO_INCLUDE_DIRS}) +target_compile_features(test_exportbuild_pkgconfig PUBLIC cxx_std_14) +target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_CFLAGS}) \ No newline at end of file From c45ca027e7c37ab16f6f410c273279850b13f075 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Mon, 29 Aug 2022 16:32:49 -0400 Subject: [PATCH 02/10] fix the lib order, cflag, add interface library of papi --- .gitlab/scripts.yml | 6 ++-- cmake/Modules/FindPAPI.cmake | 3 ++ cmake/information_helpers.cmake | 28 +++++++++++++++++++ .../test_exportbuild_pkgconfig/CMakeLists.txt | 15 +++++++++- 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/.gitlab/scripts.yml b/.gitlab/scripts.yml index f8da2265072..1905d0cdc3c 100644 --- a/.gitlab/scripts.yml +++ b/.gitlab/scripts.yml @@ -52,7 +52,8 @@ -DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR} - ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi - - ninja test_exportbuild_pkgconfig + - ls /usr/local/lib/libginkgo* + - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_exportbuild_pkgconfig dependencies: [] .build_and_test_template: @@ -124,7 +125,8 @@ - if [ -n "${SYCL_DEVICE_TYPE}" ]; then unset SYCL_DEVICE_TYPE; fi - if [ -n "${SYCL_DEVICE_FILTER}" ]; then unset SYCL_DEVICE_FILTER; fi - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi - - ninja test_exportbuild_pkgconfig + - ls /usr/local/lib/libginkgo* + - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_exportbuild_pkgconfig dependencies: [] diff --git a/cmake/Modules/FindPAPI.cmake b/cmake/Modules/FindPAPI.cmake index c2648c252fb..c7a43468a38 100644 --- a/cmake/Modules/FindPAPI.cmake +++ b/cmake/Modules/FindPAPI.cmake @@ -118,6 +118,7 @@ if(PAPI_FOUND) if(EXISTS "${PAPI_LIBRARIES}") set_target_properties(PAPI::PAPI PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" + INTERFACE_LINK_LIBRARIES "${PAPI_LIBRARIES}" IMPORTED_LOCATION "${PAPI_LIBRARIES}") endif() if(PAPI_LIBRARY_RELEASE) @@ -125,6 +126,7 @@ if(PAPI_FOUND) IMPORTED_CONFIGURATIONS RELEASE) set_target_properties(PAPI::PAPI PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" + INTERFACE_LINK_LIBRARIES_RELEASE "${PAPI_LIBRARY_RELEASE}" IMPORTED_LOCATION_RELEASE "${PAPI_LIBRARY_RELEASE}") unset(PAPI_LIBRARY_RELEASE) endif() @@ -133,6 +135,7 @@ if(PAPI_FOUND) IMPORTED_CONFIGURATIONS DEBUG) set_target_properties(PAPI::PAPI PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C" + INTERFACE_LINK_LIBRARIES_DEBUG "${PAPI_LIBRARY_DEBUG}" IMPORTED_LOCATION_DEBUG "${PAPI_LIBRARY_DEBUG}") unset(PAPI_LIBRARY_DEBUG) endif() diff --git a/cmake/information_helpers.cmake b/cmake/information_helpers.cmake index 5cf80368c8a..431c8791e06 100644 --- a/cmake/information_helpers.cmake +++ b/cmake/information_helpers.cmake @@ -10,6 +10,8 @@ function(filter_generator_expressions INPUT OUTPUT) string(REGEX REPLACE "[$*" "\\1" TMP "${TMP}") string(REGEX REPLACE ".+INTERFACE:.+>" "" TMP "${TMP}") string(REGEX REPLACE "\$" "," TMP "${TMP}") + # Remove the left : or > + string(REGEX REPLACE ":|>" "" TMP "${TMP}") # Ignore hwloc include if it is the internal one string(REGEX REPLACE "${PROJECT_BINARY_DIR}.*hwloc/src/include.*" "" TMP "${TMP}") set(${OUTPUT} "${TMP}" PARENT_SCOPE) @@ -72,6 +74,29 @@ macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${_libs}") endif() endif() + else() + # Still add the existed lib into the list such that keep the track of the dependency + if (TARGET ${_libs}) + if (upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND "${_libs}" MATCHES "ginkgo.*") + set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}${CMAKE_DEBUG_POSTFIX}") + elseif("${_libs}" MATCHES "ginkgo.*") # Ginkgo libs are appended in the form -l + set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}") + endif() + # Get the link flags and treat them + get_target_property(GINKGO_INTERFACE_LIBS_LINK_FLAGS "${_libs}" + INTERFACE_LINK_OPTIONS) + if (GINKGO_INTERFACE_LIBS_LINK_FLAGS) + filter_generator_expressions("${GINKGO_INTERFACE_LIBS_LINK_FLAGS}" + GINKGO_INTERFACE_LIB_NAME) + endif() + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIB_NAME}") + elseif(EXISTS "${_libs}") + if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_LIBRARY_DIR}/libhwloc.so") + else() + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${_libs}") + endif() + endif() endif() endforeach() endmacro() @@ -96,7 +121,10 @@ macro(ginkgo_interface_information) ginkgo_interface_libraries_recursively("${GINKGO_INTERFACE_LINK_LIBRARIES}") # Format and store the interface libraries found + # remove duplicates on the reversed list to keep the dependecy in the end of list. + list(REVERSE GINKGO_INTERFACE_LIBS_FOUND) list(REMOVE_DUPLICATES GINKGO_INTERFACE_LIBS_FOUND) + list(REVERSE GINKGO_INTERFACE_LIBS_FOUND) list(REMOVE_ITEM GINKGO_INTERFACE_LIBS_FOUND "") string(REPLACE ";" " " GINKGO_FORMATTED_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIBS_FOUND}") diff --git a/test/test_exportbuild_pkgconfig/CMakeLists.txt b/test/test_exportbuild_pkgconfig/CMakeLists.txt index 611829c0a25..c0007e84c87 100644 --- a/test/test_exportbuild_pkgconfig/CMakeLists.txt +++ b/test/test_exportbuild_pkgconfig/CMakeLists.txt @@ -7,8 +7,21 @@ pkg_check_modules(GINKGO REQUIRED ginkgo) # Here, we use test install without any data. We instantiate the # interface only. +message("GINKGOCMAKE ${CMAKE_APPBUNDLE_PATH} ${CMAKE_PREFIX_PATH} ${CMAKE_FRAMEWORK_PATH}") +message("GINKGO ${GINKGO_PREFIX}") +message("GINKGO_LIBRARIES ${GINKGO_LIBRARIES}") +message("GINKGO_INCLUDE_DIRS ${GINKGO_INCLUDE_DIRS}") +message("GINKGO_CFLAGS ${GINKGO_CFLAGS}") +message("GINKGO_LDFLAGS ${GINKGO_LDFLAGS}") add_executable(test_exportbuild_pkgconfig ../test_install/test_install.cpp) target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LIBRARIES}) +target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LDFLAGS}) target_include_directories(test_exportbuild_pkgconfig PRIVATE ${GINKGO_INCLUDE_DIRS}) target_compile_features(test_exportbuild_pkgconfig PUBLIC cxx_std_14) -target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_CFLAGS}) \ No newline at end of file +target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_CFLAGS}) + +# pkg-config only takes care of ginkgo +if(GINKGO_HAVE_PAPI_SDE) + message("Link to PAPI") + target_link_libraries(test_exportbuild_pkgconfig PRIVATE PAPI::PAPI) +endif() \ No newline at end of file From 95d99f5df657c00f4e8420a9f3a5618a7e2a9578 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Thu, 13 Oct 2022 19:59:47 +0800 Subject: [PATCH 03/10] update cmake - use GENERATOR_IS_MULTI_CONFIG - use cmake link to pkgconfig Co-authored-by: Tobias Ribizel --- .github/workflows/osx.yml | 2 ++ .github/workflows/windows-msvc-ref.yml | 2 ++ .gitlab/scripts.yml | 4 +-- CMakeLists.txt | 25 +++++++----------- cmake/information_helpers.cmake | 6 +++++ .../test_exportbuild_pkgconfig/CMakeLists.txt | 26 +++++++------------ 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index ad898cedda0..0e3692c8a39 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -62,3 +62,5 @@ jobs: cd build make install make test_install + make genexdebug + LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH make test_exportbuild_pkgconfig diff --git a/.github/workflows/windows-msvc-ref.yml b/.github/workflows/windows-msvc-ref.yml index 9237022ceb1..edf80e9c536 100644 --- a/.github/workflows/windows-msvc-ref.yml +++ b/.github/workflows/windows-msvc-ref.yml @@ -57,3 +57,5 @@ jobs: cd build cmake --install . --config ${{ matrix.config.build_type }} cmake --build . --target test_install --config ${{ matrix.config.build_type }} + cmake --build . --target genexdebug --config ${{ matrix.config.build_type }} + cmake --build . --target test_exportbuild_pkgconfig ${{ matrix.config.build_type }} diff --git a/.gitlab/scripts.yml b/.gitlab/scripts.yml index 1905d0cdc3c..20afb9b9ffe 100644 --- a/.gitlab/scripts.yml +++ b/.gitlab/scripts.yml @@ -51,8 +51,8 @@ -DGINKGO_DPCPP_SINGLE_MODE=${DPCPP_SINGLE_MODE} -DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR} - ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install + - ninja genexdebug - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi - - ls /usr/local/lib/libginkgo* - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_exportbuild_pkgconfig dependencies: [] @@ -122,10 +122,10 @@ ninja validate_all_examples fi fi + - ninja genexdebug - if [ -n "${SYCL_DEVICE_TYPE}" ]; then unset SYCL_DEVICE_TYPE; fi - if [ -n "${SYCL_DEVICE_FILTER}" ]; then unset SYCL_DEVICE_FILTER; fi - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi - - ls /usr/local/lib/libginkgo* - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_exportbuild_pkgconfig dependencies: [] diff --git a/CMakeLists.txt b/CMakeLists.txt index 101c29810b1..f832046d2ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -363,23 +363,18 @@ set(GINKGO_TEST_EXPORTBUILD_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_exportbuild/ set(GINKGO_TEST_EXPORTBUILD_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_exportbuild/") set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_exportbuild_pkgconfig/") set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_exportbuild_pkgconfig/") -if(MSVC) - set(GINKGO_TEST_INSTALL_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/$/test_install) - set(GINKGO_TEST_EXPORTBUILD_CMD ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}/$/test_exportbuild) - set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR}/$/test_exportbuild_pkgconfig) - if(GINKGO_BUILD_CUDA) - set(GINKGO_TEST_INSTALL_CUDA_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/$/test_install_cuda) - endif() -else() - set(GINKGO_TEST_INSTALL_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/test_install) - set(GINKGO_TEST_EXPORTBUILD_CMD ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}/test_exportbuild) - set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR}/test_exportbuild_pkgconfig) - if(GINKGO_BUILD_CUDA) - set(GINKGO_TEST_INSTALL_CUDA_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/test_install_cuda) - endif() +get_property(GINKGO_USE_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +# GINKGO_CONFIG_PREFIX contains / in the end. +set(GINKGO_CONFIG_PREFIX "$<$:$/>") +add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "GINKGO_CONFIG_PREFIX ${GINKGO_CONFIG_PREFIX}") +set(GINKGO_TEST_INSTALL_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_install) +set(GINKGO_TEST_EXPORTBUILD_CMD ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_exportbuild) +set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_exportbuild_pkgconfig) +if(GINKGO_BUILD_CUDA) + set(GINKGO_TEST_INSTALL_CUDA_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_install_cuda) endif() if(GINKGO_BUILD_HIP) - set(GINKGO_TEST_INSTALL_HIP_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/test_install_hip) + set(GINKGO_TEST_INSTALL_HIP_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_install_hip) endif() file(MAKE_DIRECTORY "${GINKGO_TEST_INSTALL_BIN_DIR}") diff --git a/cmake/information_helpers.cmake b/cmake/information_helpers.cmake index 431c8791e06..4e096573a98 100644 --- a/cmake/information_helpers.cmake +++ b/cmake/information_helpers.cmake @@ -1,3 +1,5 @@ +# TODO: we may use file(GENERATE ... TARGET ...) to generate config file based on the target property +# when we bump the CMake minimum version to 3.15/3.19 function(filter_generator_expressions INPUT OUTPUT) # See https://gitlab.kitware.com/cmake/cmake/-/blob/v3.22.2/Modules/FindMPI.cmake#L1218 # and other versions of this file for what we are removing here. @@ -18,10 +20,12 @@ function(filter_generator_expressions INPUT OUTPUT) endfunction() macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) + message("INTERFACE_LIBS ${INTERFACE_LIBS}") foreach(_libs ${INTERFACE_LIBS}) if (NOT "${_libs}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND AND NOT "-l${_libs}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND) if (TARGET ${_libs}) + message("${_libs} is TARGET") if (upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND "${_libs}" MATCHES "ginkgo.*") set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}${CMAKE_DEBUG_POSTFIX}") elseif("${_libs}" MATCHES "ginkgo.*") # Ginkgo libs are appended in the form -l @@ -68,10 +72,12 @@ macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) INTERFACE_LINK_LIBRARIES) ginkgo_interface_libraries_recursively("${GINKGO_LIBS_INTERFACE_LIBS}") elseif(EXISTS "${_libs}") + message("${_libs} is EXISTED") if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_LIBRARY_DIR}/libhwloc.so") else() list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${_libs}") + message("GINKGO_INTERFACE_LIBS_FOUND ${GINKGO_INTERFACE_LIBS_FOUND}") endif() endif() else() diff --git a/test/test_exportbuild_pkgconfig/CMakeLists.txt b/test/test_exportbuild_pkgconfig/CMakeLists.txt index c0007e84c87..b574a5c0caa 100644 --- a/test/test_exportbuild_pkgconfig/CMakeLists.txt +++ b/test/test_exportbuild_pkgconfig/CMakeLists.txt @@ -2,26 +2,20 @@ cmake_minimum_required(VERSION 3.9) project(GinkgoExportBuildWithPkgConfigTest LANGUAGES CXX) find_package(PkgConfig REQUIRED) -# find_package(Ginkgo REQUIRED) -pkg_check_modules(GINKGO REQUIRED ginkgo) +pkg_check_modules(GINKGO REQUIRED IMPORTED_TARGET ginkgo) -# Here, we use test install without any data. We instantiate the -# interface only. -message("GINKGOCMAKE ${CMAKE_APPBUNDLE_PATH} ${CMAKE_PREFIX_PATH} ${CMAKE_FRAMEWORK_PATH}") -message("GINKGO ${GINKGO_PREFIX}") message("GINKGO_LIBRARIES ${GINKGO_LIBRARIES}") message("GINKGO_INCLUDE_DIRS ${GINKGO_INCLUDE_DIRS}") message("GINKGO_CFLAGS ${GINKGO_CFLAGS}") message("GINKGO_LDFLAGS ${GINKGO_LDFLAGS}") + + +# Here, we use test install without any data. We instantiate the +# interface only. add_executable(test_exportbuild_pkgconfig ../test_install/test_install.cpp) -target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LIBRARIES}) -target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LDFLAGS}) -target_include_directories(test_exportbuild_pkgconfig PRIVATE ${GINKGO_INCLUDE_DIRS}) target_compile_features(test_exportbuild_pkgconfig PUBLIC cxx_std_14) -target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_CFLAGS}) - -# pkg-config only takes care of ginkgo -if(GINKGO_HAVE_PAPI_SDE) - message("Link to PAPI") - target_link_libraries(test_exportbuild_pkgconfig PRIVATE PAPI::PAPI) -endif() \ No newline at end of file +target_link_libraries(test_exportbuild_pkgconfig PUBLIC PkgConfig::GINKGO) +# target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LIBRARIES}) +# target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LDFLAGS}) +# target_include_directories(test_exportbuild_pkgconfig PRIVATE ${GINKGO_INCLUDE_DIRS}) +# target_compile_features(test_exportbuild_pkgconfig PRIVATE ${GINKGO_CFLAGS}) From 41753d8f1f8e1b66eaedb751daabf198cbf48bb3 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Wed, 19 Oct 2022 15:51:54 +0800 Subject: [PATCH 04/10] put ldflag into library --- test/test_exportbuild_pkgconfig/CMakeLists.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/test_exportbuild_pkgconfig/CMakeLists.txt b/test/test_exportbuild_pkgconfig/CMakeLists.txt index b574a5c0caa..12f6e02579d 100644 --- a/test/test_exportbuild_pkgconfig/CMakeLists.txt +++ b/test/test_exportbuild_pkgconfig/CMakeLists.txt @@ -14,8 +14,13 @@ message("GINKGO_LDFLAGS ${GINKGO_LDFLAGS}") # interface only. add_executable(test_exportbuild_pkgconfig ../test_install/test_install.cpp) target_compile_features(test_exportbuild_pkgconfig PUBLIC cxx_std_14) -target_link_libraries(test_exportbuild_pkgconfig PUBLIC PkgConfig::GINKGO) +# target_link_libraries(test_exportbuild_pkgconfig PRIVATE PkgConfig::GINKGO) +# target_link_libraries(test_exportbuild_pkgconfig PRIVATE -l/usr/lib/libpapi.so) +# CMake PkgConfig only puts the -l, -L, and -framework into link_libraries and others into link_options +# When linking the target, the linking option will be before the compiled object such that the linking error +set_property(TARGET PkgConfig::GINKGO PROPERTY INTERFACE_LINK_LIBRARIES "${GINKGO_LDFLAGS}") +set_property(TARGET PkgConfig::GINKGO PROPERTY INTERFACE_LINK_OPTIONS "") +target_link_libraries(test_exportbuild_pkgconfig PRIVATE PkgConfig::GINKGO) # target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LIBRARIES}) # target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LDFLAGS}) -# target_include_directories(test_exportbuild_pkgconfig PRIVATE ${GINKGO_INCLUDE_DIRS}) -# target_compile_features(test_exportbuild_pkgconfig PRIVATE ${GINKGO_CFLAGS}) +# target_include_directories(test_exportbuild_pkgconfig PUBLIC ${GINKGO_INCLUDE_DIRS}) From b6c21c1481a726cf5e3dad988eaa0477d80f1273 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Wed, 19 Oct 2022 23:09:59 +0800 Subject: [PATCH 05/10] fix the check of debug and add all dependecy --- .github/workflows/windows-msvc-ref.yml | 6 +++++- cmake/information_helpers.cmake | 20 ++++++++++++++----- .../test_exportbuild_pkgconfig/CMakeLists.txt | 12 +++++++---- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/workflows/windows-msvc-ref.yml b/.github/workflows/windows-msvc-ref.yml index edf80e9c536..7ee64499e75 100644 --- a/.github/workflows/windows-msvc-ref.yml +++ b/.github/workflows/windows-msvc-ref.yml @@ -58,4 +58,8 @@ jobs: cmake --install . --config ${{ matrix.config.build_type }} cmake --build . --target test_install --config ${{ matrix.config.build_type }} cmake --build . --target genexdebug --config ${{ matrix.config.build_type }} - cmake --build . --target test_exportbuild_pkgconfig ${{ matrix.config.build_type }} + echo "PKG $env:PKG_CONFIG_PATH" + $env:PKG_CONFIG_PATH="C:\Program Files (x86)\Ginkgo\lib\pkgconfig" + echo "PKG $env:PKG_CONFIG_PATH" + cat "C:\Program Files (x86)\Ginkgo\lib\pkgconfig\ginkgo.pc" + cmake --build . --target test_exportbuild_pkgconfig --config ${{ matrix.config.build_type }} diff --git a/cmake/information_helpers.cmake b/cmake/information_helpers.cmake index 4e096573a98..660e0d46ecd 100644 --- a/cmake/information_helpers.cmake +++ b/cmake/information_helpers.cmake @@ -20,12 +20,15 @@ function(filter_generator_expressions INPUT OUTPUT) endfunction() macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) - message("INTERFACE_LIBS ${INTERFACE_LIBS}") + message(STATUS "INTERFACE_LIBS ${INTERFACE_LIBS}") foreach(_libs ${INTERFACE_LIBS}) + if (NOT "${_libs}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND - AND NOT "-l${_libs}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND) + AND NOT "-l${_libs}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND + AND NOT "-l${_libs}${CMAKE_DEBUG_POSTFIX}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND) + message(STATUS "handles ${_libs}") if (TARGET ${_libs}) - message("${_libs} is TARGET") + message(STATUS "${_libs} is TARGET") if (upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND "${_libs}" MATCHES "ginkgo.*") set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}${CMAKE_DEBUG_POSTFIX}") elseif("${_libs}" MATCHES "ginkgo.*") # Ginkgo libs are appended in the form -l @@ -72,15 +75,16 @@ macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) INTERFACE_LINK_LIBRARIES) ginkgo_interface_libraries_recursively("${GINKGO_LIBS_INTERFACE_LIBS}") elseif(EXISTS "${_libs}") - message("${_libs} is EXISTED") + message(STATUS "${_libs} is EXISTED") if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_LIBRARY_DIR}/libhwloc.so") else() list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${_libs}") - message("GINKGO_INTERFACE_LIBS_FOUND ${GINKGO_INTERFACE_LIBS_FOUND}") + message(STATUS "GINKGO_INTERFACE_LIBS_FOUND ${GINKGO_INTERFACE_LIBS_FOUND}") endif() endif() else() + message(STATUS "add ${_libs}") # Still add the existed lib into the list such that keep the track of the dependency if (TARGET ${_libs}) if (upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND "${_libs}" MATCHES "ginkgo.*") @@ -96,6 +100,10 @@ macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) GINKGO_INTERFACE_LIB_NAME) endif() list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIB_NAME}") + # Keep recursing through the libraries + get_target_property(GINKGO_LIBS_INTERFACE_LIBS "${_libs}" + INTERFACE_LINK_LIBRARIES) + ginkgo_interface_libraries_recursively("${GINKGO_LIBS_INTERFACE_LIBS}") elseif(EXISTS "${_libs}") if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_LIBRARY_DIR}/libhwloc.so") @@ -128,10 +136,12 @@ macro(ginkgo_interface_information) # Format and store the interface libraries found # remove duplicates on the reversed list to keep the dependecy in the end of list. + message(STATUS "ORIGINAL ${GINKGO_INTERFACE_LIBS_FOUND}") list(REVERSE GINKGO_INTERFACE_LIBS_FOUND) list(REMOVE_DUPLICATES GINKGO_INTERFACE_LIBS_FOUND) list(REVERSE GINKGO_INTERFACE_LIBS_FOUND) list(REMOVE_ITEM GINKGO_INTERFACE_LIBS_FOUND "") + message(STATUS "AFTER ${GINKGO_INTERFACE_LIBS_FOUND}") string(REPLACE ";" " " GINKGO_FORMATTED_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIBS_FOUND}") set(GINKGO_INTERFACE_LINK_FLAGS diff --git a/test/test_exportbuild_pkgconfig/CMakeLists.txt b/test/test_exportbuild_pkgconfig/CMakeLists.txt index 12f6e02579d..61f04283b5b 100644 --- a/test/test_exportbuild_pkgconfig/CMakeLists.txt +++ b/test/test_exportbuild_pkgconfig/CMakeLists.txt @@ -4,16 +4,20 @@ project(GinkgoExportBuildWithPkgConfigTest LANGUAGES CXX) find_package(PkgConfig REQUIRED) pkg_check_modules(GINKGO REQUIRED IMPORTED_TARGET ginkgo) -message("GINKGO_LIBRARIES ${GINKGO_LIBRARIES}") -message("GINKGO_INCLUDE_DIRS ${GINKGO_INCLUDE_DIRS}") -message("GINKGO_CFLAGS ${GINKGO_CFLAGS}") -message("GINKGO_LDFLAGS ${GINKGO_LDFLAGS}") +message(STATUS "GINKGO_LIBRARIES ${GINKGO_LIBRARIES}") +message(STATUS "GINKGO_INCLUDE_DIRS ${GINKGO_INCLUDE_DIRS}") +message(STATUS "GINKGO_CFLAGS ${GINKGO_CFLAGS}") +message(STATUS "GINKGO_LDFLAGS ${GINKGO_LDFLAGS}") # Here, we use test install without any data. We instantiate the # interface only. add_executable(test_exportbuild_pkgconfig ../test_install/test_install.cpp) target_compile_features(test_exportbuild_pkgconfig PUBLIC cxx_std_14) +get_target_property(LINK_LIBRARIES PkgConfig::GINKGO INTERFACE_LINK_LIBRARIES) +message(STATUS "LINK_LIBRARIES ${LINK_LIBRARIES}") +get_target_property(INC PkgConfig::GINKGO INTERFACE_INCLUDE_DIRECTORIES) +message(STATUS "INC ${INC}") # target_link_libraries(test_exportbuild_pkgconfig PRIVATE PkgConfig::GINKGO) # target_link_libraries(test_exportbuild_pkgconfig PRIVATE -l/usr/lib/libpapi.so) # CMake PkgConfig only puts the -l, -L, and -framework into link_libraries and others into link_options From c7a8deebd3fa8ddddab9249fed389b13fd735356 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Fri, 21 Oct 2022 19:42:57 +0800 Subject: [PATCH 06/10] escape space for pkg-config and rearrange code --- .github/workflows/osx.yml | 2 - .github/workflows/windows-msvc-ref.yml | 6 - .gitlab/scripts.yml | 2 - CMakeLists.txt | 8 +- cmake/ginkgo.pc.in | 2 +- cmake/information_helpers.cmake | 143 ++++++------------ .../test_exportbuild_pkgconfig/CMakeLists.txt | 16 +- 7 files changed, 59 insertions(+), 120 deletions(-) diff --git a/.github/workflows/osx.yml b/.github/workflows/osx.yml index 0e3692c8a39..ad898cedda0 100644 --- a/.github/workflows/osx.yml +++ b/.github/workflows/osx.yml @@ -62,5 +62,3 @@ jobs: cd build make install make test_install - make genexdebug - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH make test_exportbuild_pkgconfig diff --git a/.github/workflows/windows-msvc-ref.yml b/.github/workflows/windows-msvc-ref.yml index 7ee64499e75..9237022ceb1 100644 --- a/.github/workflows/windows-msvc-ref.yml +++ b/.github/workflows/windows-msvc-ref.yml @@ -57,9 +57,3 @@ jobs: cd build cmake --install . --config ${{ matrix.config.build_type }} cmake --build . --target test_install --config ${{ matrix.config.build_type }} - cmake --build . --target genexdebug --config ${{ matrix.config.build_type }} - echo "PKG $env:PKG_CONFIG_PATH" - $env:PKG_CONFIG_PATH="C:\Program Files (x86)\Ginkgo\lib\pkgconfig" - echo "PKG $env:PKG_CONFIG_PATH" - cat "C:\Program Files (x86)\Ginkgo\lib\pkgconfig\ginkgo.pc" - cmake --build . --target test_exportbuild_pkgconfig --config ${{ matrix.config.build_type }} diff --git a/.gitlab/scripts.yml b/.gitlab/scripts.yml index 20afb9b9ffe..cbc9d70ae45 100644 --- a/.gitlab/scripts.yml +++ b/.gitlab/scripts.yml @@ -51,7 +51,6 @@ -DGINKGO_DPCPP_SINGLE_MODE=${DPCPP_SINGLE_MODE} -DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR} - ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install - - ninja genexdebug - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_exportbuild_pkgconfig dependencies: [] @@ -122,7 +121,6 @@ ninja validate_all_examples fi fi - - ninja genexdebug - if [ -n "${SYCL_DEVICE_TYPE}" ]; then unset SYCL_DEVICE_TYPE; fi - if [ -n "${SYCL_DEVICE_FILTER}" ]; then unset SYCL_DEVICE_FILTER; fi - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index f832046d2ed..5aed0560d8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,6 +345,13 @@ if(GINKGO_BUILD_DOC) add_subdirectory(doc) endif() + +# add escape character '\' and convert the list to string +string(REPLACE " " "\ " PKG_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +list(TRANSFORM GINKGO_INTERFACE_LINK_FLAGS REPLACE " " "\\\\ ") +list(TRANSFORM GINKGO_INTERFACE_CXX_FLAGS REPLACE " " "\\\\ ") +string(REPLACE ";" " " GINKGO_INTERFACE_CXX_FLAGS "${GINKGO_INTERFACE_CXX_FLAGS}") +string(REPLACE ";" " " GINKGO_INTERFACE_LINK_FLAGS "${GINKGO_INTERFACE_LINK_FLAGS}") configure_file(${Ginkgo_SOURCE_DIR}/cmake/ginkgo.pc.in ${Ginkgo_BINARY_DIR}/ginkgo.pc.in @ONLY) file(GENERATE OUTPUT ${Ginkgo_BINARY_DIR}/ginkgo_$.pc @@ -366,7 +373,6 @@ set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_ex get_property(GINKGO_USE_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) # GINKGO_CONFIG_PREFIX contains / in the end. set(GINKGO_CONFIG_PREFIX "$<$:$/>") -add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "GINKGO_CONFIG_PREFIX ${GINKGO_CONFIG_PREFIX}") set(GINKGO_TEST_INSTALL_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_install) set(GINKGO_TEST_EXPORTBUILD_CMD ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_exportbuild) set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_exportbuild_pkgconfig) diff --git a/cmake/ginkgo.pc.in b/cmake/ginkgo.pc.in index 9d5aeb65808..25eb7791ff2 100644 --- a/cmake/ginkgo.pc.in +++ b/cmake/ginkgo.pc.in @@ -1,4 +1,4 @@ -prefix=@CMAKE_INSTALL_PREFIX@ +prefix=@PKG_CMAKE_INSTALL_PREFIX@ libdir=${prefix}/@GINKGO_INSTALL_LIBRARY_DIR@ includedir=${prefix}/@GINKGO_INSTALL_INCLUDE_DIR@ diff --git a/cmake/information_helpers.cmake b/cmake/information_helpers.cmake index 660e0d46ecd..aead7339472 100644 --- a/cmake/information_helpers.cmake +++ b/cmake/information_helpers.cmake @@ -20,96 +20,57 @@ function(filter_generator_expressions INPUT OUTPUT) endfunction() macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) - message(STATUS "INTERFACE_LIBS ${INTERFACE_LIBS}") + # always add the interface to the list to keep the order information + # Currently, it does not support the circular dependence and MSVC. foreach(_libs ${INTERFACE_LIBS}) - - if (NOT "${_libs}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND - AND NOT "-l${_libs}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND - AND NOT "-l${_libs}${CMAKE_DEBUG_POSTFIX}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND) - message(STATUS "handles ${_libs}") - if (TARGET ${_libs}) - message(STATUS "${_libs} is TARGET") - if (upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND "${_libs}" MATCHES "ginkgo.*") - set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}${CMAKE_DEBUG_POSTFIX}") - elseif("${_libs}" MATCHES "ginkgo.*") # Ginkgo libs are appended in the form -l - set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}") + if (TARGET ${_libs}) + if("${_libs}" MATCHES "ginkgo.*") + set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}") + if(upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG") + set(GINKGO_INTERFACE_LIB_NAME "${GINKGO_INTERFACE_LIB_NAME}${CMAKE_DEBUG_POSTFIX}") endif() - - # Get the link flags and treat them - get_target_property(GINKGO_INTERFACE_LIBS_LINK_FLAGS "${_libs}" - INTERFACE_LINK_OPTIONS) - if (GINKGO_INTERFACE_LIBS_LINK_FLAGS) - filter_generator_expressions("${GINKGO_INTERFACE_LIBS_LINK_FLAGS}" - GINKGO_INTERFACE_LIB_NAME) - endif() - if (NOT "${GINKGO_INTERFACE_LIB_NAME}" IN_LIST GINKGO_INTERFACE_LIBS_FOUND) - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIB_NAME}") - endif() - - # Populate the include directories - get_target_property(GINKGO_LIBS_INTERFACE_INCS "${_libs}" - INTERFACE_INCLUDE_DIRECTORIES) - foreach(_incs ${GINKGO_LIBS_INTERFACE_INCS}) - filter_generator_expressions("${_incs}" GINKGO_INTERFACE_INC_FILTERED) - if (GINKGO_INTERFACE_INC_FILTERED AND NOT - "-I${GINKGO_INTERFACE_INC_FILTERED}" IN_LIST GINKGO_INTERFACE_CFLAGS_FOUND) - list(APPEND GINKGO_INTERFACE_CFLAGS_FOUND "-I${GINKGO_INTERFACE_INC_FILTERED}") - endif() - endforeach() - - # Populate the compiler options and definitions if needed - get_target_property(GINKGO_LIBS_INTERFACE_DEFS "${_libs}" - INTERFACE_COMPILE_DEFINITIONS) - if (GINKGO_LIBS_INTERFACE_DEFS) - list(APPEND GINKGO_INTERFACE_CFLAGS_FOUND "${GINKGO_LIBS_INTERFACE_DEFS}") - endif() - get_target_property(GINKGO_LIBS_INTERFACE_OPTS "${_libs}" - INTERFACE_COMPILE_OPTIONS) - filter_generator_expressions("${GINKGO_LIBS_INTERFACE_OPTS}" GINKGO_LIBS_INTERFACE_OPTS_FILTERED) - if (GINKGO_LIBS_INTERFACE_OPTS) - list(APPEND GINKGO_INTERFACE_CFLAGS_FOUND "${GINKGO_LIBS_INTERFACE_OPTS_FILTERED}") + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIB_NAME}") + endif() + # Get the link flags and treat them + get_target_property(GINKGO_INTERFACE_LIBS_LINK_FLAGS "${_libs}" + INTERFACE_LINK_OPTIONS) + if (GINKGO_INTERFACE_LIBS_LINK_FLAGS) + filter_generator_expressions("${GINKGO_INTERFACE_LIBS_LINK_FLAGS}" + GINKGO_INTERFACE_LIB_NAME) + endif() + # Populate the include directories + get_target_property(GINKGO_LIBS_INTERFACE_INCS "${_libs}" + INTERFACE_INCLUDE_DIRECTORIES) + foreach(_incs ${GINKGO_LIBS_INTERFACE_INCS}) + filter_generator_expressions("${_incs}" GINKGO_INTERFACE_INC_FILTERED) + if (GINKGO_INTERFACE_INC_FILTERED AND NOT + "-I${GINKGO_INTERFACE_INC_FILTERED}" IN_LIST GINKGO_INTERFACE_CFLAGS_FOUND) + list(APPEND GINKGO_INTERFACE_CFLAGS_FOUND "-I${GINKGO_INTERFACE_INC_FILTERED}") endif() + endforeach() - # Keep recursing through the libraries - get_target_property(GINKGO_LIBS_INTERFACE_LIBS "${_libs}" - INTERFACE_LINK_LIBRARIES) - ginkgo_interface_libraries_recursively("${GINKGO_LIBS_INTERFACE_LIBS}") - elseif(EXISTS "${_libs}") - message(STATUS "${_libs} is EXISTED") - if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_LIBRARY_DIR}/libhwloc.so") - else() - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${_libs}") - message(STATUS "GINKGO_INTERFACE_LIBS_FOUND ${GINKGO_INTERFACE_LIBS_FOUND}") - endif() + # Populate the compiler options and definitions if needed + get_target_property(GINKGO_LIBS_INTERFACE_DEFS "${_libs}" + INTERFACE_COMPILE_DEFINITIONS) + if (GINKGO_LIBS_INTERFACE_DEFS) + list(APPEND GINKGO_INTERFACE_CFLAGS_FOUND "${GINKGO_LIBS_INTERFACE_DEFS}") endif() - else() - message(STATUS "add ${_libs}") - # Still add the existed lib into the list such that keep the track of the dependency - if (TARGET ${_libs}) - if (upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND "${_libs}" MATCHES "ginkgo.*") - set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}${CMAKE_DEBUG_POSTFIX}") - elseif("${_libs}" MATCHES "ginkgo.*") # Ginkgo libs are appended in the form -l - set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}") - endif() - # Get the link flags and treat them - get_target_property(GINKGO_INTERFACE_LIBS_LINK_FLAGS "${_libs}" - INTERFACE_LINK_OPTIONS) - if (GINKGO_INTERFACE_LIBS_LINK_FLAGS) - filter_generator_expressions("${GINKGO_INTERFACE_LIBS_LINK_FLAGS}" - GINKGO_INTERFACE_LIB_NAME) - endif() - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIB_NAME}") - # Keep recursing through the libraries - get_target_property(GINKGO_LIBS_INTERFACE_LIBS "${_libs}" - INTERFACE_LINK_LIBRARIES) - ginkgo_interface_libraries_recursively("${GINKGO_LIBS_INTERFACE_LIBS}") - elseif(EXISTS "${_libs}") - if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_LIBRARY_DIR}/libhwloc.so") - else() - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${_libs}") - endif() + get_target_property(GINKGO_LIBS_INTERFACE_OPTS "${_libs}" + INTERFACE_COMPILE_OPTIONS) + filter_generator_expressions("${GINKGO_LIBS_INTERFACE_OPTS}" GINKGO_LIBS_INTERFACE_OPTS_FILTERED) + if (GINKGO_LIBS_INTERFACE_OPTS) + list(APPEND GINKGO_INTERFACE_CFLAGS_FOUND "${GINKGO_LIBS_INTERFACE_OPTS_FILTERED}") + endif() + + # Keep recursing through the libraries + get_target_property(GINKGO_LIBS_INTERFACE_LIBS "${_libs}" + INTERFACE_LINK_LIBRARIES) + ginkgo_interface_libraries_recursively("${GINKGO_LIBS_INTERFACE_LIBS}") + elseif(EXISTS "${_libs}") + if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_LIBRARY_DIR}/libhwloc.so") + else() + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${_libs}") endif() endif() endforeach() @@ -136,23 +97,19 @@ macro(ginkgo_interface_information) # Format and store the interface libraries found # remove duplicates on the reversed list to keep the dependecy in the end of list. - message(STATUS "ORIGINAL ${GINKGO_INTERFACE_LIBS_FOUND}") list(REVERSE GINKGO_INTERFACE_LIBS_FOUND) list(REMOVE_DUPLICATES GINKGO_INTERFACE_LIBS_FOUND) list(REVERSE GINKGO_INTERFACE_LIBS_FOUND) list(REMOVE_ITEM GINKGO_INTERFACE_LIBS_FOUND "") - message(STATUS "AFTER ${GINKGO_INTERFACE_LIBS_FOUND}") - string(REPLACE ";" " " - GINKGO_FORMATTED_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIBS_FOUND}") + # keep it as list set(GINKGO_INTERFACE_LINK_FLAGS - "${GINKGO_INTERFACE_LINK_FLAGS} ${GINKGO_FORMATTED_INTERFACE_LIBS_FOUND}") + ${GINKGO_INTERFACE_LINK_FLAGS} ${GINKGO_INTERFACE_LIBS_FOUND}) unset(GINKGO_INTERFACE_LIBS_FOUND) # Format and store the interface cflags found list(REMOVE_DUPLICATES GINKGO_INTERFACE_CFLAGS_FOUND) list(REMOVE_ITEM GINKGO_INTERFACE_CFLAGS_FOUND "") - string(REPLACE ";" " " - GINKGO_FORMATTED_INTERFACE_CFLAGS_FOUND "${GINKGO_INTERFACE_CFLAGS_FOUND}") - set(GINKGO_INTERFACE_CXX_FLAGS "${GINKGO_FORMATTED_INTERFACE_CFLAGS_FOUND}") + # Keep it as list + set(GINKGO_INTERFACE_CXX_FLAGS ${GINKGO_INTERFACE_CFLAGS_FOUND}) unset(GINKGO_INTERFACE_CFLAGS_FOUND) endmacro(ginkgo_interface_information) diff --git a/test/test_exportbuild_pkgconfig/CMakeLists.txt b/test/test_exportbuild_pkgconfig/CMakeLists.txt index 61f04283b5b..6d1c5d534f8 100644 --- a/test/test_exportbuild_pkgconfig/CMakeLists.txt +++ b/test/test_exportbuild_pkgconfig/CMakeLists.txt @@ -4,27 +4,13 @@ project(GinkgoExportBuildWithPkgConfigTest LANGUAGES CXX) find_package(PkgConfig REQUIRED) pkg_check_modules(GINKGO REQUIRED IMPORTED_TARGET ginkgo) -message(STATUS "GINKGO_LIBRARIES ${GINKGO_LIBRARIES}") -message(STATUS "GINKGO_INCLUDE_DIRS ${GINKGO_INCLUDE_DIRS}") -message(STATUS "GINKGO_CFLAGS ${GINKGO_CFLAGS}") -message(STATUS "GINKGO_LDFLAGS ${GINKGO_LDFLAGS}") - # Here, we use test install without any data. We instantiate the # interface only. add_executable(test_exportbuild_pkgconfig ../test_install/test_install.cpp) target_compile_features(test_exportbuild_pkgconfig PUBLIC cxx_std_14) -get_target_property(LINK_LIBRARIES PkgConfig::GINKGO INTERFACE_LINK_LIBRARIES) -message(STATUS "LINK_LIBRARIES ${LINK_LIBRARIES}") -get_target_property(INC PkgConfig::GINKGO INTERFACE_INCLUDE_DIRECTORIES) -message(STATUS "INC ${INC}") -# target_link_libraries(test_exportbuild_pkgconfig PRIVATE PkgConfig::GINKGO) -# target_link_libraries(test_exportbuild_pkgconfig PRIVATE -l/usr/lib/libpapi.so) # CMake PkgConfig only puts the -l, -L, and -framework into link_libraries and others into link_options -# When linking the target, the linking option will be before the compiled object such that the linking error +# When linking the target, the linking option will be before the compiled object to lead the linking error set_property(TARGET PkgConfig::GINKGO PROPERTY INTERFACE_LINK_LIBRARIES "${GINKGO_LDFLAGS}") set_property(TARGET PkgConfig::GINKGO PROPERTY INTERFACE_LINK_OPTIONS "") target_link_libraries(test_exportbuild_pkgconfig PRIVATE PkgConfig::GINKGO) -# target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LIBRARIES}) -# target_link_libraries(test_exportbuild_pkgconfig PRIVATE ${GINKGO_LDFLAGS}) -# target_include_directories(test_exportbuild_pkgconfig PUBLIC ${GINKGO_INCLUDE_DIRS}) From d15beb915beec8c9e970644f86137a3723e585d5 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Wed, 2 Nov 2022 00:25:30 +0800 Subject: [PATCH 07/10] update doc, and use cmake-gen-exp for debug suffix Co-authored-by: Tobias Ribizel --- CMakeLists.txt | 4 +++- cmake/information_helpers.cmake | 12 ++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5aed0560d8f..c5ed5c14046 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -346,10 +346,12 @@ if(GINKGO_BUILD_DOC) endif() -# add escape character '\' and convert the list to string +# add escape character '\' for space string(REPLACE " " "\ " PKG_CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +# add escape character '\' for space in regex mode list(TRANSFORM GINKGO_INTERFACE_LINK_FLAGS REPLACE " " "\\\\ ") list(TRANSFORM GINKGO_INTERFACE_CXX_FLAGS REPLACE " " "\\\\ ") +# convert the list to string string(REPLACE ";" " " GINKGO_INTERFACE_CXX_FLAGS "${GINKGO_INTERFACE_CXX_FLAGS}") string(REPLACE ";" " " GINKGO_INTERFACE_LINK_FLAGS "${GINKGO_INTERFACE_LINK_FLAGS}") configure_file(${Ginkgo_SOURCE_DIR}/cmake/ginkgo.pc.in diff --git a/cmake/information_helpers.cmake b/cmake/information_helpers.cmake index aead7339472..781f7ecd27c 100644 --- a/cmake/information_helpers.cmake +++ b/cmake/information_helpers.cmake @@ -25,10 +25,7 @@ macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) foreach(_libs ${INTERFACE_LIBS}) if (TARGET ${_libs}) if("${_libs}" MATCHES "ginkgo.*") - set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}") - if(upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - set(GINKGO_INTERFACE_LIB_NAME "${GINKGO_INTERFACE_LIB_NAME}${CMAKE_DEBUG_POSTFIX}") - endif() + set(GINKGO_INTERFACE_LIB_NAME "-l${_libs}$<$:${CMAKE_DEBUG_POSTFIX}>") list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${GINKGO_INTERFACE_LIB_NAME}") endif() # Get the link flags and treat them @@ -81,12 +78,7 @@ macro(ginkgo_interface_information) unset(GINKGO_INTERFACE_LIBS_FOUND) unset(GINKGO_INTERFACE_CFLAGS_FOUND) # Prepare recursively populated library list - string(TOUPPER "${CMAKE_BUILD_TYPE}" upper_CMAKE_BUILD_TYPE) - if (upper_CMAKE_BUILD_TYPE STREQUAL "DEBUG") - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "-lginkgo${CMAKE_DEBUG_POSTFIX}") - else() - list(APPEND GINKGO_INTERFACE_LIBS_FOUND "-lginkgo") - endif() + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "-lginkgo$<$:${CMAKE_DEBUG_POSTFIX}>") # Prepare recursively populated include directory list list(APPEND GINKGO_INTERFACE_CFLAGS_FOUND "-I${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_INCLUDE_DIR}") From 3c5143aa1b9a462a92f70c9125b567666fb1a7e1 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Sat, 5 Nov 2022 00:22:33 +0800 Subject: [PATCH 08/10] change name Co-authored-by: Terry Cojean --- .gitlab/scripts.yml | 4 ++-- CMakeLists.txt | 16 ++++++++-------- .../CMakeLists.txt | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) rename test/{test_exportbuild_pkgconfig => test_pkgconfig}/CMakeLists.txt (74%) diff --git a/.gitlab/scripts.yml b/.gitlab/scripts.yml index cbc9d70ae45..ef364c09b0d 100644 --- a/.gitlab/scripts.yml +++ b/.gitlab/scripts.yml @@ -52,7 +52,7 @@ -DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR} - ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi - - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_exportbuild_pkgconfig + - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_pkgconfig dependencies: [] .build_and_test_template: @@ -124,7 +124,7 @@ - if [ -n "${SYCL_DEVICE_TYPE}" ]; then unset SYCL_DEVICE_TYPE; fi - if [ -n "${SYCL_DEVICE_FILTER}" ]; then unset SYCL_DEVICE_FILTER; fi - if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi - - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_exportbuild_pkgconfig + - LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ninja test_pkgconfig dependencies: [] diff --git a/CMakeLists.txt b/CMakeLists.txt index c5ed5c14046..2d87a9de3cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -370,14 +370,14 @@ set(GINKGO_TEST_INSTALL_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_install/") set(GINKGO_TEST_INSTALL_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_install/") set(GINKGO_TEST_EXPORTBUILD_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_exportbuild/") set(GINKGO_TEST_EXPORTBUILD_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_exportbuild/") -set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_exportbuild_pkgconfig/") -set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_exportbuild_pkgconfig/") +set(GINKGO_TEST_PKGCONFIG_SRC_DIR "${Ginkgo_SOURCE_DIR}/test/test_pkgconfig/") +set(GINKGO_TEST_PKGCONFIG_BIN_DIR "${Ginkgo_BINARY_DIR}/test/test_pkgconfig/") get_property(GINKGO_USE_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) # GINKGO_CONFIG_PREFIX contains / in the end. set(GINKGO_CONFIG_PREFIX "$<$:$/>") set(GINKGO_TEST_INSTALL_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_install) set(GINKGO_TEST_EXPORTBUILD_CMD ${GINKGO_TEST_EXPORTBUILD_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_exportbuild) -set(GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_exportbuild_pkgconfig) +set(GINKGO_TEST_PKGCONFIG_CMD ${GINKGO_TEST_PKGCONFIG_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_pkgconfig) if(GINKGO_BUILD_CUDA) set(GINKGO_TEST_INSTALL_CUDA_CMD ${GINKGO_TEST_INSTALL_BIN_DIR}/${GINKGO_CONFIG_PREFIX}test_install_cuda) endif() @@ -432,10 +432,10 @@ add_custom_target(test_exportbuild COMMENT "Running a test on Ginkgo's exported build directory. " "This requires compiling Ginkgo with `-DGINKGO_EXPORT_BUILD_DIR=ON` first.") -add_custom_target(test_exportbuild_pkgconfig +add_custom_target(test_pkgconfig COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${TOOLSET} - -H${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_SRC_DIR} - -B${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR} + -H${GINKGO_TEST_PKGCONFIG_SRC_DIR} + -B${GINKGO_TEST_PKGCONFIG_BIN_DIR} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER} @@ -444,9 +444,9 @@ add_custom_target(test_exportbuild_pkgconfig # `$` is always be the same as `CMAKE_BUILD_TYPE` in # single-configuration generator. COMMAND ${CMAKE_COMMAND} - --build ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_BIN_DIR} + --build ${GINKGO_TEST_PKGCONFIG_BIN_DIR} --config $ - COMMAND ${GINKGO_TEST_EXPORTBUILD_PKGCONFIG_CMD} + COMMAND ${GINKGO_TEST_PKGCONFIG_CMD} COMMENT "Running a test on Ginkgo's PkgConfig" "This requires installing Ginkgo first") diff --git a/test/test_exportbuild_pkgconfig/CMakeLists.txt b/test/test_pkgconfig/CMakeLists.txt similarity index 74% rename from test/test_exportbuild_pkgconfig/CMakeLists.txt rename to test/test_pkgconfig/CMakeLists.txt index 6d1c5d534f8..883ad134f05 100644 --- a/test/test_exportbuild_pkgconfig/CMakeLists.txt +++ b/test/test_pkgconfig/CMakeLists.txt @@ -7,10 +7,10 @@ pkg_check_modules(GINKGO REQUIRED IMPORTED_TARGET ginkgo) # Here, we use test install without any data. We instantiate the # interface only. -add_executable(test_exportbuild_pkgconfig ../test_install/test_install.cpp) -target_compile_features(test_exportbuild_pkgconfig PUBLIC cxx_std_14) +add_executable(test_pkgconfig ../test_install/test_install.cpp) +target_compile_features(test_pkgconfig PUBLIC cxx_std_14) # CMake PkgConfig only puts the -l, -L, and -framework into link_libraries and others into link_options # When linking the target, the linking option will be before the compiled object to lead the linking error set_property(TARGET PkgConfig::GINKGO PROPERTY INTERFACE_LINK_LIBRARIES "${GINKGO_LDFLAGS}") set_property(TARGET PkgConfig::GINKGO PROPERTY INTERFACE_LINK_OPTIONS "") -target_link_libraries(test_exportbuild_pkgconfig PRIVATE PkgConfig::GINKGO) +target_link_libraries(test_pkgconfig PRIVATE PkgConfig::GINKGO) From 6c3a249943ed0744b37e9ff8f5fa9e2d0d8980c8 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Sat, 5 Nov 2022 02:48:04 +0800 Subject: [PATCH 09/10] hip uses $LINK_ONLY --- cmake/information_helpers.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/information_helpers.cmake b/cmake/information_helpers.cmake index 781f7ecd27c..ef6c0ecbd74 100644 --- a/cmake/information_helpers.cmake +++ b/cmake/information_helpers.cmake @@ -62,6 +62,8 @@ macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) # Keep recursing through the libraries get_target_property(GINKGO_LIBS_INTERFACE_LIBS "${_libs}" INTERFACE_LINK_LIBRARIES) + # removing $ + list(TRANSFORM GINKGO_LIBS_INTERFACE_LIBS REPLACE "\\$" "\\1") ginkgo_interface_libraries_recursively("${GINKGO_LIBS_INTERFACE_LIBS}") elseif(EXISTS "${_libs}") if ("${_libs}" MATCHES "${PROJECT_BINARY_DIR}.*hwloc.so") From 2c9e4ac4a89c563ad1223c031caae11aa7c859f7 Mon Sep 17 00:00:00 2001 From: "Yuhsiang M. Tsai" Date: Sat, 5 Nov 2022 12:54:44 +0800 Subject: [PATCH 10/10] get imported location from hip --- cmake/information_helpers.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmake/information_helpers.cmake b/cmake/information_helpers.cmake index ef6c0ecbd74..4507dea23d4 100644 --- a/cmake/information_helpers.cmake +++ b/cmake/information_helpers.cmake @@ -35,6 +35,16 @@ macro(ginkgo_interface_libraries_recursively INTERFACE_LIBS) filter_generator_expressions("${GINKGO_INTERFACE_LIBS_LINK_FLAGS}" GINKGO_INTERFACE_LIB_NAME) endif() + # Get the imported library + get_target_property(_libs_type "${_libs}" TYPE) + get_target_property(_libs_imported "${_libs}" IMPORTED) + if (_libs_imported AND NOT ${_libs_type} STREQUAL "INTERFACE_LIBRARY") + # only get the value from release for HIP related target + get_target_property(GINKGO_LIBS_IMPORTED_LIBS "${_libs}" IMPORTED_LOCATION_RELEASE) + if (GINKGO_LIBS_IMPORTED_LIBS) + list(APPEND GINKGO_INTERFACE_LIBS_FOUND "${GINKGO_LIBS_IMPORTED_LIBS}") + endif() + endif() # Populate the include directories get_target_property(GINKGO_LIBS_INTERFACE_INCS "${_libs}" INTERFACE_INCLUDE_DIRECTORIES) @@ -88,7 +98,6 @@ macro(ginkgo_interface_information) # Call the recursive interface libraries macro get_target_property(GINKGO_INTERFACE_LINK_LIBRARIES ginkgo INTERFACE_LINK_LIBRARIES) ginkgo_interface_libraries_recursively("${GINKGO_INTERFACE_LINK_LIBRARIES}") - # Format and store the interface libraries found # remove duplicates on the reversed list to keep the dependecy in the end of list. list(REVERSE GINKGO_INTERFACE_LIBS_FOUND)