CMakeLists.txt 19 KB

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