Skip to content

Commit

Permalink
fix windows build and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RSchwan committed May 29, 2024
1 parent de6ba77 commit 4bcb9e2
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 21 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,20 @@ jobs:
shell: bash -l {0}
if: runner.os == 'Windows'
working-directory: build
run: cmake --build .
run: cmake --build . --config $CMAKE_BUILD_TYPE

- name: Build piqp
shell: bash -l {0}
if: runner.os != 'Windows'
working-directory: build
run: cmake --build . -- -j2
run: cmake --build . --config $CMAKE_BUILD_TYPE -- -j2

- name: Test piqp
shell: bash -l {0}
working-directory: build
run: ctest --test-dir tests --verbose
run: ctest -C $CMAKE_BUILD_TYPE --test-dir tests --verbose

- name: Test piqp c interface
shell: bash -l {0}
working-directory: build
run: ctest -C $CMAKE_BUILD_TYPE --test-dir interfaces/c/tests --verbose
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

project(piqp
VERSION 0.3.1
Expand Down Expand Up @@ -184,6 +184,15 @@ endif ()
add_library(piqp::piqp ALIAS piqp)
add_library(piqp::piqp_header_only ALIAS piqp_header_only)

macro(fix_test_dll target)
if (WIN32)
add_custom_command(
TARGET ${target} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_RUNTIME_DLLS:${target}> $<TARGET_FILE_DIR:${target}>
)
endif ()
endmacro()

if (BUILD_C_INTERFACE)
add_subdirectory(interfaces/c)
endif()
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down
20 changes: 12 additions & 8 deletions docs/interfaces/c_cpp/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ cd piqp
mkdir build
cd build
cmake .. -DCMAKE_CXX_FLAGS="-march=native" -DBUILD_TESTS=OFF -DBUILD_BENCHMARKS=OFF
cmake --build .
cmake --build . --config Release
```
Note that by setting `-march=native`, we allow the compiler to optimize for the full available instruction set on the machine compiling the code.
* Install libraries and header files (requires CMake 3.15+)
```shell
cmake --install .
cmake --install . --config Release
```
This will install the C++ and C headers and the static and shared library for the C interface.
This will install the C++ and C headers and shared libraries.

{: .note }
If you want to build static libraries instead, you can pass `-DBUILD_SHARED_LIBS=OFF` when configuring cmake.

## Using PIQP in CMake Projects

Expand All @@ -42,11 +45,12 @@ find_package(piqp REQUIRED)
# PIQP requires at least C++14
set(CMAKE_CXX_STANDARD 14)
# Link the PIQP C++ header-only library
# Link the PIQP C++ library with precompiled template instantiations
target_link_libraries(yourTarget PRIVATE piqp::piqp)
# Link the PIQP C shared library
target_link_libraries(yourTarget PRIVATE piqp::piqp_c_shared)
# or link the PIQP C static library
target_link_libraries(yourTarget PRIVATE piqp::piqp_c_static)
# Link the PIQP C++ header-only library
target_link_libraries(yourTarget PRIVATE piqp::piqp_header_only)
# Link the PIQP C library
target_link_libraries(yourTarget PRIVATE piqp::piqp_c)
```
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

project(piqp_examples)

Expand Down
2 changes: 1 addition & 1 deletion examples/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

add_executable(c_dense_example c_dense_example.c)
target_link_libraries(c_dense_example PRIVATE piqp::piqp_c)
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

add_executable(cpp_dense_example cpp_dense_example.cpp)
target_link_libraries(cpp_dense_example PRIVATE piqp::piqp)
Expand Down
2 changes: 1 addition & 1 deletion interfaces/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

add_library(piqp_c src/piqp.cpp include/piqp.h)
target_include_directories(piqp_c PUBLIC
Expand Down
4 changes: 3 additions & 1 deletion interfaces/c/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down Expand Up @@ -37,5 +37,7 @@ target_link_libraries(pipq-c-interface-test INTERFACE piqp_c gtest_main gtest)
add_executable(c_interface_test src/c_interface_test.cpp)
target_link_libraries(c_interface_test PRIVATE pipq-c-interface-test)

fix_test_dll(c_interface_test)

include(GoogleTest)
gtest_discover_tests(c_interface_test)
2 changes: 1 addition & 1 deletion interfaces/matlab/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

find_package(Matlab)

Expand Down
2 changes: 1 addition & 1 deletion interfaces/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down
16 changes: 15 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.

cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.21)

# Avoid warning about DOWNLOAD_EXTRACT_TIMESTAMP in CMake 3.24:
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
Expand Down Expand Up @@ -76,6 +76,20 @@ if (BUILD_MAROS_MESZAROS_TEST)
target_link_libraries(sparse_maros_meszaros_tests PRIVATE pipq-test Matio::Matio)
endif()

fix_test_dll(dense_ldlt_test)
fix_test_dll(dense_kkt_test)
fix_test_dll(dense_solver_test)
fix_test_dll(sparse_kkt_test)
fix_test_dll(sparse_ldlt_test)
fix_test_dll(sparse_utils_test)
fix_test_dll(sparse_solver_test)
fix_test_dll(preconditioner_test)
fix_test_dll(io_utils_test)
if (BUILD_MAROS_MESZAROS_TEST)
fix_test_dll(dense_maros_meszaros_tests)
fix_test_dll(sparse_maros_meszaros_tests)
endif()

include(GoogleTest)
gtest_discover_tests(dense_ldlt_test)
gtest_discover_tests(dense_kkt_test)
Expand Down

0 comments on commit 4bcb9e2

Please sign in to comment.