Skip to content
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

Simplify CMake #169

Merged
merged 5 commits into from
Aug 24, 2022
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
17 changes: 9 additions & 8 deletions .github/workflows/actions_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ jobs:
run: git submodule update --init
- name: Add MSBuild to PATH
uses: microsoft/[email protected]
- name: Build tests
run: msbuild CPP/Tests/VisualStudio/Tests_cpp.sln /p:Configuration=Release /p:Platform=x64
- name: Build
run: |
mkdir CPP/build
cd CPP/build
cmake .. -DCLIPPER2_TESTS=ON -DCLIPPER2_UTILS:BOOL=ON -DCLIPPER2_EXAMPLES:BOOL=ON
cmake --build . --config RelWithDebInfo --parallel
- name: Run tests
run: x64\Release\Tests.exe
working-directory: CPP/Tests/VisualStudio
- name: Build console demo program
run: msbuild CPP/Examples/ConsoleDemo1/ConsoleDemo1_cpp.sln
- name: Build inflate demo application
run: msbuild CPP/Examples/InflateDemo/InflateDemoApp.sln
run: |
cd CPP/build
ctest . -C RelWithDebInfo --output-on-failure
ubuntu-latest-gcc-default:
runs-on: 'ubuntu-latest'
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RandomPolygons.txt
1 change: 1 addition & 0 deletions CPP/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build*
102 changes: 47 additions & 55 deletions CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,39 @@ option(CLIPPER2_UTILS "Build utilities" OFF)
option(CLIPPER2_EXAMPLES "Build examples" OFF)
option(CLIPPER2_TESTS "Build tests" OFF)

add_library(Clipper2 SHARED
Clipper2Lib/clipper.core.h
Clipper2Lib/clipper.engine.cpp
Clipper2Lib/clipper.engine.h
Clipper2Lib/clipper.h
Clipper2Lib/clipper.minkowski.h
Clipper2Lib/clipper.offset.cpp
Clipper2Lib/clipper.offset.h
)
add_library(Clipper2 STATIC
Clipper2Lib/clipper.core.h
Clipper2Lib/clipper.engine.cpp
Clipper2Lib/clipper.engine.h
Clipper2Lib/clipper.h
Clipper2Lib/clipper.minkowski.h
Clipper2Lib/clipper.offset.cpp
Clipper2Lib/clipper.offset.h
)

target_include_directories(Clipper2
PUBLIC Clipper2Lib
SYSTEM INTERFACE Clipper2Lib
)

target_compile_options(Clipper2 PRIVATE -Wall -Wextra -Wpedantic -Werror)
target_link_libraries(Clipper2 PRIVATE -lm)
set_target_properties(Clipper2 PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(Clipper2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY "./lib")
set_target_properties(Clipper2 PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_SOURCE_DIR}/lib")
PUBLIC Clipper2Lib
SYSTEM INTERFACE Clipper2Lib
)

if (WIN32)
target_compile_options(Clipper2 PRIVATE /W4 /WX)
else()
target_compile_options(Clipper2 PRIVATE -Wall -Wextra -Wpedantic -Werror)
target_link_libraries(Clipper2 PUBLIC -lm)
endif()

if(CLIPPER2_UTILS OR CLIPPER2_TESTS OR CLIPPER2_EXAMPLES)
add_library(Clipper2utils SHARED
add_library(Clipper2utils STATIC
Utils/clipper.svg.cpp
Utils/clipper.svg.h
Utils/ClipFileLoad.cpp
Utils/ClipFileLoad.h
Utils/ClipFileSave.cpp
Utils/ClipFileSave.h
)
target_link_libraries(Clipper2utils PRIVATE -lm Clipper2)
set_target_properties(Clipper2utils PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(Clipper2utils PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_SOURCE_DIR}/lib")

target_link_libraries(Clipper2utils PRIVATE Clipper2)
target_include_directories(Clipper2utils
PUBLIC Utils
SYSTEM INTERFACE Utils
Expand All @@ -51,56 +51,48 @@ endif()

if(CLIPPER2_EXAMPLES)
add_executable(ConsoleDemo1 Examples/ConsoleDemo1/ConsoleDemo1.cpp)
target_include_directories(ConsoleDemo1 PRIVATE Clipper2Lib)
target_link_libraries(ConsoleDemo1 PRIVATE -lm Clipper2 Clipper2utils)
set_target_properties(ConsoleDemo1 PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(ConsoleDemo1 PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_SOURCE_DIR}/lib")
target_link_libraries(ConsoleDemo1 PRIVATE Clipper2 Clipper2utils)

install( FILES Examples/InflateDemo/rabbit.svg DESTINATION . )
file(COPY Examples/InflateDemo/rabbit.svg DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ GROUP_READ WORLD_READ )

add_executable(InflateDemo1 Examples/InflateDemo/InflateDemo1.cpp)
target_include_directories(InflateDemo1 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(InflateDemo1 PRIVATE -lm Clipper2 Clipper2utils)
set_target_properties(InflateDemo1 PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(InflateDemo1 PROPERTIES LINK_FLAGS "-Wl,-rpath,${CMAKE_SOURCE_DIR}/lib")
target_link_libraries(InflateDemo1 PRIVATE Clipper2 Clipper2utils)
endif()


if(CLIPPER2_TESTS)
# See: https://cliutils.gitlab.io/modern-cmake/chapters/testing/googletest.html

enable_testing()
if (WIN32)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
include(GoogleTest)

add_subdirectory("${PROJECT_SOURCE_DIR}/Tests/googletest/")

macro(package_add_test TESTNAME FILES )
# create an executable in which the tests will be stored
add_executable(${TESTNAME} ${FILES})
# link the Google test infrastructure, mocking library, and a default main function to
# the test executable. Remove g_test_main if writing your own main function.
target_link_libraries(${TESTNAME} gtest gmock gtest_main Clipper2 Clipper2utils)
# gtest_discover_tests replaces gtest_add_tests,
# see https://cmake.org/cmake/help/v3.10/module/GoogleTest.html for more options to pass to it
gtest_discover_tests(${TESTNAME}
add_executable(ClipperTests
Tests/TestLines.cpp
Tests/TestOffsetOrientation.cpp
Tests/TestOrientation.cpp
Tests/TestPolygons.cpp
Tests/TestPolytreeHoles1.cpp
Tests/TestPolytreeHoles2.cpp
Tests/TestPolytreeIntersection.cpp
Tests/TestPolytreeUnion.cpp
Tests/TestRandomPaths.cpp
Tests/TestTrimCollinear.cpp
)

target_link_libraries(ClipperTests gtest gmock gtest_main Clipper2 Clipper2utils)

gtest_discover_tests(ClipperTests
# set a working directory so your project root so that you can find test data via paths relative to the project root
WORKING_DIRECTORY ${PROJECT_DIR}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/../Tests
PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_DIR}"
)
set_target_properties(${TESTNAME} PROPERTIES FOLDER tests)
endmacro()

package_add_test(test1 Tests/Tests/TestLines.cpp )
package_add_test(test2 Tests/Tests/TestOffsetOrientation.cpp )
package_add_test(test3 Tests/Tests/TestOrientation.cpp )
package_add_test(test4 Tests/Tests/TestPolygons.cpp )
package_add_test(test5 Tests/Tests/TestPolytreeHoles1.cpp )
package_add_test(test6 Tests/Tests/TestPolytreeHoles2.cpp )
package_add_test(test7 Tests/Tests/TestPolytreeIntersection.cpp )
package_add_test(test8 Tests/Tests/TestPolytreeUnion.cpp )
package_add_test(test9 Tests/Tests/TestRandomPaths.cpp )
package_add_test(test10 Tests/Tests/TestTrimCollinear.cpp )

)

install( FILES ../Tests/PolytreeHoleOwner.txt DESTINATION . )
install( FILES ../Tests/PolytreeHoleOwner2.txt DESTINATION . )
install( FILES ../Tests/Lines.txt DESTINATION . )
Expand Down
2 changes: 1 addition & 1 deletion CPP/Clipper2Lib/clipper.core.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct Point {
template <typename T2>
inline void Init(const T2 x_ = 0, const T2 y_ = 0)
{
if (std::numeric_limits<T>::is_integer &&
if constexpr (std::numeric_limits<T>::is_integer &&
!std::numeric_limits<T2>::is_integer)
{
x = static_cast<T>(std::round(x_));
Expand Down
160 changes: 0 additions & 160 deletions CPP/Examples/ConsoleDemo1/ConsoleDemo1.vcxproj

This file was deleted.

31 changes: 0 additions & 31 deletions CPP/Examples/ConsoleDemo1/ConsoleDemo1_cpp.sln

This file was deleted.

Loading