CMakeLists.txt 23 KB

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