diff --git a/.github/workflows/windows-build.yml b/.github/workflows/windows-build.yml index 259a41e92a7..cd0acc0476d 100644 --- a/.github/workflows/windows-build.yml +++ b/.github/workflows/windows-build.yml @@ -4,7 +4,7 @@ on: [push] jobs: windows_cuda: - name: cuda102/release/shared + name: cuda102/release/shared (only compile) runs-on: [windows-latest] steps: - uses: actions/checkout@v2 @@ -51,22 +51,15 @@ jobs: cmake -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DGINKGO_BUILD_CUDA=OFF -DGINKGO_BUILD_OMP=OFF .. cmake --build . -j8 --config ${{ matrix.config.build_type }} ctest . -C ${{ matrix.config.build_type }} - cmake --install . --config ${{ matrix.config.build_type }} - - name: test_install (allowed failed) - run: | - cd build - cmake --build . --target test_install - continue-on-error: true - name: install_shared_env if: matrix.config.shared == 'ON' run: | echo "::set-env name=PATH::C:\Program Files (x86)\Ginkgo\lib;$env:origin_path" - echo $env:PATH - - name: test_install + - name: install run: | - cd build/test_install - cmake --build . --config ${{ matrix.config.build_type }} - .\${{ matrix.config.build_type }}\test_install.exe + cd build + cmake --install . --config ${{ matrix.config.build_type }} + cmake --build . --target test_install --config ${{ matrix.config.build_type }} windows_mingw: strategy: @@ -82,6 +75,7 @@ jobs: - name: shared_env if: matrix.config.shared == 'ON' run: | + echo "::set-env name=origin_path::$env:PATH" echo "::add-path::$pwd\build\windows_shared_library" - name: debug_env if: matrix.config.build_type == 'Debug' @@ -97,9 +91,20 @@ jobs: cmake -G "MinGW Makefiles" -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} .. cmake --build . -j8 ctest . + shell: cmd + - name: install_shared_env + if: matrix.config.shared == 'ON' + run: | + echo "::set-env name=PATH::C:\Program Files (x86)\Ginkgo\lib;$env:origin_path" + - name: install + run: | + set PATH=%PATH:C:\Program Files\Git\bin;=% + set PATH=%PATH:C:\Program Files\Git\usr\bin;=% + cd build cmake --install . cmake --build . --target test_install shell: cmd + windows_cygwin: strategy: fail-fast: false @@ -117,7 +122,7 @@ jobs: choco install cygwin -y choco install cyg-get -y cyg-get cmake make gcc-g++ git - - name: add_env + - name: shared_static_env run: | echo "::set-env name=shared_ON_path::;$pwd\build\windows_shared_library" echo "::set-env name=shared_OFF_path::" @@ -128,26 +133,25 @@ jobs: - name: configure run: | path C:\tools\cygwin\bin%shared_${{ matrix.config.shared }}_path% - echo %PATH% mkdir build cd build bash -c "cmake -DBUILD_SHARED_LIBS=${{ matrix.config.shared }} -DCMAKE_BUILD_TYPE=${{ matrix.config.build_type }} .." bash -c "make -j8" bash -c "make test" - bash -c "make install" - bash -c "./omp/test/factorization/par_ilu_kernels.exe" shell: cmd - - name: test_install_shared + - name: install_shared if: matrix.config.shared == 'ON' run: | path C:\tools\cygwin\bin cd build + bash -c "make install" bash -c "export PATH=/usr/local/lib:$PATH && make test_install" shell: cmd - - name: test_install_static + - name: install_static if: matrix.config.shared == 'OFF' run: | path C:\tools\cygwin\bin cd build + bash -c "make install" bash -c "make test_install" shell: cmd \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 40f7886333f..383c203b80b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,7 @@ configure_file(${Ginkgo_SOURCE_DIR}/include/ginkgo/config.hpp.in include(cmake/build_helpers.cmake) include(cmake/hip_helpers.cmake) include(cmake/install_helpers.cmake) +include(cmake/windows_helpers.cmake) # This is modified from https://gitlab.kitware.com/cmake/community/wikis/FAQ#dynamic-replace if(MSVC) @@ -231,16 +232,26 @@ configure_file(${Ginkgo_SOURCE_DIR}/cmake/ginkgo.pc.in ginkgo_install() -set(GINKGO_TEST_INSTALL_COMMAND "${Ginkgo_BINARY_DIR}/test_install/test_install") -if (GINKGO_BUILD_CUDA) - set(GINKGO_TEST_INSTALL_COMMAND "${GINKGO_TEST_INSTALL_COMMAND}" && "${Ginkgo_BINARY_DIR}/test_install/test_install_cuda") -endif() +if (MSVC) + # Set path/command with $ + set(GINKGO_TEST_INSTALL_COMMAND "${Ginkgo_BINARY_DIR}/test_install/$/test_install") + if (GINKGO_BUILD_CUDA) + set(GINKGO_TEST_INSTALL_COMMAND "${GINKGO_TEST_INSTALL_COMMAND}" "${Ginkgo_BINARY_DIR}/test_install/$/test_install_cuda") + endif () + set(GINKGO_BUILD_TEST_INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_install --config $) +else () + set(GINKGO_TEST_INSTALL_COMMAND "${Ginkgo_BINARY_DIR}/test_install/test_install") + if (GINKGO_BUILD_CUDA) + set(GINKGO_TEST_INSTALL_COMMAND "${GINKGO_TEST_INSTALL_COMMAND}" "${Ginkgo_BINARY_DIR}/test_install/test_install_cuda") + endif () + set(GINKGO_BUILD_TEST_INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_install) +endif () add_custom_target(test_install COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -H${Ginkgo_SOURCE_DIR}/test_install -B${Ginkgo_BINARY_DIR}/test_install -DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_CONFIG_DIR} - -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} - COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_install + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + COMMAND ${GINKGO_BUILD_TEST_INSTALL_COMMAND} COMMAND ${GINKGO_TEST_INSTALL_COMMAND} COMMENT "Running a test on the installed binaries. This requires running `(sudo) make install` first.") diff --git a/cmake/GinkgoConfig.cmake.in b/cmake/GinkgoConfig.cmake.in index bda841f2731..8f99a6304d2 100644 --- a/cmake/GinkgoConfig.cmake.in +++ b/cmake/GinkgoConfig.cmake.in @@ -130,6 +130,7 @@ set(GINKGO_OPENMP_FLAGS "@OpenMP_CXX_FLAGS@") # Provide useful HIP helper functions include(${CMAKE_CURRENT_LIST_DIR}/hip_helpers.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/windows_helpers.cmake) # NOTE: we do not export benchmarks, examples, tests or devel tools # so `third_party` libraries are currently unneeded. diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index b178d7953eb..7ce55e8ebb3 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -78,26 +78,3 @@ function(ginkgo_check_shared_library name) "Please add ${GINKGO_WINDOWS_SHARED_LIBRARY_PATH} into the environment variable PATH.") endif() endfunction() - -function(ginkgo_switch_windows_link lang from to) - foreach(flag_var - "CMAKE_${lang}_FLAGS" "CMAKE_${lang}_FLAGS_DEBUG" "CMAKE_${lang}_FLAGS_RELEASE" - "CMAKE_${lang}_FLAGS_MINSIZEREL" "CMAKE_${lang}_FLAGS_RELWITHDEBINFO" - ) - if(${flag_var} MATCHES "/${from}") - string(REGEX REPLACE "/${from}" "/${to}" ${flag_var} "${${flag_var}}") - endif(${flag_var} MATCHES "/${from}") - if(${flag_var} MATCHES "-${from}") - string(REGEX REPLACE "-${from}" "-${to}" ${flag_var} "${${flag_var}}") - endif(${flag_var} MATCHES "-${from}") - set(${flag_var} "${${flag_var}}" CACHE STRING "" FORCE) - endforeach() -endfunction() - -macro(ginkgo_switch_to_windows_static lang) - ginkgo_switch_windows_link(${lang} "MD" "MT") -endmacro() - -macro(ginkgo_switch_to_windows_dynamic lang) - ginkgo_switch_windows_link(${lang} "MT" "MD") -endmacro() diff --git a/cmake/install_helpers.cmake b/cmake/install_helpers.cmake index e9a883919bd..ba7ea3fd468 100644 --- a/cmake/install_helpers.cmake +++ b/cmake/install_helpers.cmake @@ -71,6 +71,7 @@ function(ginkgo_install) "${Ginkgo_BINARY_DIR}/GinkgoConfig.cmake" "${Ginkgo_BINARY_DIR}/GinkgoConfigVersion.cmake" "${Ginkgo_SOURCE_DIR}/cmake/hip_helpers.cmake" + "${Ginkgo_SOURCE_DIR}/cmake/windows_helpers.cmake" DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}" ) install(EXPORT Ginkgo diff --git a/cmake/windows_helpers.cmake b/cmake/windows_helpers.cmake new file mode 100644 index 00000000000..5f517a555ad --- /dev/null +++ b/cmake/windows_helpers.cmake @@ -0,0 +1,22 @@ +function(ginkgo_switch_windows_link lang from to) + foreach(flag_var + "CMAKE_${lang}_FLAGS" "CMAKE_${lang}_FLAGS_DEBUG" "CMAKE_${lang}_FLAGS_RELEASE" + "CMAKE_${lang}_FLAGS_MINSIZEREL" "CMAKE_${lang}_FLAGS_RELWITHDEBINFO" + ) + if(${flag_var} MATCHES "/${from}") + string(REGEX REPLACE "/${from}" "/${to}" ${flag_var} "${${flag_var}}") + endif(${flag_var} MATCHES "/${from}") + if(${flag_var} MATCHES "-${from}") + string(REGEX REPLACE "-${from}" "-${to}" ${flag_var} "${${flag_var}}") + endif(${flag_var} MATCHES "-${from}") + set(${flag_var} "${${flag_var}}" CACHE STRING "" FORCE) + endforeach() +endfunction() + +macro(ginkgo_switch_to_windows_static lang) + ginkgo_switch_windows_link(${lang} "MD" "MT") +endmacro() + +macro(ginkgo_switch_to_windows_dynamic lang) + ginkgo_switch_windows_link(${lang} "MT" "MD") +endmacro() diff --git a/test_install/CMakeLists.txt b/test_install/CMakeLists.txt index e681ad9f13e..3da6bc9acba 100644 --- a/test_install/CMakeLists.txt +++ b/test_install/CMakeLists.txt @@ -7,6 +7,16 @@ find_package(Ginkgo REQUIRED # Alternatively, use `cmake -DCMAKE_PREFIX_PATH=` to specify the install directory ) +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() + include(CheckLanguage) check_language(CUDA) @@ -40,6 +50,11 @@ target_link_libraries(test_install PRIVATE Ginkgo::ginkgo) if(GINKGO_BUILD_CUDA) enable_language(CUDA) + if(GINKGO_BUILD_SHARED_LIBS) + ginkgo_switch_to_windows_dynamic("CUDA") + else() + ginkgo_switch_to_windows_static("CUDA") + endif() add_executable(test_install_cuda test_install_cuda.cu) target_link_libraries(test_install_cuda PRIVATE Ginkgo::ginkgo) endif()