CMakeLists.txt 26 KB

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