CMakeLists.txt 19 KB

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