From e6a6266f3df3726f3d9e4fb4312d7dbc1c57326e Mon Sep 17 00:00:00 2001
From: John Beard <john.j.beard@gmail.com>
Date: Thu, 31 Jan 2019 11:53:01 +0000
Subject: [PATCH] Build: libpolygon provides its own includes

Libpolygon can provide its own includes via target_include_dirs PUBLIC.
This means any linking targets do not need to specifiy them manually.

As common requires polygon, the polygon dep is also now no longer
required downstream of libcommon, as it's transisitvely implied
by libcommon's target_link_libraries.

This resolves a circular dependency previously detected and also
simplifies CMakeLists.
---
 3d-viewer/CMakeLists.txt                          |  2 +-
 bitmap2component/CMakeLists.txt                   |  2 --
 common/CMakeLists.txt                             | 11 ++++++++---
 cvpcb/CMakeLists.txt                              |  4 ----
 eeschema/CMakeLists.txt                           |  4 ----
 gerbview/CMakeLists.txt                           |  4 ----
 include/geometry/shape_line_chain.h               |  3 ++-
 kicad/CMakeLists.txt                              |  2 --
 pagelayout_editor/CMakeLists.txt                  |  3 ---
 pcb_calculator/CMakeLists.txt                     |  2 --
 pcbnew/CMakeLists.txt                             |  2 --
 pcbnew/connectivity/CMakeLists.txt                |  1 -
 pcbnew/router/CMakeLists.txt                      |  1 -
 polygon/CMakeLists.txt                            |  3 +++
 polygon/{ => include}/SutherlandHodgmanClipPoly.h |  0
 polygon/{ => include}/clipper.hpp                 |  0
 polygon/{ => include}/math_for_graphics.h         |  0
 polygon/{ => include}/polygon_test_point_inside.h |  0
 qa/common/CMakeLists.txt                          |  2 --
 qa/common_tools/CMakeLists.txt                    |  2 --
 qa/pcb_test_window/CMakeLists.txt                 |  5 -----
 qa/pcbnew/CMakeLists.txt                          |  1 -
 qa/pcbnew_tools/CMakeLists.txt                    |  1 -
 qa/pcbnew_utils/CMakeLists.txt                    |  2 --
 tools/CMakeLists.txt                              |  1 -
 25 files changed, 14 insertions(+), 44 deletions(-)
 rename polygon/{ => include}/SutherlandHodgmanClipPoly.h (100%)
 rename polygon/{ => include}/clipper.hpp (100%)
 rename polygon/{ => include}/math_for_graphics.h (100%)
 rename polygon/{ => include}/polygon_test_point_inside.h (100%)

