CMakeLists.txt 27 KB

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