CMakeLists.txt 23 KB

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