CMakeLists.txt 27 KB

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