diff --git a/3d-viewer/CMakeLists.txt b/3d-viewer/CMakeLists.txt
index 728f1c3f7b..3a0c78151d 100644
--- a/3d-viewer/CMakeLists.txt
+++ b/3d-viewer/CMakeLists.txt
@@ -8,7 +8,6 @@ include_directories(
     ${CMAKE_CURRENT_BINARY_DIR}
     ../include/legacy_wx
     ../pcbnew
-    ../polygon
     3d_canvas
     3d_cache
     3d_rendering
@@ -108,6 +107,7 @@ add_dependencies( 3d-viewer pcbcommon )
 
 target_link_libraries( 3d-viewer
                        gal
+                       polygon
                        ${Boost_}
                        ${wxWidgets_LIBRARIES}
                        ${OPENGL_LIBRARIES}
diff --git a/bitmap2component/CMakeLists.txt b/bitmap2component/CMakeLists.txt
index f0c624aebb..78b05c9f73 100644
--- a/bitmap2component/CMakeLists.txt
+++ b/bitmap2component/CMakeLists.txt
@@ -6,7 +6,6 @@ endif()
 include_directories( BEFORE ${INC_BEFORE} )
 include_directories(
     ../potrace
-    ../polygon
     ${INC_AFTER}
     )
 
@@ -49,7 +48,6 @@ add_executable( bitmap2component WIN32 MACOSX_BUNDLE
 
 target_link_libraries( bitmap2component
     common
-    polygon
     gal
     ${wxWidgets_LIBRARIES}
     potrace
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
index 2c37df527e..915acb7e7c 100644
--- a/common/CMakeLists.txt
+++ b/common/CMakeLists.txt
@@ -17,7 +17,6 @@ include_directories(
     ${CURL_INCLUDE_DIRS}
     ../3d-viewer
     ../pcbnew
-    ../polygon
     ${INC_AFTER}
     ${OCE_INCLUDE_DIRS}
     ${OCC_INCLUDE_DIR}
@@ -93,10 +92,11 @@ add_library( legacy_wx STATIC ${LEGACY_WX_SRCS} )
 target_include_directories( legacy_wx PUBLIC ../include/legacy_wx )
 target_include_directories( legacy_gal PUBLIC ../include/legacy_gal )
 
-target_link_libraries( legacy_wx PRIVATE bitmaps )
-target_link_libraries( legacy_gal PRIVATE bitmaps )
+target_link_libraries( legacy_wx PRIVATE bitmaps polygon )
+target_link_libraries( legacy_gal PRIVATE bitmaps polygon )
 
 target_link_libraries( gal
+    polygon
     bitmaps
     ${GLEW_LIBRARIES}
     ${CAIRO_LIBRARIES}
@@ -423,6 +423,7 @@ add_library( common STATIC ${COMMON_SRCS} )
 add_dependencies( common version_header )
 target_link_libraries( common
     bitmaps
+    polygon
     gal
     ${Boost_LIBRARIES}
     ${CURL_LIBRARIES}
@@ -504,6 +505,10 @@ target_include_directories( pcbcommon PUBLIC
     ../include/legacy_wx
 )
 
+target_link_libraries( pcbcommon PUBLIC
+    common
+)
+
 
 # auto-generate netlist_lexer.h and netlist_keywords.cpp
 make_lexer(
diff --git a/cvpcb/CMakeLists.txt b/cvpcb/CMakeLists.txt
index 42acb5b6a0..d300ee44a3 100644
--- a/cvpcb/CMakeLists.txt
+++ b/cvpcb/CMakeLists.txt
@@ -12,7 +12,6 @@ include_directories(
     ../3d-viewer
     ../pcbnew
     ../pcbnew/dialogs
-    ../polygon
     ../common
     ${GLM_INCLUDE_DIR}
     ${INC_AFTER}
@@ -146,21 +145,18 @@ target_link_libraries( cvpcb_kiface
     pcad2kicadpcb
     3d-viewer
     common
-    polygon
     gal
     legacy_wx
     pcbcommon
     pcad2kicadpcb
     3d-viewer
     common
-    polygon
     gal
     legacy_wx
     pcbcommon
     pcad2kicadpcb
     3d-viewer
     common
-    polygon
     gal
     legacy_wx
     ${wxWidgets_LIBRARIES}
diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt
index f6708cb6ba..c56ac2d9cb 100644
--- a/eeschema/CMakeLists.txt
+++ b/eeschema/CMakeLists.txt
@@ -342,19 +342,15 @@ add_library( eeschema_kiface SHARED
     )
 target_link_libraries( eeschema_kiface
     common
-    polygon
     gal
     legacy_gal
     common
-    polygon
     gal
     legacy_gal
     common
-    polygon
     gal
     legacy_gal
     common
-    polygon
     gal
     legacy_gal
     ${wxWidgets_LIBRARIES}
diff --git a/gerbview/CMakeLists.txt b/gerbview/CMakeLists.txt
index e455d64e91..66269d5e2d 100644
--- a/gerbview/CMakeLists.txt
+++ b/gerbview/CMakeLists.txt
@@ -12,7 +12,6 @@ include_directories(
     dialogs
     ../common
     ../3d-viewer
-    ../polygon
     ${INC_AFTER}
     )
 
@@ -143,15 +142,12 @@ set_target_properties( gerbview_kiface PROPERTIES
     )
 target_link_libraries( gerbview_kiface
     common
-    polygon
     gal
     legacy_wx
     common
-    polygon
     gal
     legacy_wx
     common
-    polygon
     gal
     legacy_wx
     ${wxWidgets_LIBRARIES}
diff --git a/include/geometry/shape_line_chain.h b/include/geometry/shape_line_chain.h
index 16c78d8ac6..adcbef0248 100644
--- a/include/geometry/shape_line_chain.h
+++ b/include/geometry/shape_line_chain.h
@@ -34,7 +34,8 @@
 #include <math/vector2d.h>
 #include <geometry/shape.h>
 #include <geometry/seg.h>
-#include <../polygon/clipper.hpp>
+
+#include <clipper.hpp>
 
 /**
  * Class SHAPE_LINE_CHAIN
diff --git a/kicad/CMakeLists.txt b/kicad/CMakeLists.txt
index 06ae3853c9..1c693aded4 100644
--- a/kicad/CMakeLists.txt
+++ b/kicad/CMakeLists.txt
@@ -71,13 +71,11 @@ if( APPLE )
         )
     target_link_libraries( kicad
         common
-        polygon
         ${wxWidgets_LIBRARIES}
         )
 else()
     target_link_libraries( kicad
         common
-        polygon
         gal
         ${wxWidgets_LIBRARIES}
         ${GDI_PLUS_LIBRARIES}
diff --git a/pagelayout_editor/CMakeLists.txt b/pagelayout_editor/CMakeLists.txt
index 59bb248b80..5e013398b3 100644
--- a/pagelayout_editor/CMakeLists.txt
+++ b/pagelayout_editor/CMakeLists.txt
@@ -109,15 +109,12 @@ add_library( pl_editor_kiface MODULE
     )
 target_link_libraries( pl_editor_kiface
     common
-    polygon
     gal
     legacy_wx
     common
-    polygon
     gal
     legacy_wx
     common
-    polygon
     gal
     legacy_wx
     ${wxWidgets_LIBRARIES}
diff --git a/pcb_calculator/CMakeLists.txt b/pcb_calculator/CMakeLists.txt
index ad01dbb032..e040451298 100644
--- a/pcb_calculator/CMakeLists.txt
+++ b/pcb_calculator/CMakeLists.txt
@@ -5,7 +5,6 @@ include_directories(
     dialogs
     transline
     attenuators
-    ../polygon
     ../common
     ${INC_AFTER}
     )
@@ -88,7 +87,6 @@ set_target_properties( pcb_calculator_kiface PROPERTIES
     )
 target_link_libraries( pcb_calculator_kiface
     common
-    polygon
     ${wxWidgets_LIBRARIES}
     )
 set_source_files_properties( pcb_calculator.cpp PROPERTIES
diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt
index babfb13d57..1d3cc5cf54 100644
--- a/pcbnew/CMakeLists.txt
+++ b/pcbnew/CMakeLists.txt
@@ -42,7 +42,6 @@ include_directories(
     ./autorouter
     ../3d-viewer
     ../common
-    ../polygon
     ../common/dialogs
     ./exporters
     ../dxflib_qcad
@@ -679,7 +678,6 @@ set( PCBNEW_KIFACE_LIBRARIES
     pcad2kicadpcb
     legacy_wx
     common
-    polygon
     gal
     lib_dxf
     idf3
diff --git a/pcbnew/connectivity/CMakeLists.txt b/pcbnew/connectivity/CMakeLists.txt
index 2932ed8ba0..69e238741c 100644
--- a/pcbnew/connectivity/CMakeLists.txt
+++ b/pcbnew/connectivity/CMakeLists.txt
@@ -4,7 +4,6 @@ include_directories(
     ./
     ../
     ../../include
-    ../../polygon
     ${INC_AFTER}
 )
 
diff --git a/pcbnew/router/CMakeLists.txt b/pcbnew/router/CMakeLists.txt
index 44a945644a..e7ca4422cb 100644
--- a/pcbnew/router/CMakeLists.txt
+++ b/pcbnew/router/CMakeLists.txt
@@ -6,7 +6,6 @@ include_directories(
     ../../include
     ../../3d-viewer
     ../../pcbnew
-    ../../polygon
     ${INC_AFTER}
 )
 
diff --git a/polygon/CMakeLists.txt b/polygon/CMakeLists.txt
index 4399614058..881f426812 100644
--- a/polygon/CMakeLists.txt
+++ b/polygon/CMakeLists.txt
@@ -16,3 +16,6 @@ set(POLYGON_SRCS
 
 add_library(polygon STATIC ${POLYGON_SRCS})
 
+target_include_directories( polygon PUBLIC
+    include
+)
\ No newline at end of file
diff --git a/polygon/SutherlandHodgmanClipPoly.h b/polygon/include/SutherlandHodgmanClipPoly.h
similarity index 100%
rename from polygon/SutherlandHodgmanClipPoly.h
rename to polygon/include/SutherlandHodgmanClipPoly.h
diff --git a/polygon/clipper.hpp b/polygon/include/clipper.hpp
similarity index 100%
rename from polygon/clipper.hpp
rename to polygon/include/clipper.hpp
diff --git a/polygon/math_for_graphics.h b/polygon/include/math_for_graphics.h
similarity index 100%
rename from polygon/math_for_graphics.h
rename to polygon/include/math_for_graphics.h
diff --git a/polygon/polygon_test_point_inside.h b/polygon/include/polygon_test_point_inside.h
similarity index 100%
rename from polygon/polygon_test_point_inside.h
rename to polygon/include/polygon_test_point_inside.h
diff --git a/qa/common/CMakeLists.txt b/qa/common/CMakeLists.txt
index 55d8d8f89e..9ac55d56b7 100644
--- a/qa/common/CMakeLists.txt
+++ b/qa/common/CMakeLists.txt
@@ -62,7 +62,6 @@ set( common_srcs
 set( common_libs
     common
     legacy_gal
-    polygon
     gal
     qa_utils
     unit_test_utils
@@ -89,7 +88,6 @@ include_directories(
     ${CMAKE_SOURCE_DIR}
     ${CMAKE_SOURCE_DIR}/pcbnew
     ${CMAKE_SOURCE_DIR}/include
-    ${CMAKE_SOURCE_DIR}/polygon
     ${INC_AFTER}
 )
 
diff --git a/qa/common_tools/CMakeLists.txt b/qa/common_tools/CMakeLists.txt
index 9267bfe7d4..445f1d217c 100644
--- a/qa/common_tools/CMakeLists.txt
+++ b/qa/common_tools/CMakeLists.txt
@@ -41,14 +41,12 @@ add_executable( qa_common_tools
 include_directories(
     ${CMAKE_SOURCE_DIR}
     ${CMAKE_SOURCE_DIR}/include
-    ${CMAKE_SOURCE_DIR}/polygon
     ${INC_AFTER}
 )
 
 target_link_libraries( qa_common_tools
     common
     legacy_gal
-    polygon
     gal
     qa_utils
     ${wxWidgets_LIBRARIES}
diff --git a/qa/pcb_test_window/CMakeLists.txt b/qa/pcb_test_window/CMakeLists.txt
index 7e8eed0c07..e1ab06d4ce 100644
--- a/qa/pcb_test_window/CMakeLists.txt
+++ b/qa/pcb_test_window/CMakeLists.txt
@@ -55,7 +55,6 @@ include_directories(
     ${CMAKE_SOURCE_DIR}/pcbnew/router
     ${CMAKE_SOURCE_DIR}/pcbnew/tools
     ${CMAKE_SOURCE_DIR}/pcbnew/dialogs
-    ${CMAKE_SOURCE_DIR}/polygon
     ${CMAKE_SOURCE_DIR}/common/geometry
     ${CMAKE_SOURCE_DIR}/qa/qa_utils
     ${Boost_INCLUDE_DIR}
@@ -63,19 +62,15 @@ include_directories(
 )
 
 target_link_libraries( test_window
-    polygon
     pnsrouter
     common
     pcbcommon
-    polygon
     pnsrouter
     common
     pcbcommon
-    polygon
     pnsrouter
     common
     pcbcommon
-    polygon
     pnsrouter
     common
     pcbcommon
diff --git a/qa/pcbnew/CMakeLists.txt b/qa/pcbnew/CMakeLists.txt
index a3645cbc0d..e194cd650c 100644
--- a/qa/pcbnew/CMakeLists.txt
+++ b/qa/pcbnew/CMakeLists.txt
@@ -64,7 +64,6 @@ target_link_libraries( qa_pcbnew
     common
     pcbcommon
     legacy_wx
-    polygon
     gal
     qa_utils
     lib_dxf
diff --git a/qa/pcbnew_tools/CMakeLists.txt b/qa/pcbnew_tools/CMakeLists.txt
index 2b9550e2f7..76934655c5 100644
--- a/qa/pcbnew_tools/CMakeLists.txt
+++ b/qa/pcbnew_tools/CMakeLists.txt
@@ -52,7 +52,6 @@ target_link_libraries( qa_pcbnew_tools
     common
     pcbcommon
     legacy_wx
-    polygon
     gal
     qa_utils
     lib_dxf
diff --git a/qa/pcbnew_utils/CMakeLists.txt b/qa/pcbnew_utils/CMakeLists.txt
index a6c46130f4..f8aab26569 100644
--- a/qa/pcbnew_utils/CMakeLists.txt
+++ b/qa/pcbnew_utils/CMakeLists.txt
@@ -45,7 +45,6 @@ target_include_directories( qa_pcbnew_utils PUBLIC
     # target_include_directories and made PUBLIC)
     ${CMAKE_SOURCE_DIR}
     ${CMAKE_SOURCE_DIR}/include
-    ${CMAKE_SOURCE_DIR}/polygon
     ${CMAKE_SOURCE_DIR}/pcbnew
     ${CMAKE_SOURCE_DIR}/common
     ${CMAKE_SOURCE_DIR}/pcbnew/router
@@ -65,7 +64,6 @@ target_link_libraries( qa_pcbnew_utils PUBLIC
 #     common
 #     pcbcommon
 #     legacy_wx
-#     polygon
 #     gal
 #     qa_utils
 #     lib_dxf
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt
index 40602e92d2..2c9587bbf2 100644
--- a/tools/CMakeLists.txt
+++ b/tools/CMakeLists.txt
@@ -14,7 +14,6 @@ add_executable( container_test
     )
 target_link_libraries( container_test
     common
-    polygon
     ${wxWidgets_LIBRARIES}
     )