Skip to content

Commit

Permalink
Fix GinkgoConfig.cmake. Test linking build dir.
Browse files Browse the repository at this point in the history
Issue found by: #680
  • Loading branch information
tcojean committed Aug 20, 2021
1 parent f15b8b3 commit 2e6b38f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ stages:
CONFIG_LOG: "ON"
CXX_FLAGS: ""
EXTRA_CMAKE_FLAGS: ""
EXPORT_BUILD_DIR: "OFF"
CI_PROJECT_DIR_SUFFIX: ""

.before_script_template: &default_before_script
Expand Down Expand Up @@ -65,8 +66,10 @@ stages:
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_EXAMPLES=ON
-DGINKGO_RUN_EXAMPLES=${RUN_EXAMPLES}
-DGINKGO_CONFIG_LOG_DETAILED=${CONFIG_LOG}
-DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR}
- ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT}
- if [ ! -z ${SYCL_DEVICE_TYPE+x} ]; then unset SYCL_DEVICE_TYPE; fi
- if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi
dependencies: []
except:
- schedules
Expand Down Expand Up @@ -94,6 +97,7 @@ stages:
-DGINKGO_BUILD_TESTS=ON -DGINKGO_BUILD_EXAMPLES=ON
-DGINKGO_CONFIG_LOG_DETAILED=${CONFIG_LOG}
-DGINKGO_RUN_EXAMPLES=${RUN_EXAMPLES}
-DGINKGO_EXPORT_BUILD_DIR=${EXPORT_BUILD_DIR}
- ninja -j${NUM_CORES} -l${CI_LOAD_LIMIT} install
- |
(( $(ctest -N | tail -1 | sed 's/Total Tests: //') != 0 )) || exit 1
Expand Down Expand Up @@ -121,6 +125,7 @@ stages:
fi
fi
- if [ ! -z ${SYCL_DEVICE_TYPE+x} ]; then unset SYCL_DEVICE_TYPE; fi
- if [ "${EXPORT_BUILD_DIR}" == "ON" ]; then ninja test_exportbuild; fi
dependencies: []
except:
- schedules
Expand Down Expand Up @@ -742,6 +747,28 @@ subdir-build:
- cuda
- gpu

# Ensure Ginkgo can be used when exporting the build directory
export-build:
<<: *default_build
stage: code_quality
image: localhost:5000/gko-cuda102-gnu8-llvm8-intel2019
variables:
<<: *default_variables
BUILD_OMP: "ON"
BUILD_CUDA: "ON"
BUILD_HIP: "ON"
EXPORT_BUILD_DIR: "ON"
only:
variables:
- $RUN_CI_TAG
dependencies: []
allow_failure: no
tags:
- private_ci
- cuda
- gpu


# Run clang-tidy and iwyu
clang-tidy:
<<: *default_build
Expand Down
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,13 @@ ginkgo_install()
if(MSVC)
# Set path/command with $<CONFIG>
set(GINKGO_TEST_INSTALL_COMMAND "${Ginkgo_BINARY_DIR}/test_install/$<CONFIG>/test_install")
set(GINKGO_TEST_EXPORTBUILD_COMMAND "${Ginkgo_BINARY_DIR}/test_exportbuild/$<CONFIG>/test_exportbuild")
if(GINKGO_BUILD_CUDA)
set(GINKGO_TEST_INSTALL_COMMAND "${GINKGO_TEST_INSTALL_COMMAND}" "${Ginkgo_BINARY_DIR}/test_install/$<CONFIG>/test_install_cuda")
endif()
else()
set(GINKGO_TEST_INSTALL_COMMAND "${Ginkgo_BINARY_DIR}/test_install/test_install")
set(GINKGO_TEST_EXPORTBUILD_COMMAND "${Ginkgo_BINARY_DIR}/test_exportbuild/test_exportbuild")
if(GINKGO_BUILD_CUDA)
set(GINKGO_TEST_INSTALL_COMMAND "${GINKGO_TEST_INSTALL_COMMAND}" "${Ginkgo_BINARY_DIR}/test_install/test_install_cuda")
endif()
Expand All @@ -312,6 +314,20 @@ add_custom_target(test_install
COMMAND ${GINKGO_TEST_INSTALL_COMMAND}
COMMENT "Running a test on the installed binaries. This requires running `(sudo) make install` first.")

add_custom_target(test_exportbuild
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -H${Ginkgo_SOURCE_DIR}/test_exportbuild
-B${Ginkgo_BINARY_DIR}/test_exportbuild
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
-DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER}
# `--config cfg` is ignored by single-configuration generator.
# `$<CONFIG>` is always be the same as `CMAKE_BUILD_TYPE` in
# single-configuration generator.
COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_exportbuild --config $<CONFIG>
COMMAND ${GINKGO_TEST_EXPORTBUILD_COMMAND}
COMMENT "Running a test on Ginkgo's exported build directory. "
"This requires compiling Ginkgo with `-DGINKGO_EXPORT_BUILD_DIR=ON` first.")


# Setup CPack
set(CPACK_PACKAGE_DESCRIPTION_FILE "${Ginkgo_SOURCE_DIR}/README.md")
set(CPACK_RESOURCE_FILE_LICENSE "${Ginkgo_SOURCE_DIR}/LICENSE")
Expand Down
5 changes: 5 additions & 0 deletions cmake/install_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ function(ginkgo_install)
"${Ginkgo_BINARY_DIR}/GinkgoConfig.cmake"
INSTALL_DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
)
set(HELPERS "hip_helpers.cmake" "windows_helpers.cmake")
foreach (helper ${HELPERS})
configure_file(${Ginkgo_SOURCE_DIR}/cmake/${helper}
${Ginkgo_BINARY_DIR}/${helper} COPYONLY)
endforeach()
install(FILES
"${Ginkgo_BINARY_DIR}/GinkgoConfig.cmake"
"${Ginkgo_BINARY_DIR}/GinkgoConfigVersion.cmake"
Expand Down
33 changes: 33 additions & 0 deletions test_exportbuild/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.9)
project(GinkgoExportBuildTest LANGUAGES CXX)

find_package(Ginkgo REQUIRED)

if(MSVC)
if(GINKGO_BUILD_SHARED_LIBS)
ginkgo_switch_to_windows_dynamic("CXX")
ginkgo_switch_to_windows_dynamic("C")
else()
ginkgo_switch_to_windows_static("CXX")
ginkgo_switch_to_windows_static("C")
endif()
endif()

add_executable(test_exportbuild ../test_install/test_install.cpp)
target_compile_features(test_exportbuild PUBLIC cxx_std_14)
target_link_libraries(test_exportbuild PRIVATE Ginkgo::ginkgo)

if(GINKGO_BUILD_HIP AND GINKGO_HIP_PLATFORM MATCHES "hcc"
AND GINKGO_HIP_VERSION VERSION_GREATER_EQUAL "3.5"
AND NOT GINKGO_BUILD_SHARED_LIBS)
# Compile options somehow add hip-clang specific flags. Wipe them.
# Currently, the flags wiped out should be:
# -x;hip;--hip-device-lib-path=/opt/rocm/lib;--cuda-gpu-arch=gfx900;
# --cuda-gpu-arch=gfx906
set_target_properties(hip::device PROPERTIES INTERFACE_COMPILE_OPTIONS "")
# In addition, link libraries have a similar problem. We only keep
# `hip::host`. Currently, the flags should be:
# hip::host;--hip-device-lib-path=/opt/rocm/lib;--hip-link;
# --cuda-gpu-arch=gfx900;--cuda-gpu-arch=gfx906
set_target_properties(hip::device PROPERTIES INTERFACE_LINK_LIBRARIES "hip::host")
endif()
7 changes: 3 additions & 4 deletions test_install/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ if(GINKGO_BUILD_CUDA)
target_link_libraries(test_install_cuda PRIVATE Ginkgo::ginkgo)
endif()

if(GINKGO_BUILD_HIP
AND GINKGO_HIP_PLATFORM MATCHES "hcc"
AND GINKGO_HIP_VERSION VERSION_GREATER_EQUAL "3.5"
AND NOT GINKGO_BUILD_SHARED_LIBS)
if(GINKGO_BUILD_HIP AND GINKGO_HIP_PLATFORM MATCHES "hcc"
AND GINKGO_HIP_VERSION VERSION_GREATER_EQUAL "3.5"
AND NOT GINKGO_BUILD_SHARED_LIBS)
# Compile options somehow add hip-clang specific flags. Wipe them.
# Currently, the flags wiped out should be:
# -x;hip;--hip-device-lib-path=/opt/rocm/lib;--cuda-gpu-arch=gfx900;
Expand Down

0 comments on commit 2e6b38f

Please sign in to comment.