CMakeLists.txt 28 KB

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