2018-05-17 08:37:26 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
project(Libnest2D)
|
|
|
|
|
|
|
|
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
|
2018-07-16 14:07:29 +00:00
|
|
|
# Update if necessary
|
2018-05-17 08:37:26 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long ")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED)
|
|
|
|
|
|
|
|
# Add our own cmake module path.
|
|
|
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/)
|
|
|
|
|
|
|
|
option(LIBNEST2D_UNITTESTS "If enabled, googletest framework will be downloaded
|
|
|
|
and the provided unit tests will be included in the build." OFF)
|
|
|
|
|
2018-06-05 10:02:45 +00:00
|
|
|
option(LIBNEST2D_BUILD_EXAMPLES "If enabled, examples will be built." OFF)
|
|
|
|
|
2018-07-16 14:07:29 +00:00
|
|
|
set(LIBNEST2D_GEOMETRIES_BACKEND "clipper" CACHE STRING
|
|
|
|
"Build libnest2d with geometry classes implemented by the chosen backend.")
|
2018-05-17 08:37:26 +00:00
|
|
|
|
2018-07-16 14:07:29 +00:00
|
|
|
set(LIBNEST2D_OPTIMIZER_BACKEND "nlopt" CACHE STRING
|
|
|
|
"Build libnest2d with optimization features implemented by the chosen backend.")
|
2018-05-17 08:37:26 +00:00
|
|
|
|
|
|
|
set(LIBNEST2D_SRCFILES
|
2018-07-16 14:07:29 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/libnest2d.hpp # Templates only
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d.h # Exports ready made types using template arguments
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/geometry_traits.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/common.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/optimizer.hpp
|
2018-07-27 10:28:14 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/metaloop.hpp
|
2018-08-09 07:59:05 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/rotfinder.hpp
|
2018-07-16 14:07:29 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/placers/placer_boilerplate.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/placers/bottomleftplacer.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/placers/nfpplacer.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/geometry_traits_nfp.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/selections/selection_boilerplate.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/selections/filler.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/selections/firstfit.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/selections/djd_heuristic.hpp
|
2018-05-17 08:37:26 +00:00
|
|
|
)
|
|
|
|
|
2018-07-16 14:07:29 +00:00
|
|
|
set(LIBNEST2D_LIBRARIES "")
|
|
|
|
|
|
|
|
set(LIBNEST2D_HEADERS ${CMAKE_CURRENT_SOURCE_DIR})
|
2018-05-17 08:37:26 +00:00
|
|
|
|
2018-07-16 14:07:29 +00:00
|
|
|
if(LIBNEST2D_GEOMETRIES_BACKEND STREQUAL "clipper")
|
|
|
|
|
|
|
|
# Clipper backend is not enough on its own, it still needs some functions
|
|
|
|
# from Boost geometry
|
2018-05-17 08:37:26 +00:00
|
|
|
if(NOT Boost_INCLUDE_DIRS_FOUND)
|
2018-06-05 10:02:45 +00:00
|
|
|
find_package(Boost 1.58 REQUIRED)
|
2018-05-17 08:37:26 +00:00
|
|
|
# TODO automatic download of boost geometry headers
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_subdirectory(libnest2d/clipper_backend)
|
|
|
|
|
|
|
|
include_directories(BEFORE ${CLIPPER_INCLUDE_DIRS})
|
|
|
|
include_directories(${Boost_INCLUDE_DIRS})
|
|
|
|
|
2018-07-27 10:28:14 +00:00
|
|
|
list(APPEND LIBNEST2D_SRCFILES ${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/clipper_backend/clipper_backend.hpp
|
2018-07-16 14:07:29 +00:00
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/boost_alg.hpp)
|
|
|
|
list(APPEND LIBNEST2D_LIBRARIES ${CLIPPER_LIBRARIES})
|
|
|
|
list(APPEND LIBNEST2D_HEADERS ${CLIPPER_INCLUDE_DIRS}
|
|
|
|
${Boost_INCLUDE_DIRS_FOUND})
|
2018-05-17 08:37:26 +00:00
|
|
|
endif()
|
|
|
|
|
2018-07-16 14:07:29 +00:00
|
|
|
if(LIBNEST2D_OPTIMIZER_BACKEND STREQUAL "nlopt")
|
|
|
|
find_package(NLopt 1.4)
|
|
|
|
if(NOT NLopt_FOUND)
|
|
|
|
message(STATUS "NLopt not found so downloading "
|
|
|
|
"and automatic build is performed...")
|
|
|
|
include(DownloadNLopt)
|
|
|
|
endif()
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
|
|
|
|
list(APPEND LIBNEST2D_SRCFILES ${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/optimizers/simplex.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/optimizers/subplex.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/optimizers/genetic.hpp
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/libnest2d/optimizers/nlopt_boilerplate.hpp)
|
2018-07-27 10:28:14 +00:00
|
|
|
list(APPEND LIBNEST2D_LIBRARIES ${NLopt_LIBS})
|
2018-07-16 14:07:29 +00:00
|
|
|
list(APPEND LIBNEST2D_HEADERS ${NLopt_INCLUDE_DIR})
|
2018-06-05 10:02:45 +00:00
|
|
|
endif()
|
2018-05-17 08:37:26 +00:00
|
|
|
|
|
|
|
if(LIBNEST2D_UNITTESTS)
|
2018-07-27 10:28:14 +00:00
|
|
|
enable_testing()
|
2018-05-17 08:37:26 +00:00
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
2018-06-05 10:02:45 +00:00
|
|
|
|
|
|
|
if(LIBNEST2D_BUILD_EXAMPLES)
|
2018-08-22 11:52:41 +00:00
|
|
|
|
2018-07-16 14:07:29 +00:00
|
|
|
add_executable(example examples/main.cpp
|
|
|
|
# tools/libnfpglue.hpp
|
|
|
|
# tools/libnfpglue.cpp
|
2018-08-20 14:34:35 +00:00
|
|
|
tools/nfp_svgnest.hpp
|
|
|
|
tools/nfp_svgnest_glue.hpp
|
2018-07-16 14:07:29 +00:00
|
|
|
tools/svgtools.hpp
|
2018-06-05 10:02:45 +00:00
|
|
|
tests/printer_parts.cpp
|
2018-07-16 14:07:29 +00:00
|
|
|
tests/printer_parts.h
|
2018-08-22 11:52:41 +00:00
|
|
|
${LIBNEST2D_SRCFILES}
|
|
|
|
)
|
|
|
|
set(TBB_STATIC ON)
|
|
|
|
find_package(TBB QUIET)
|
|
|
|
if(TBB_FOUND)
|
|
|
|
message(STATUS "Parallelization with Intel TBB")
|
|
|
|
target_include_directories(example PUBLIC ${TBB_INCLUDE_DIRS})
|
|
|
|
target_compile_definitions(example PUBLIC ${TBB_DEFINITIONS} -DUSE_TBB)
|
|
|
|
if(MSVC)
|
|
|
|
# Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
|
|
|
|
target_compile_definitions(example PUBLIC -D__TBB_NO_IMPLICIT_LINKAGE)
|
|
|
|
endif()
|
|
|
|
# The Intel TBB library will use the std::exception_ptr feature of C++11.
|
|
|
|
target_compile_definitions(example PUBLIC -DTBB_USE_CAPTURED_EXCEPTION=1)
|
|
|
|
|
|
|
|
target_link_libraries(example ${TBB_LIBRARIES})
|
|
|
|
else()
|
|
|
|
find_package(OpenMP QUIET)
|
|
|
|
if(OpenMP_CXX_FOUND)
|
|
|
|
message(STATUS "Parallelization with OpenMP")
|
|
|
|
target_include_directories(example PUBLIC OpenMP::OpenMP_CXX)
|
|
|
|
target_link_libraries(example OpenMP::OpenMP_CXX)
|
|
|
|
endif()
|
|
|
|
endif()
|
2018-07-16 14:07:29 +00:00
|
|
|
|
|
|
|
target_link_libraries(example ${LIBNEST2D_LIBRARIES})
|
|
|
|
target_include_directories(example PUBLIC ${LIBNEST2D_HEADERS})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_directory_property(hasParent PARENT_DIRECTORY)
|
|
|
|
if(hasParent)
|
|
|
|
set(LIBNEST2D_INCLUDES ${LIBNEST2D_HEADERS} PARENT_SCOPE)
|
|
|
|
set(LIBNEST2D_LIBRARIES ${LIBNEST2D_LIBRARIES} PARENT_SCOPE)
|
2018-06-05 10:02:45 +00:00
|
|
|
endif()
|