From ba94d262025c97f8a9ea5faa154356f71299693a Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Mon, 12 Aug 2024 21:01:01 +0200 Subject: [PATCH 1/2] Fix ctest for shared libs --- .github/workflows/main.yml | 23 +++++++---------------- CMakeLists.txt | 9 ++++++++- tests/CMakeLists.txt | 7 +++++++ 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a733805..7790fc8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,7 +41,7 @@ jobs: cd shapelib-* cmake . cmake --build . -j$(nproc) - ctest --test-dir . --verbose + ctest --no-tests=error --test-dir . --verbose build-cmake: name: ${{ matrix.toolchain }} @@ -52,8 +52,7 @@ jobs: toolchain: - linux-gcc - macos-clang - - windows-msvc-shared - - windows-msvc-static + - windows-msvc configuration: - Release @@ -67,11 +66,7 @@ jobs: os: macos-latest compiler: clang - - toolchain: windows-msvc-shared - os: windows-latest - compiler: msvc - - - toolchain: windows-msvc-static + - toolchain: windows-msvc os: windows-latest compiler: msvc @@ -81,10 +76,8 @@ jobs: - name: Configure (${{ matrix.configuration }}) run: | - if [ "${{ matrix.toolchain }}" == "windows-msvc-shared" ]; then - cmake -S . -Bbuild -DCMAKE_UNITY_BUILD=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_TESTING=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=~/install - elif [ "${{ matrix.toolchain }}" == "windows-msvc-static" ]; then - cmake -S . -Bbuild -DCMAKE_UNITY_BUILD=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_TESTING=ON -DBASH_EXECUTABLE="C:/Program Files/Git/bin/bash.exe" -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=~/install + if [ "${{ matrix.toolchain }}" == "windows-msvc" ]; then + cmake -S . -Bbuild -DCMAKE_UNITY_BUILD=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_TESTING=ON -DCMAKE_INSTALL_PREFIX=~/install else cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DCMAKE_UNITY_BUILD=ON -DCMAKE_COMPILE_WARNING_AS_ERROR=ON -DBUILD_TESTING=ON -DCMAKE_INSTALL_PREFIX=~/install fi @@ -98,7 +91,7 @@ jobs: fi - name: Test - run: ctest --test-dir build --build-config ${{ matrix.configuration }} --verbose + run: ctest --no-tests=error --test-dir build --build-config ${{ matrix.configuration }} --verbose - name: Install run: | @@ -143,9 +136,7 @@ jobs: - name: Test run: | export PATH=/usr/bin:/usr/local/bin:$PATH - cp ./build/*.dll ./build/tests/ - cp ./build/bin/*.dll ./build/tests/ - ctest --test-dir build --build-config Release --verbose + ctest --no-tests=error --test-dir build --build-config Release --verbose shell: C:\cygwin\bin\bash.exe -eo pipefail -o igncr '{0}' build-nmake: diff --git a/CMakeLists.txt b/CMakeLists.txt index ed99f16..3a8f6af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ endif() # In windows all created dlls are gathered in the dll directory # if you add this directory to your PATH all shared libraries are available -if(BUILD_SHARED_LIBS AND WIN32 AND NOT CYGWIN) +if(BUILD_SHARED_LIBS AND (WIN32 OR CYGWIN)) set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/dll) endif() @@ -250,6 +250,13 @@ if(BUILD_TESTING) foreach(executable shptest shputils) add_executable(${executable} ${executable}.c) target_link_libraries(${executable} PRIVATE ${PACKAGE}) + if (WIN32 OR CYGWIN) + add_custom_command( + TARGET ${executable} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ + COMMAND_EXPAND_LISTS + ) + endif() endforeach() # Set environment variables defining path to executables being used diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0ee9add..34e3ee8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,6 +32,13 @@ foreach(executable dbf_test sbn_test shp_test) ) target_compile_features(${executable} PUBLIC cxx_std_17) set_target_properties(${executable} PROPERTIES FOLDER "tests" CXX_EXTENSIONS OFF) + if (WIN32 OR CYGWIN) + add_custom_command( + TARGET ${executable} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ + COMMAND_EXPAND_LISTS + ) + endif() endforeach() configure_file( From f3fac66085b8c2fdfd37c40ade98120352153253 Mon Sep 17 00:00:00 2001 From: Thomas Beutlich Date: Mon, 12 Aug 2024 22:00:10 +0200 Subject: [PATCH 2/2] Check for CMake version --- CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a8f6af..dc5df86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -250,7 +250,7 @@ if(BUILD_TESTING) foreach(executable shptest shputils) add_executable(${executable} ${executable}.c) target_link_libraries(${executable} PRIVATE ${PACKAGE}) - if (WIN32 OR CYGWIN) + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21" AND (WIN32 OR CYGWIN)) add_custom_command( TARGET ${executable} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 34e3ee8..5fc5190 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,7 @@ foreach(executable dbf_test sbn_test shp_test) ) target_compile_features(${executable} PUBLIC cxx_std_17) set_target_properties(${executable} PROPERTIES FOLDER "tests" CXX_EXTENSIONS OFF) - if (WIN32 OR CYGWIN) + if (${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.21" AND (WIN32 OR CYGWIN)) add_custom_command( TARGET ${executable} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $