Skip to content

Commit

Permalink
Shared library fix (#247)
Browse files Browse the repository at this point in the history
* Fixes for #243 as per discussion

* Move files as per #243 discussion

* Fix include paths in Examples

* * Replace relative include paths in examples
* Disable unused-(function|result) warning for gcc targets
* Fix some indentation in CMakeLists.txt

* - Add pkgconfig
- Fix test in CMakeLists.txt for actual gcc use
  • Loading branch information
sergey-239 authored Oct 1, 2022
1 parent c9de2eb commit acfeee6
Show file tree
Hide file tree
Showing 28 changed files with 68 additions and 45 deletions.
53 changes: 32 additions & 21 deletions CPP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,34 @@ option(BUILD_SHARED_LIBS "Build shared libs" OFF)
include(GNUInstallDirs)

set(CLIPPER2_INC
Clipper2Lib/clipper.core.h
Clipper2Lib/clipper.engine.h
Clipper2Lib/clipper.h
Clipper2Lib/clipper.minkowski.h
Clipper2Lib/clipper.offset.h
Clipper2Lib/include/clipper2/clipper.core.h
Clipper2Lib/include/clipper2/clipper.engine.h
Clipper2Lib/include/clipper2/clipper.h
Clipper2Lib/include/clipper2/clipper.minkowski.h
Clipper2Lib/include/clipper2/clipper.offset.h
)

set(CLIPPER2_SRC
Clipper2Lib/clipper.engine.cpp
Clipper2Lib/clipper.offset.cpp
Clipper2Lib/src/clipper.engine.cpp
Clipper2Lib/src/clipper.offset.cpp
)

set(PCFILE "${CMAKE_CURRENT_BINARY_DIR}/Clipper2.pc")

# 2d version of Clipper2
add_library(Clipper2 ${CLIPPER2_SRC})
add_library(Clipper2 ${CLIPPER2_INC} ${CLIPPER2_SRC})

target_include_directories(Clipper2
PUBLIC Clipper2Lib
PUBLIC Clipper2Lib/include
)

# Clipper2 but with USINGZ defined
add_library(Clipper2Z ${CLIPPER2_SRC})
add_library(Clipper2Z ${CLIPPER2_INC} ${CLIPPER2_SRC})

target_compile_definitions(Clipper2Z PUBLIC USINGZ)

target_include_directories(Clipper2Z
PUBLIC Clipper2Lib
PUBLIC Clipper2Lib/include
)

if (WIN32)
Expand Down Expand Up @@ -72,25 +74,25 @@ if(CLIPPER2_UTILS OR CLIPPER2_TESTS OR CLIPPER2_EXAMPLES)
Utils/ClipFileSave.cpp
)

add_library(Clipper2utils STATIC ${CLIPPER2_UTILS_SRC})
add_library(Clipper2utils STATIC ${CLIPPER2_UTILS_INC} ${CLIPPER2_UTILS_SRC})

target_link_libraries(Clipper2utils PUBLIC Clipper2)
target_include_directories(Clipper2utils
PUBLIC Utils
)

add_library(Clipper2Zutils STATIC ${CLIPPER2_UTILS_SRC})
add_library(Clipper2Zutils STATIC ${CLIPPER2_UTILS_INC} ${CLIPPER2_UTILS_SRC})

target_link_libraries(Clipper2Zutils PUBLIC Clipper2Z)
target_include_directories(Clipper2Zutils
PUBLIC Utils
)

set_target_properties(Clipper2utils Clipper2Zutils PROPERTIES FOLDER Libraries)
if (NOT WIN32)
target_compile_options(Clipper2utils PRIVATE -Wno-unused-variable -Wno-unused-function)
target_compile_options(Clipper2Zutils PRIVATE -Wno-unused-variable -Wno-unused-function)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(Clipper2utils PRIVATE -Wno-unused-variable -Wno-unused-function)
target_compile_options(Clipper2Zutils PRIVATE -Wno-unused-variable -Wno-unused-function)
endif()
endif()

if(CLIPPER2_EXAMPLES)
Expand All @@ -112,6 +114,12 @@ if(CLIPPER2_EXAMPLES)
target_link_libraries(UsingZ1 PRIVATE Clipper2Z Clipper2Zutils)

set_target_properties(ConsoleDemo1 ConsoleDemo2 InflateDemo1 UsingZ1 PROPERTIES FOLDER Examples)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(ConsoleDemo1 PRIVATE -Wno-unused-result -Wno-unused-function)
target_compile_options(ConsoleDemo2 PRIVATE -Wno-unused-result -Wno-unused-function)
target_compile_options(InflateDemo1 PRIVATE -Wno-unused-result -Wno-unused-function)
target_compile_options(UsingZ1 PRIVATE -Wno-unused-result -Wno-unused-function)
endif()
endif()


Expand Down Expand Up @@ -146,10 +154,10 @@ if(CLIPPER2_TESTS)
add_executable(ClipperTestsZ ${ClipperTests_SRC})
target_link_libraries(ClipperTestsZ gtest gtest_main Clipper2Z Clipper2Zutils)

if (NOT WIN32)
target_compile_options(ClipperTests PRIVATE -Wno-unused-variable -Wno-unused-function)
target_compile_options(ClipperTestsZ PRIVATE -Wno-unused-variable -Wno-unused-function)
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options(ClipperTests PRIVATE -Wno-unused-variable -Wno-unused-function)
target_compile_options(ClipperTestsZ PRIVATE -Wno-unused-variable -Wno-unused-function)
endif()

set_target_properties(ClipperTests ClipperTestsZ PROPERTIES FOLDER Tests)

Expand All @@ -172,6 +180,9 @@ endif()
file(COPY ../Tests/Polygons.txt DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ GROUP_READ WORLD_READ )
endif()

CONFIGURE_FILE(Clipper2.pc.cmakein "${PCFILE}" @ONLY)

install(TARGETS Clipper2 Clipper2Z
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/clipper2
)
install(FILES ${PCFILE} DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkconfig)
12 changes: 12 additions & 0 deletions CPP/Clipper2.pc.cmakein
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: Clipper2
Description: A Polygon Clipping and Offsetting library in C++
Version: @PROJECT_VERSION@
URL: https://github.com/AngusJohnson/Clipper2
Requires:
Libs: -L${libdir} -lClipper2
Cflags: -I${includedir}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <vector>
#include <numeric>
#include <algorithm>
#include "clipper.engine.h"
#include "clipper2/clipper.engine.h"

