-
Notifications
You must be signed in to change notification settings - Fork 102
/
CMakeLists.txt
179 lines (143 loc) · 6.15 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
cmake_minimum_required(VERSION 3.1)
project(Libnest2D)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED)
# Add our own cmake module path.
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/)
include(RequirePackage)
set(RP_REPOSITORY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external CACHE PATH "" FORCE)
option(LIBNEST2D_BUILD_UNITTESTS "If enabled, googletest framework will be downloaded
and the provided unit tests will be included in the build." OFF)
option(BUILD_SHARED_LIBS "Build shared libs instead of static (applies for dependencies as well)" OFF)
option(LIBNEST2D_HEADER_ONLY "If enabled static library will not be built." ON)
set(GEOMETRY_BACKENDS clipper boost eigen)
set(LIBNEST2D_GEOMETRIES clipper CACHE STRING "Geometry backend")
set_property(CACHE LIBNEST2D_GEOMETRIES PROPERTY STRINGS ${GEOMETRY_BACKENDS})
list(FIND GEOMETRY_BACKENDS ${LIBNEST2D_GEOMETRIES} GEOMETRY_TYPE)
if(${GEOMETRY_TYPE} EQUAL -1)
message(FATAL_ERROR "Option ${LIBNEST2D_GEOMETRIES} not supported, valid entries are ${GEOMETRY_BACKENDS}")
endif()
set(OPTIMIZERS nlopt optimlib)
set(LIBNEST2D_OPTIMIZER nlopt CACHE STRING "Optimization backend")
set_property(CACHE LIBNEST2D_OPTIMIZER PROPERTY STRINGS ${OPTIMIZERS})
list(FIND OPTIMIZERS ${LIBNEST2D_OPTIMIZER} OPTIMIZER_TYPE)
if(${OPTIMIZER_TYPE} EQUAL -1)
message(FATAL_ERROR "Option ${LIBNEST2D_OPTIMIZER} not supported, valid entries are ${OPTIMIZERS}")
endif()
set(THREADING std tbb omp none)
set(LIBNEST2D_THREADING std CACHE STRING "Multithreading")
set_property(CACHE LIBNEST2D_THREADING PROPERTY STRINGS ${THREADING})
list(FIND THREADING ${LIBNEST2D_THREADING} THREADING_TYPE)
if(${THREADING_TYPE} EQUAL -1)
message(FATAL_ERROR "Option ${LIBNEST2D_THREADING} not supported, valid entries are ${THREADING}")
endif()
add_library(libnest2d_headeronly INTERFACE)
set(SRC_DIR ${PROJECT_SOURCE_DIR}/include)
set(LIBNEST2D_SRCFILES
include/libnest2d/libnest2d.hpp
include/libnest2d/nester.hpp
include/libnest2d/geometry_traits.hpp
include/libnest2d/geometry_traits_nfp.hpp
include/libnest2d/common.hpp
include/libnest2d/parallel.hpp
include/libnest2d/optimizer.hpp
include/libnest2d/utils/metaloop.hpp
include/libnest2d/utils/rotfinder.hpp
include/libnest2d/utils/rotcalipers.hpp
include/libnest2d/utils/bigint.hpp
include/libnest2d/utils/rational.hpp
include/libnest2d/utils/boost_alg.hpp
include/libnest2d/placers/placer_boilerplate.hpp
include/libnest2d/placers/bottomleftplacer.hpp
include/libnest2d/placers/nfpplacer.hpp
include/libnest2d/selections/selection_boilerplate.hpp
include/libnest2d/selections/filler.hpp
include/libnest2d/selections/firstfit.hpp
include/libnest2d/selections/djd_heuristic.hpp
)
set(LIBNEST2D_PUBLIC_PACKAGES "" CACHE INTERNAL "")
if(NOT ${LIBNEST2D_THREADING} STREQUAL "none")
include(threading_${LIBNEST2D_THREADING})
target_link_libraries(libnest2d_headeronly INTERFACE ${LIBNEST2D_THREADING}Threading)
target_compile_definitions(libnest2d_headeronly INTERFACE LIBNEST2D_THREADING_${LIBNEST2D_THREADING})
endif()
add_subdirectory(${SRC_DIR}/libnest2d/backends/${LIBNEST2D_GEOMETRIES})
target_link_libraries(libnest2d_headeronly INTERFACE ${LIBNEST2D_GEOMETRIES}Backend)
target_compile_definitions(libnest2d_headeronly INTERFACE LIBNEST2D_GEOMETRIES_${LIBNEST2D_GEOMETRIES})
add_subdirectory(${SRC_DIR}/libnest2d/optimizers/${LIBNEST2D_OPTIMIZER})
target_link_libraries(libnest2d_headeronly INTERFACE ${LIBNEST2D_OPTIMIZER}Optimizer)
target_compile_definitions(libnest2d_headeronly INTERFACE LIBNEST2D_OPTIMIZER_${LIBNEST2D_OPTIMIZER})
target_include_directories(libnest2d_headeronly INTERFACE $<BUILD_INTERFACE:${SRC_DIR}>)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
add_library(libnest2d INTERFACE)
if(NOT LIBNEST2D_HEADER_ONLY)
set(LIBNAME libnest2d_${LIBNEST2D_GEOMETRIES}_${LIBNEST2D_OPTIMIZER})
add_library(${LIBNAME} ${PROJECT_SOURCE_DIR}/src/libnest2d.cpp)
set_target_properties(${LIBNAME} PROPERTIES PREFIX "")
set_target_properties(${LIBNAME} PROPERTIES DEBUG_POSTFIX "d")
set_target_properties(${LIBNAME} PROPERTIES SOVERSION "1.0")
target_link_libraries(${LIBNAME} PUBLIC libnest2d_headeronly)
target_compile_definitions(${LIBNAME} PUBLIC LIBNEST2D_STATIC)
target_sources(${LIBNAME} PRIVATE ${LIBNEST2D_SRCFILES})
target_link_libraries(libnest2d INTERFACE ${LIBNAME})
else()
target_link_libraries(libnest2d INTERFACE libnest2d_headeronly)
endif()
if(LIBNEST2D_BUILD_UNITTESTS)
enable_testing()
add_subdirectory(${PROJECT_SOURCE_DIR}/tests)
endif()
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION 1.0
COMPATIBILITY AnyNewerVersion
)
export(EXPORT ${PROJECT_NAME}Targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake"
NAMESPACE ${PROJECT_NAME}::
)
install(TARGETS libnest2d libnest2d_headeronly ${LIBNAME}
EXPORT ${PROJECT_NAME}Targets
)
configure_file(cmake_modules/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
@ONLY
)
set(ConfigPackageLocation lib/cmake/${PROJECT_NAME})
install(EXPORT ${PROJECT_NAME}Targets
FILE
${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${ConfigPackageLocation}
)
foreach (srcfile IN ITEMS ${LIBNEST2D_SRCFILES})
get_filename_component(srcfile_dir ${srcfile} DIRECTORY)
install(
FILES
${PROJECT_SOURCE_DIR}/${srcfile}
DESTINATION
${srcfile_dir}
COMPONENT
Devel
)
endforeach()
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindClipper.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindNLopt.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindTBB.cmake"
DESTINATION
${ConfigPackageLocation}
COMPONENT
Devel
)
rp_install_versions_file(${ConfigPackageLocation})
foreach(p ${LIBNEST2D_PUBLIC_PACKAGES})
set(_pkgstr "${_pkgstr} ${p}")
endforeach()
message(STATUS "Installed Libnest2DConfig.cmake will require packages:${_pkgstr}")