Skip to content

Commit

Permalink
Merge pull request #146 from thbeu/fix-ctest-for-shared-libs
Browse files Browse the repository at this point in the history
CMake ≥ 3.21: Fix ctest paths for shared libs (MSVC and CygWin)
  • Loading branch information
rouault authored Aug 13, 2024
2 parents 26ccd69 + f3fac66 commit 1441087
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -52,8 +52,7 @@ jobs:
toolchain:
- linux-gcc
- macos-clang
- windows-msvc-shared
- windows-msvc-static
- windows-msvc

configuration:
- Release
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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: |
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -250,6 +250,13 @@ if(BUILD_TESTING)
foreach(executable shptest shputils)
add_executable(${executable} ${executable}.c)
target_link_libraries(${executable} PRIVATE ${PACKAGE})
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 $<TARGET_RUNTIME_DLLS:${executable}> $<TARGET_FILE_DIR:${executable}>
COMMAND_EXPAND_LISTS
)
endif()
endforeach()

# Set environment variables defining path to executables being used
Expand Down
7 changes: 7 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 (${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 $<TARGET_RUNTIME_DLLS:${executable}> $<TARGET_FILE_DIR:${executable}>
COMMAND_EXPAND_LISTS
)
endif()
endforeach()

configure_file(
Expand Down

0 comments on commit 1441087

Please sign in to comment.