CMakeLists.txt 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. #/|/ Copyright (c) Prusa Research 2017 - 2023 Tomáš Mészáros @tamasmeszaros, Vojtěch Bubník @bubnikv, Lukáš Matěna @lukasmatena, Filip Sykala @Jony01, Oleksandra Iushchenko @YuSanka, Lukáš Hejl @hejllukas, David Kocík @kocikdav, Enrico Turri @enricoturri1966, Vojtěch Král @vojtechkral
  2. #/|/ Copyright (c) 2023 Ben Greiner
  3. #/|/ Copyright (c) 2021 D-mo @dimitry-ishenko
  4. #/|/ Copyright (c) 2020 Pascal de Bruijn @pmjdebruijn
  5. #/|/ Copyright (c) 2019 Sam Segers
  6. #/|/ Copyright (c) 2019 Colin Gilgenbach @hexane360
  7. #/|/ Copyright (c) 2018 Dan Kortschak
  8. #/|/
  9. #/|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
  10. #/|/
  11. cmake_minimum_required(VERSION 3.13)
  12. project(PrusaSlicer)
  13. include("version.inc")
  14. include(GNUInstallDirs)
  15. include(CMakeDependentOption)
  16. set(SLIC3R_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
  17. file(TO_NATIVE_PATH "${SLIC3R_RESOURCES_DIR}" SLIC3R_RESOURCES_DIR_WIN)
  18. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  19. message(STATUS "No build type selected, default to Release")
  20. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE)
  21. endif()
  22. if(DEFINED ENV{SLIC3R_STATIC})
  23. set(SLIC3R_STATIC_INITIAL $ENV{SLIC3R_STATIC})
  24. else()
  25. if (MSVC OR MINGW OR APPLE)
  26. set(SLIC3R_STATIC_INITIAL 1)
  27. else()
  28. set(SLIC3R_STATIC_INITIAL 0)
  29. endif()
  30. endif()
  31. option(SLIC3R_STATIC "Compile PrusaSlicer with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL})
  32. option(SLIC3R_GUI "Compile PrusaSlicer with GUI components (OpenGL, wxWidgets)" 1)
  33. option(SLIC3R_FHS "Assume PrusaSlicer is to be installed in a FHS directory structure" 0)
  34. option(SLIC3R_PCH "Use precompiled headers" 1)
  35. option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1)
  36. option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1)
  37. option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0)
  38. option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0)
  39. option(SLIC3R_UBSAN "Enable UBSan on Clang and GCC" 0)
  40. option(SLIC3R_ENABLE_FORMAT_STEP "Enable compilation of STEP file support" ON)
  41. # If SLIC3R_FHS is 1 -> SLIC3R_DESKTOP_INTEGRATION is always 0, othrewise variable.
  42. CMAKE_DEPENDENT_OPTION(SLIC3R_DESKTOP_INTEGRATION "Allow perfoming desktop integration during runtime" 1 "NOT SLIC3R_FHS" 0)
  43. set(OPENVDB_FIND_MODULE_PATH "" CACHE PATH "Path to OpenVDB installation's find modules.")
  44. set(SLIC3R_GTK "2" CACHE STRING "GTK version to use with wxWidgets on Linux")
  45. set(IS_CROSS_COMPILE FALSE)
  46. if (SLIC3R_STATIC)
  47. # Prefer config scripts over find modules. This is helpful when building with
  48. # the static dependencies. Many libraries have their own export scripts
  49. # while having a Find<PkgName> module in standard cmake installation.
  50. # (e.g. CURL)
  51. set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
  52. endif ()
  53. # Dependency build management
  54. option(${PROJECT_NAME}_BUILD_DEPS "Build dependencies before the project" OFF)
  55. option(${PROJECT_NAME}_DEPS_OUTPUT_QUIET "Don't print build output for dependencies" OFF)
  56. set(${PROJECT_NAME}_DEPS_PRESET "default" CACHE STRING "Preset of the dependencies when ${PROJECT_NAME}_BUILD_DEPS is ON")
  57. set(${PROJECT_NAME}_DEPS_BUILD_DIR "" CACHE PATH "Binary dir of the dependencies build when ${PROJECT_NAME}_BUILD_DEPS is ON")
  58. if (${PROJECT_NAME}_BUILD_DEPS)
  59. include(deps/autobuild.cmake)
  60. endif ()
  61. if (APPLE)
  62. set(CMAKE_FIND_FRAMEWORK LAST)
  63. set(CMAKE_FIND_APPBUNDLE LAST)
  64. list(FIND CMAKE_OSX_ARCHITECTURES ${CMAKE_SYSTEM_PROCESSOR} _arch_idx)
  65. if (CMAKE_OSX_ARCHITECTURES AND _arch_idx LESS 0)
  66. set(IS_CROSS_COMPILE TRUE)
  67. endif ()
  68. endif ()
  69. option(SLIC3R_BUILD_SANDBOXES "Build development sandboxes" OFF)
  70. option(SLIC3R_BUILD_TESTS "Build unit tests" ON)
  71. if (IS_CROSS_COMPILE)
  72. message("Detected cross compilation setup. Tests and encoding checks will be forcedly disabled!")
  73. set(SLIC3R_PERL_XS OFF CACHE BOOL "" FORCE)
  74. set(SLIC3R_BUILD_TESTS OFF CACHE BOOL "" FORCE)
  75. endif ()
  76. # Print out the SLIC3R_* cache options
  77. get_cmake_property(_cache_vars CACHE_VARIABLES)
  78. list (SORT _cache_vars)
  79. foreach (_cache_var ${_cache_vars})
  80. if("${_cache_var}" MATCHES "^SLIC3R_")
  81. message(STATUS "${_cache_var}: ${${_cache_var}}")
  82. endif ()
  83. endforeach()
  84. if (SLIC3R_GUI)
  85. add_definitions(-DSLIC3R_GUI)
  86. endif ()
  87. if(SLIC3R_DESKTOP_INTEGRATION)
  88. add_definitions(-DSLIC3R_DESKTOP_INTEGRATION)
  89. endif ()
  90. if (MSVC AND CMAKE_CXX_COMPILER_ID STREQUAL Clang)
  91. set(IS_CLANG_CL TRUE)
  92. # clang-cl can interpret SYSTEM header paths if -imsvc is used
  93. set(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-imsvc")
  94. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall \
  95. -Wno-old-style-cast -Wno-reserved-id-macro -Wno-c++98-compat-pedantic")
  96. else ()
  97. set(IS_CLANG_CL FALSE)
  98. endif ()
  99. if (MSVC)
  100. if (SLIC3R_MSVC_COMPILE_PARALLEL AND NOT IS_CLANG_CL)
  101. add_compile_options(/MP)
  102. endif ()
  103. # /bigobj (Increase Number of Sections in .Obj file)
  104. # error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm90' or greater
  105. # Generate symbols at every build target, even for the release.
  106. add_compile_options(-bigobj -Zm520 /Zi)
  107. # Disable STL4007: Many result_type typedefs and all argument_type, first_argument_type, and second_argument_type typedefs are deprecated in C++17.
  108. #FIXME Remove this line after eigen library adapts to the new C++17 adaptor rules.
  109. add_compile_options(-D_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING)
  110. # Disable warnings on conversion from unsigned to signed (possible loss of data)
  111. # C4244: 'conversion' conversion from 'type1' to 'type2', possible loss of data. An integer type is converted to a smaller integer type.
  112. # C4267: The compiler detected a conversion from size_t to a smaller type.
  113. add_compile_options(/wd4244 /wd4267)
  114. # Enforce strict C++ conformance, so our code that compiles on MSVC also compiles on GCC and clang.
  115. add_compile_options(/permissive-)
  116. endif ()
  117. if (MINGW)
  118. add_compile_options(-Wa,-mbig-obj)
  119. endif ()
  120. if (NOT MSVC)
  121. # ARMs (Raspberry PI) use an unsigned char by default. Let's make it consistent for PrusaSlicer on all platforms.
  122. add_compile_options(-fsigned-char)
  123. endif ()
  124. # Display and check CMAKE_PREFIX_PATH
  125. message(STATUS "SLIC3R_STATIC: ${SLIC3R_STATIC}")
  126. if (NOT "${CMAKE_PREFIX_PATH}" STREQUAL "")
  127. message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH} (from cache or command line)")
  128. set(PREFIX_PATH_CHECK ${CMAKE_PREFIX_PATH})
  129. elseif (NOT "$ENV{CMAKE_PREFIX_PATH}" STREQUAL "")
  130. message(STATUS "CMAKE_PREFIX_PATH: $ENV{CMAKE_PREFIX_PATH} (from environment)")
  131. set(PREFIX_PATH_CHECK $ENV{CMAKE_PREFIX_PATH})
  132. else ()
  133. message(STATUS "CMAKE_PREFIX_PATH: (default)")
  134. endif ()
  135. foreach (DIR ${PREFIX_PATH_CHECK})
  136. if (NOT EXISTS "${DIR}")
  137. message(WARNING "CMAKE_PREFIX_PATH element doesn't exist: ${DIR}")
  138. endif ()
  139. endforeach ()
  140. # Add our own cmake module path.
  141. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/)
  142. enable_testing ()
  143. # Enable C++17 language standard.
  144. set(CMAKE_CXX_STANDARD 17)
  145. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  146. if(NOT WIN32)
  147. # Add DEBUG flags to debug builds.
  148. add_compile_options("$<$<CONFIG:DEBUG>:-DDEBUG>")
  149. endif()
  150. # To be able to link libslic3r with the Perl XS module.
  151. # Once we get rid of Perl and libslic3r is linked statically, we can get rid of -fPIC
  152. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  153. # WIN10SDK_PATH is used to point CMake to the WIN10 SDK installation directory.
  154. # We pick it from environment if it is not defined in another way
  155. if(WIN32)
  156. if(NOT DEFINED WIN10SDK_PATH)
  157. if(DEFINED ENV{WIN10SDK_PATH})
  158. set(WIN10SDK_PATH "$ENV{WIN10SDK_PATH}")
  159. endif()
  160. endif()
  161. if(DEFINED WIN10SDK_PATH)
  162. if (EXISTS "${WIN10SDK_PATH}/include/winrt/windows.graphics.printing3d.h")
  163. set(WIN10SDK_INCLUDE_PATH "${WIN10SDK_PATH}/Include")
  164. else()
  165. message("WIN10SDK_PATH is invalid: ${WIN10SDK_PATH}")
  166. message("${WIN10SDK_PATH}/include/winrt/windows.graphics.printing3d.h was not found")
  167. message("STL fixing by WinSDK will not be compiled")
  168. unset(WIN10SDK_PATH)
  169. endif()
  170. else()
  171. # Try to use the default Windows 10 SDK path.
  172. set(WIN10SDK_INCLUDE_PATH "$ENV{WindowsSdkDir}/Include/$ENV{WindowsSDKVersion}")
  173. if (NOT EXISTS "${WIN10SDK_INCLUDE_PATH}/winrt/windows.graphics.printing3d.h")
  174. message("${WIN10SDK_INCLUDE_PATH}/winrt/windows.graphics.printing3d.h was not found")
  175. message("STL fixing by WinSDK will not be compiled")
  176. unset(WIN10SDK_INCLUDE_PATH)
  177. endif()
  178. endif()
  179. if(WIN10SDK_INCLUDE_PATH)
  180. message("Building with Win10 STL fixing service support")
  181. add_definitions(-DHAS_WIN10SDK)
  182. include_directories("${WIN10SDK_INCLUDE_PATH}")
  183. else()
  184. message("Building without Win10 STL fixing service support")
  185. endif()
  186. endif()
  187. if (APPLE)
  188. message("OS X SDK Path: ${CMAKE_OSX_SYSROOT}")
  189. if (CMAKE_OSX_DEPLOYMENT_TARGET)
  190. message("OS X Deployment Target: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
  191. else ()
  192. message("OS X Deployment Target: (default)")
  193. endif ()
  194. endif ()
  195. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  196. find_package(PkgConfig REQUIRED)
  197. if (CMAKE_VERSION VERSION_LESS "3.1")
  198. # Workaround for an old CMake, which does not understand CMAKE_CXX_STANDARD.
  199. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  200. endif()
  201. # Boost on Raspberry-Pi does not link to pthreads.
  202. set(THREADS_PREFER_PTHREAD_FLAG ON)
  203. find_package(Threads REQUIRED)
  204. find_package(DBus REQUIRED)
  205. include_directories(${DBUS_INCLUDE_DIRS})
  206. endif()
  207. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX)
  208. # Adding -fext-numeric-literals to enable GCC extensions on definitions of quad float literals, which are required by Boost.
  209. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fext-numeric-literals" )
  210. endif()
  211. if (NOT MSVC AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang"))
  212. if (NOT MINGW)
  213. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall" )
  214. endif ()
  215. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder" )
  216. # On GCC and Clang, no return from a non-void function is a warning only. Here, we make it an error.
  217. add_compile_options(-Werror=return-type)
  218. # removes LOTS of extraneous Eigen warnings (GCC only supports it since 6.1)
  219. # https://eigen.tuxfamily.org/bz/show_bug.cgi?id=1221
  220. if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0)
  221. add_compile_options(-Wno-ignored-attributes) # Tamas: Eigen include dirs are marked as SYSTEM
  222. endif()
  223. # Clang reports legacy OpenGL calls as deprecated. Turn off the warning for now
  224. # to reduce the clutter, we know about this one. It should be reenabled after
  225. # we finally get rid of the deprecated code.
  226. if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  227. add_compile_options(-Wno-deprecated-declarations)
  228. endif()
  229. # Clang reports misleading indentation for some IF blocks because of mixing tabs with spaces.
  230. if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  231. add_compile_options(-Wno-misleading-indentation)
  232. endif()
  233. #GCC generates loads of -Wunknown-pragmas when compiling igl. The fix is not easy due to a bug in gcc, see
  234. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66943 or
  235. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53431
  236. # We will turn the warning of for GCC for now:
  237. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  238. add_compile_options(-Wno-unknown-pragmas)
  239. endif()
  240. endif()
  241. if (SLIC3R_ASAN)
  242. # ASAN should be available on MSVC starting with Visual Studio 2019 16.9
  243. # https://devblogs.microsoft.com/cppblog/address-sanitizer-for-msvc-now-generally-available/
  244. add_compile_options(-fsanitize=address)
  245. if (NOT MSVC)
  246. add_compile_options(-fno-omit-frame-pointer)
  247. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
  248. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
  249. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address")
  250. endif ()
  251. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  252. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
  253. endif ()
  254. endif ()
  255. if (SLIC3R_UBSAN)
  256. # Stacktrace for every report is enabled by default. It can be disabled by running PrusaSlicer with "UBSAN_OPTIONS=print_stacktrace=0".
  257. # Define macro SLIC3R_UBSAN to allow detection in the source code if this sanitizer is enabled.
  258. add_compile_definitions(SLIC3R_UBSAN)
  259. # Clang supports much more useful checks than GCC, so when Clang is detected, another checks will be enabled.
  260. # List of what GCC is checking: https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html
  261. # List of what Clang is checking: https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html
  262. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  263. set(_ubsan_flags "-fsanitize=undefined,integer")
  264. else ()
  265. set(_ubsan_flags "-fsanitize=undefined")
  266. endif ()
  267. add_compile_options(${_ubsan_flags} -fno-omit-frame-pointer)
  268. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_ubsan_flags}")
  269. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${_ubsan_flags}")
  270. set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${_ubsan_flags}")
  271. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  272. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lubsan")
  273. endif ()
  274. endif ()
  275. if (APPLE)
  276. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror=partial-availability -Werror=unguarded-availability -Werror=unguarded-availability-new")
  277. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=partial-availability -Werror=unguarded-availability -Werror=unguarded-availability-new")
  278. endif ()
  279. # Where all the bundled libraries reside?
  280. set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
  281. set(LIBDIR_BIN ${CMAKE_CURRENT_BINARY_DIR}/src)
  282. # For the bundled boost libraries (boost::nowide)
  283. include_directories(${LIBDIR})
  284. # For generated header files
  285. include_directories(${LIBDIR_BIN}/platform)
  286. if(WIN32)
  287. add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
  288. if(MSVC)
  289. # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking.
  290. add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_USE_WINAPI_VERSION=0x601 -DBOOST_SYSTEM_USE_UTF8 )
  291. # Force the source code encoding to UTF-8. See PrusaSlicer GH pull request #5583
  292. add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
  293. add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
  294. endif(MSVC)
  295. endif(WIN32)
  296. add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE -DWXINTL_NO_GETTEXT_MACRO)
  297. # Disable unsafe implicit wxString to const char* / std::string and vice versa. This implicit conversion breaks the UTF-8 encoding quite often.
  298. add_definitions(-DwxNO_UNSAFE_WXSTRING_CONV)
  299. # Find and configure boost
  300. if(SLIC3R_STATIC)
  301. # Use static boost libraries.
  302. set(Boost_USE_STATIC_LIBS ON)
  303. # Use boost libraries linked statically to the C++ runtime.
  304. # set(Boost_USE_STATIC_RUNTIME ON)
  305. endif()
  306. #set(Boost_DEBUG ON)
  307. # set(Boost_COMPILER "-mgw81")
  308. # boost::process was introduced first in version 1.64.0,
  309. # boost::beast::detail::base64 was introduced first in version 1.66.0
  310. set(MINIMUM_BOOST_VERSION "1.66.0")
  311. set(_boost_components "system;filesystem;thread;log;locale;regex;chrono;atomic;date_time;iostreams")
  312. find_package(Boost ${MINIMUM_BOOST_VERSION} REQUIRED COMPONENTS ${_boost_components})
  313. add_library(boost_libs INTERFACE)
  314. add_library(boost_headeronly INTERFACE)
  315. if (APPLE)
  316. # BOOST_ASIO_DISABLE_KQUEUE : prevents a Boost ASIO bug on OS X: https://svn.boost.org/trac/boost/ticket/5339
  317. target_compile_definitions(boost_headeronly INTERFACE BOOST_ASIO_DISABLE_KQUEUE)
  318. endif()
  319. if(NOT SLIC3R_STATIC)
  320. target_compile_definitions(boost_headeronly INTERFACE BOOST_LOG_DYN_LINK)
  321. endif()
  322. function(slic3r_remap_configs targets from_Cfg to_Cfg)
  323. if(MSVC)
  324. string(TOUPPER ${from_Cfg} from_CFG)
  325. foreach(tgt ${targets})
  326. if(TARGET ${tgt})
  327. set_target_properties(${tgt} PROPERTIES MAP_IMPORTED_CONFIG_${from_CFG} ${to_Cfg})
  328. endif()
  329. endforeach()
  330. endif()
  331. endfunction()
  332. if(TARGET Boost::system)
  333. message(STATUS "Boost::boost exists")
  334. target_link_libraries(boost_headeronly INTERFACE Boost::boost)
  335. # Only from cmake 3.12
  336. # list(TRANSFORM _boost_components PREPEND Boost:: OUTPUT_VARIABLE _boost_targets)
  337. set(_boost_targets "")
  338. foreach(comp ${_boost_components})
  339. list(APPEND _boost_targets "Boost::${comp}")
  340. endforeach()
  341. target_link_libraries(boost_libs INTERFACE
  342. boost_headeronly # includes the custom compile definitions as well
  343. ${_boost_targets}
  344. )
  345. slic3r_remap_configs("${_boost_targets}" RelWithDebInfo Release)
  346. else()
  347. target_include_directories(boost_headeronly INTERFACE ${Boost_INCLUDE_DIRS})
  348. target_link_libraries(boost_libs INTERFACE boost_headeronly ${Boost_LIBRARIES})
  349. endif()
  350. # Find and configure intel-tbb
  351. if(SLIC3R_STATIC)
  352. set(TBB_STATIC 1)
  353. endif()
  354. set(TBB_DEBUG 1)
  355. find_package(TBB REQUIRED)
  356. slic3r_remap_configs(TBB::tbb RelWithDebInfo Release)
  357. slic3r_remap_configs(TBB::tbbmalloc RelWithDebInfo Release)
  358. # include_directories(${TBB_INCLUDE_DIRS})
  359. # add_definitions(${TBB_DEFINITIONS})
  360. # if(MSVC)
  361. # # Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
  362. # add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE)
  363. # endif()
  364. # The Intel TBB library will use the std::exception_ptr feature of C++11.
  365. # add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)
  366. find_package(CURL REQUIRED)
  367. add_library(libcurl INTERFACE)
  368. target_link_libraries(libcurl INTERFACE CURL::libcurl)
  369. # Fixing curl's cmake config script bugs
  370. if (NOT WIN32)
  371. # Required by libcurl
  372. find_package(ZLIB REQUIRED)
  373. target_link_libraries(libcurl INTERFACE ZLIB::ZLIB)
  374. else()
  375. target_link_libraries(libcurl INTERFACE crypt32)
  376. endif()
  377. ## OPTIONAL packages
  378. # Find eigen3 or use bundled version
  379. if (NOT SLIC3R_STATIC)
  380. find_package(Eigen3 3.3)
  381. endif ()
  382. if (NOT EIGEN3_FOUND)
  383. set(EIGEN3_FOUND 1)
  384. set(EIGEN3_INCLUDE_DIR ${LIBDIR}/eigen/)
  385. endif ()
  386. include_directories(BEFORE SYSTEM ${EIGEN3_INCLUDE_DIR})
  387. # Find expat. We have our overriden FindEXPAT which exports libexpat target
  388. # no matter what.
  389. find_package(EXPAT REQUIRED)
  390. add_library(libexpat INTERFACE)
  391. if (TARGET EXPAT::EXPAT )
  392. target_link_libraries(libexpat INTERFACE EXPAT::EXPAT)
  393. elseif(TARGET expat::expat)
  394. target_link_libraries(libexpat INTERFACE expat::expat)
  395. endif ()
  396. find_package(PNG REQUIRED)
  397. set(OpenGL_GL_PREFERENCE "LEGACY")
  398. find_package(OpenGL REQUIRED)
  399. # Find glew or use bundled version
  400. if (SLIC3R_STATIC AND NOT SLIC3R_STATIC_EXCLUDE_GLEW)
  401. set(GLEW_USE_STATIC_LIBS ON)
  402. set(GLEW_VERBOSE ON)
  403. endif()
  404. find_package(GLEW REQUIRED)
  405. # Find the Cereal serialization library
  406. find_package(cereal REQUIRED)
  407. add_library(libcereal INTERFACE)
  408. if (NOT TARGET cereal::cereal)
  409. target_link_libraries(libcereal INTERFACE cereal)
  410. else()
  411. target_link_libraries(libcereal INTERFACE cereal::cereal)
  412. endif()
  413. # l10n
  414. set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization")
  415. add_custom_target(gettext_make_pot
  416. COMMAND xgettext --keyword=L --keyword=_L --keyword=_u8L --keyword=L_CONTEXT:1,2c --keyword=_L_PLURAL:1,2 --add-comments=TRN --from-code=UTF-8 --debug --boost
  417. -f "${L10N_DIR}/list.txt"
  418. -o "${L10N_DIR}/PrusaSlicer.pot"
  419. COMMAND hintsToPot ${SLIC3R_RESOURCES_DIR} ${L10N_DIR}
  420. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  421. COMMENT "Generate pot file from strings in the source tree"
  422. )
  423. add_custom_target(gettext_merge_community_po_with_pot
  424. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  425. COMMENT "Merge community po with new generated pot file"
  426. )
  427. file(GLOB L10N_PO_FILES "${L10N_DIR}/*/PrusaSlicer*.po")
  428. # list of names of directories, which are licalized by PS internally
  429. list(APPEND PS_L10N_DIRS "cs" "de" "es" "fr" "it" "ja" "pl")
  430. foreach(po_file ${L10N_PO_FILES})
  431. GET_FILENAME_COMPONENT(po_dir "${po_file}" DIRECTORY)
  432. GET_FILENAME_COMPONENT(po_dir_name "${po_dir}" NAME)
  433. list(FIND PS_L10N_DIRS ${po_dir_name} found_dir_id)
  434. # found_dir_id==-1 means that po_dir_name wasn't found in PS_L10N_DIRS
  435. if(found_dir_id LESS 0)
  436. add_custom_command(
  437. TARGET gettext_merge_community_po_with_pot PRE_BUILD
  438. COMMAND msgmerge -N -o ${po_file} ${po_file} "${L10N_DIR}/PrusaSlicer.pot"
  439. # delete obsolete lines from resulting PO to avoid conflicts after a merging of it with wxWidgets.po
  440. COMMAND msgattrib --no-obsolete -o ${po_file} ${po_file}
  441. DEPENDS ${po_file}
  442. )
  443. endif()
  444. endforeach()
  445. add_custom_target(gettext_concat_wx_po_with_po
  446. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  447. COMMENT "Concatenate and merge wxWidgets localization po with PrusaSlicer po file"
  448. )
  449. file(GLOB L10N_PO_FILES "${L10N_DIR}/*/PrusaSlicer*.po")
  450. foreach(po_file ${L10N_PO_FILES})
  451. GET_FILENAME_COMPONENT(po_dir "${po_file}" DIRECTORY)
  452. GET_FILENAME_COMPONENT(po_dir_name "${po_dir}" NAME)
  453. SET(wx_po_file "${L10N_DIR}/wx_locale/${po_dir_name}.po")
  454. #SET(po_new_file "${po_dir}/PrusaSlicer_.po")
  455. add_custom_command(
  456. TARGET gettext_concat_wx_po_with_po PRE_BUILD
  457. COMMAND msgcat --use-first -o ${po_file} ${po_file} ${wx_po_file}
  458. # delete obsolete lines from resulting PO
  459. COMMAND msgattrib --no-obsolete -o ${po_file} ${po_file}
  460. DEPENDS ${po_file}
  461. )
  462. endforeach()
  463. add_custom_target(gettext_po_to_mo
  464. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  465. COMMENT "Generate localization mo files (binary) from po files (texts)"
  466. )
  467. file(GLOB L10N_PO_FILES "${L10N_DIR}/*/PrusaSlicer*.po")
  468. foreach(po_file ${L10N_PO_FILES})
  469. GET_FILENAME_COMPONENT(po_dir "${po_file}" DIRECTORY)
  470. SET(mo_file "${po_dir}/PrusaSlicer.mo")
  471. add_custom_command(
  472. TARGET gettext_po_to_mo PRE_BUILD
  473. COMMAND msgfmt ARGS --check-format -o ${mo_file} ${po_file}
  474. #COMMAND msgfmt ARGS --check-compatibility -o ${mo_file} ${po_file}
  475. DEPENDS ${po_file}
  476. )
  477. endforeach()
  478. find_package(NLopt 1.4 REQUIRED)
  479. slic3r_remap_configs(NLopt::nlopt RelWithDebInfo Release)
  480. if(SLIC3R_STATIC)
  481. set(OPENVDB_USE_STATIC_LIBS ON)
  482. set(USE_BLOSC TRUE)
  483. endif ()
  484. find_package(OpenVDB 5.0 COMPONENTS openvdb)
  485. if(OpenVDB_FOUND)
  486. slic3r_remap_configs(IlmBase::Half RelWithDebInfo Release)
  487. slic3r_remap_configs(Blosc::blosc RelWithDebInfo Release)
  488. else ()
  489. message(FATAL_ERROR "OpenVDB could not be found with the bundled find module. "
  490. "You can try to specify the find module location of your "
  491. "OpenVDB installation with the OPENVDB_FIND_MODULE_PATH cache variable.")
  492. endif ()
  493. set(TOP_LEVEL_PROJECT_DIR ${PROJECT_SOURCE_DIR})
  494. function(prusaslicer_copy_dlls target)
  495. if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
  496. set(_bits 64)
  497. elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
  498. set(_bits 32)
  499. endif ()
  500. get_property(_is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  501. get_target_property(_alt_out_dir ${target} RUNTIME_OUTPUT_DIRECTORY)
  502. if (_alt_out_dir)
  503. set (_out_dir "${_alt_out_dir}")
  504. elseif (_is_multi)
  505. set (_out_dir "$<TARGET_PROPERTY:${target},BINARY_DIR>/$<CONFIG>")
  506. else ()
  507. set (_out_dir "$<TARGET_PROPERTY:${target},BINARY_DIR>")
  508. endif ()
  509. # This has to be a separate target due to the windows command line lenght limits
  510. add_custom_command(TARGET ${target} POST_BUILD
  511. COMMAND ${CMAKE_COMMAND} -E copy ${TOP_LEVEL_PROJECT_DIR}/deps/+GMP/gmp/lib/win${_bits}/libgmp-10.dll ${_out_dir}
  512. COMMENT "Copy gmp runtime to build tree"
  513. VERBATIM)
  514. add_custom_command(TARGET ${target} POST_BUILD
  515. COMMAND ${CMAKE_COMMAND} -E copy ${TOP_LEVEL_PROJECT_DIR}/deps/+MPFR/mpfr/lib/win${_bits}/libmpfr-4.dll ${_out_dir}
  516. COMMENT "Copy mpfr runtime to build tree"
  517. VERBATIM)
  518. endfunction()
  519. # libslic3r, PrusaSlicer GUI and the PrusaSlicer executable.
  520. add_subdirectory(src)
  521. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT PrusaSlicer_app_console)
  522. add_dependencies(gettext_make_pot hintsToPot)
  523. # Perl bindings, currently only used for the unit / integration tests of libslic3r.
  524. # Also runs the unit / integration tests.
  525. #FIXME Port the tests into C++ to finally get rid of the Perl!
  526. if (SLIC3R_PERL_XS)
  527. add_subdirectory(xs)
  528. endif ()
  529. if(SLIC3R_BUILD_SANDBOXES)
  530. add_subdirectory(sandboxes)
  531. endif()
  532. if(SLIC3R_BUILD_TESTS)
  533. add_subdirectory(tests)
  534. endif()
  535. # Resources install target, configure fhs.hpp on UNIX
  536. if (WIN32)
  537. install(DIRECTORY "${SLIC3R_RESOURCES_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/resources")
  538. elseif (SLIC3R_FHS)
  539. # CMAKE_INSTALL_FULL_DATAROOTDIR: read-only architecture-independent data root (share)
  540. set(SLIC3R_FHS_RESOURCES "${CMAKE_INSTALL_FULL_DATAROOTDIR}/PrusaSlicer")
  541. install(DIRECTORY ${SLIC3R_RESOURCES_DIR}/ DESTINATION ${SLIC3R_FHS_RESOURCES}
  542. PATTERN "*/udev" EXCLUDE
  543. )
  544. install(FILES src/platform/unix/PrusaSlicer.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
  545. install(FILES src/platform/unix/PrusaGcodeviewer.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
  546. foreach(SIZE 32 128 192)
  547. install(FILES ${SLIC3R_RESOURCES_DIR}/icons/PrusaSlicer_${SIZE}px.png
  548. DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${SIZE}x${SIZE}/apps RENAME PrusaSlicer.png
  549. )
  550. install(FILES ${SLIC3R_RESOURCES_DIR}/icons/PrusaSlicer-gcodeviewer_${SIZE}px.png
  551. DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/${SIZE}x${SIZE}/apps RENAME PrusaSlicer-gcodeviewer.png
  552. )
  553. endforeach()
  554. install(DIRECTORY ${SLIC3R_RESOURCES_DIR}/udev/ DESTINATION lib/udev/rules.d)
  555. else ()
  556. install(FILES src/platform/unix/PrusaSlicer.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/resources/applications)
  557. install(FILES src/platform/unix/PrusaGcodeviewer.desktop DESTINATION ${CMAKE_INSTALL_PREFIX}/resources/applications)
  558. install(DIRECTORY "${SLIC3R_RESOURCES_DIR}/" DESTINATION "${CMAKE_INSTALL_PREFIX}/resources")
  559. endif ()
  560. configure_file(${LIBDIR}/platform/unix/fhs.hpp.in ${LIBDIR_BIN}/platform/unix/fhs.hpp)