diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9969d84177c..668bbe9c0d6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c2016d90bf..b1144e771e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,11 +290,13 @@ ginkgo_install() if(MSVC) # Set path/command with $ 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() 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() @@ -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. + # `$` is always be the same as `CMAKE_BUILD_TYPE` in + # single-configuration generator. + COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_exportbuild --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") diff --git a/cmake/install_helpers.cmake b/cmake/install_helpers.cmake index ba7ea3fd468..68a75a5f9a5 100644 --- a/cmake/install_helpers.cmake +++ b/cmake/install_helpers.cmake @@ -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" diff --git a/test_exportbuild/CMakeLists.txt b/test_exportbuild/CMakeLists.txt new file mode 100644 index 00000000000..8cfb100263e --- /dev/null +++ b/test_exportbuild/CMakeLists.txt @@ -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() diff --git a/test_install/CMakeLists.txt b/test_install/CMakeLists.txt index 49dc0ba2bf8..53a588f3359 100644 --- a/test_install/CMakeLists.txt +++ b/test_install/CMakeLists.txt @@ -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;