Skip to content

CMake ≥ 3.21: Fix ctest paths for shared libs (MSVC and CygWin) #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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