namespace Clipper2Lib {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*******************************************************************************/

#include <cmath>
#include "clipper.h"
#include "clipper.offset.h"
#include "clipper2/clipper.h"
#include "clipper2/clipper.offset.h"

namespace Clipper2Lib {

Expand Down
2 changes: 1 addition & 1 deletion CPP/Examples/ConsoleDemo1/ConsoleDemo1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string>
#include <chrono>

#include "../../Clipper2Lib/clipper.h"
#include "clipper2/clipper.h"
#include "../../Utils/clipper.svg.utils.h"
#include "../../Utils/ClipFileLoad.h"
#include "../../Utils/ClipFileSave.h"
Expand Down
2 changes: 1 addition & 1 deletion CPP/Examples/ConsoleDemo2/ConsoleDemo2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <string>
#include <chrono>

#include "../../Clipper2Lib/clipper.h"
#include "clipper2/clipper.h"
#include "../../Utils/clipper.svg.utils.h"
#include "../../Utils/ClipFileLoad.h"
#include "../../Utils/ClipFileSave.h"
Expand Down
2 changes: 1 addition & 1 deletion CPP/Examples/InflateDemo/InflateDemo1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <cstdlib>
#include "../../Clipper2Lib/clipper.h"
#include "clipper2/clipper.h"
#include "../../Utils/clipper.svg.h"
#include "../../Utils/clipper.svg.utils.h"
#include "../../Utils/Timer.h"
Expand Down
2 changes: 1 addition & 1 deletion CPP/Examples/UsingZ/UsingZ1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#include <cstdlib>
#include "../../Clipper2Lib/clipper.h"
#include "clipper2/clipper.h"
#include "../../Utils/clipper.svg.h"
#include "../../Utils/clipper.svg.utils.h"

Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestLines.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"
#include "ClipFileLoad.h"

TEST(Clipper2Tests, TestMultipleLines) {
Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestOffsetOrientation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.offset.h"
#include "clipper2/clipper.offset.h"

TEST(Clipper2Tests, TestOffsettingOrientation) {
Clipper2Lib::ClipperOffset co;
Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestOrientation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"

using namespace Clipper2Lib;

Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestPolygons.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"
#include "ClipFileLoad.h"

inline Clipper2Lib::PathD MakeRandomPath(int width, int height, unsigned vertCnt)
Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestPolytreeHoles1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"
#include "ClipFileLoad.h"

using namespace Clipper2Lib;
Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestPolytreeHoles2.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"
#include "ClipFileLoad.h"

using namespace Clipper2Lib;
Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestPolytreeIntersection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"

using namespace Clipper2Lib;

Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestPolytreeUnion.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"

using namespace Clipper2Lib;

Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestRandomPaths.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"
#include <fstream>
#include <random>

Expand Down
2 changes: 1 addition & 1 deletion CPP/Tests/TestTrimCollinear.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "clipper.h"
#include "clipper2/clipper.h"

using namespace Clipper2Lib;

Expand Down
2 changes: 1 addition & 1 deletion CPP/Utils/ClipFileLoad.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <fstream>
#include <string>
#include "clipper.h"
#include "clipper2/clipper.h"
#ifndef _WIN32
#include <sys/types.h>
#include <sys/stat.h>
Expand Down
6 changes: 3 additions & 3 deletions CPP/Utils/ClipFileSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class BMH_Search
{
while (current < end)
{
uint8_t i = shift[(unsigned)*current]; //compare last byte first
uint8_t i = shift[static_cast<unsigned>(*current)]; //compare last byte first
if (!i) //last byte matches if i == 0
{
char* j = current - needle_len_less1;
Expand All @@ -88,12 +88,12 @@ class BMH_Search
{
while (current < end)
{
uint8_t i = shift[case_table[(unsigned)*current]];
uint8_t i = shift[case_table[static_cast<unsigned>(*current)]];
if (!i)
{
char* j = current - needle_len_less1;
while (i < needle_len_less1 &&
needle_ic_[i] == case_table[(unsigned)*(j + (unsigned)i)]) ++i;
needle_ic_[i] == case_table[static_cast<unsigned>(*(j + i))]) ++i;
if (i == needle_len_less1)
{
++current;
Expand Down
2 changes: 1 addition & 1 deletion CPP/Utils/ClipFileSave.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef CLIPPER_TEST_SAVE_H
#define CLIPPER_TEST_SAVE_H

#include "clipper.h"
#include "clipper2/clipper.h"

bool SaveTest(const std::string& filename, bool append,
Clipper2Lib::Paths64* subj, Clipper2Lib::Paths64* subj_open, Clipper2Lib::Paths64* clip,
Expand Down
2 changes: 1 addition & 1 deletion CPP/Utils/clipper.svg.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <cstdlib>
#include <string>
#include "clipper.h"
#include "clipper2/clipper.h"

namespace Clipper2Lib {

Expand Down
2 changes: 1 addition & 1 deletion CPP/Utils/clipper.svg.utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <cstdlib>
#include <string>
#include "clipper.h"
#include "clipper2/clipper.h"
#include "clipper.svg.h"
#ifndef _WIN32
#include <sys/types.h>
Expand Down

0 comments on commit acfeee6

Please sign in to comment.