Skip to content

Commit

Permalink
escape space for pkg-config and rearrange code
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Nov 1, 2022
1 parent ff4a1e2 commit 8218704
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 120 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions .github/workflows/windows-msvc-ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 0 additions & 2 deletions .gitlab/scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_$<CONFIG>.pc
Expand All @@ -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 "$<$<BOOL:${GINKGO_USE_MULTI_CONFIG}>:$<CONFIG>/>")
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)
Expand Down
2 changes: 1 addition & 1 deletion cmake/ginkgo.pc.in
Original file line number Diff line number Diff line change
@@ -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@

Expand Down
143 changes: 50 additions & 93 deletions cmake/information_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)

Expand Down
16 changes: 1 addition & 15 deletions test/test_exportbuild_pkgconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

0 comments on commit 8218704

Please sign in to comment.