Skip to content

Commit

Permalink
test_install use correct config in MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Mar 17, 2020
1 parent 383131d commit db9bbd1
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 47 deletions.
40 changes: 22 additions & 18 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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::"
Expand All @@ -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
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 $<CONFIG>
set(GINKGO_TEST_INSTALL_COMMAND "${Ginkgo_BINARY_DIR}/test_install/$<CONFIG>/test_install")
if (GINKGO_BUILD_CUDA)
set(GINKGO_TEST_INSTALL_COMMAND "${GINKGO_TEST_INSTALL_COMMAND}" "${Ginkgo_BINARY_DIR}/test_install/$<CONFIG>/test_install_cuda")
endif ()
set(GINKGO_BUILD_TEST_INSTALL_COMMAND COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_install --config $<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.")

Expand Down
1 change: 1 addition & 0 deletions cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 0 additions & 23 deletions cmake/build_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions cmake/install_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions cmake/windows_helpers.cmake
Original file line number Diff line number Diff line change
@@ -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()
15 changes: 15 additions & 0 deletions test_install/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ find_package(Ginkgo REQUIRED
# Alternatively, use `cmake -DCMAKE_PREFIX_PATH=<ginkgo_install_dir>` 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)

Expand Down Expand Up @@ -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()

0 comments on commit db9bbd1

Please sign in to comment.