CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. project(Slic3r)
  2. cmake_minimum_required(VERSION 3.2)
  3. include("version.inc")
  4. set(SLIC3R_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources")
  5. file(TO_NATIVE_PATH "${SLIC3R_RESOURCES_DIR}" SLIC3R_RESOURCES_DIR_WIN)
  6. if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  7. message(STATUS "No build type selected, default to Release")
  8. set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE)
  9. endif()
  10. if(DEFINED ENV{SLIC3R_STATIC})
  11. set(SLIC3R_STATIC_INITIAL $ENV{SLIC3R_STATIC})
  12. else()
  13. if (MSVC OR MINGW OR APPLE)
  14. set(SLIC3R_STATIC_INITIAL 1)
  15. else()
  16. set(SLIC3R_STATIC_INITIAL 0)
  17. endif()
  18. endif()
  19. option(SLIC3R_STATIC "Compile Slic3r with static libraries (Boost, TBB, glew)" ${SLIC3R_STATIC_INITIAL})
  20. option(SLIC3R_GUI "Compile Slic3r with GUI components (OpenGL, wxWidgets)" 1)
  21. option(SLIC3R_PROFILE "Compile Slic3r with an invasive Shiny profiler" 0)
  22. option(SLIC3R_MSVC_COMPILE_PARALLEL "Compile on Visual Studio in parallel" 1)
  23. option(SLIC3R_MSVC_PDB "Generate PDB files on MSVC in Release mode" 1)
  24. option(SLIC3R_PERL_XS "Compile XS Perl module and enable Perl unit and integration tests" 0)
  25. option(SLIC3R_ASAN "Enable ASan on Clang and GCC" 0)
  26. option(SLIC3R_SYNTAXONLY "Only perform source code correctness checking, no binary output (UNIX only)" 0)
  27. # Proposal for C++ unit tests and sandboxes
  28. option(SLIC3R_BUILD_SANDBOXES "Build development sandboxes" OFF)
  29. option(SLIC3R_BUILD_TESTS "Build unit tests" OFF)
  30. if (MSVC)
  31. if (SLIC3R_MSVC_COMPILE_PARALLEL)
  32. add_compile_options(/MP)
  33. endif ()
  34. # /bigobj (Increase Number of Sections in .Obj file)
  35. # error C3859: virtual memory range for PCH exceeded; please recompile with a command line option of '-Zm90' or greater
  36. add_compile_options(-bigobj -Zm316)
  37. endif ()
  38. message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
  39. # Add our own cmake module path.
  40. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/)
  41. enable_testing ()
  42. # Enable C++11 language standard.
  43. set(CMAKE_CXX_STANDARD 11)
  44. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  45. set(CMAKE_C_STANDARD 11)
  46. set(CMAKE_C_STANDARD_REQUIRED ON)
  47. # To be able to link libslic3r with the Perl XS module.
  48. # Once we get rid of Perl and libslic3r is linked statically, we can get rid of -fPIC
  49. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  50. # WIN10SDK_PATH is used to point CMake to the WIN10 SDK installation directory.
  51. # We pick it from environment if it is not defined in another way
  52. if(WIN32)
  53. if(NOT DEFINED WIN10SDK_PATH)
  54. if(DEFINED ENV{WIN10SDK_PATH})
  55. set(WIN10SDK_PATH "$ENV{WIN10SDK_PATH}")
  56. endif()
  57. endif()
  58. if(DEFINED WIN10SDK_PATH AND NOT EXISTS "${WIN10SDK_PATH}/include/winrt/windows.graphics.printing3d.h")
  59. message("WIN10SDK_PATH is invalid: ${WIN10SDK_PATH}")
  60. message("${WIN10SDK_PATH}/include/winrt/windows.graphics.printing3d.h was not found")
  61. message("STL fixing by the Netfabb service will not be compiled")
  62. unset(WIN10SDK_PATH)
  63. endif()
  64. if(WIN10SDK_PATH)
  65. message("Building with Win10 Netfabb STL fixing service support")
  66. add_definitions(-DHAS_WIN10SDK)
  67. include_directories("${WIN10SDK_PATH}/Include")
  68. else()
  69. message("Building without Win10 Netfabb STL fixing service support")
  70. endif()
  71. endif()
  72. if (APPLE)
  73. if (NOT CMAKE_OSX_DEPLOYMENT_TARGET)
  74. set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "OS X Deployment target (SDK version)" FORCE)
  75. endif ()
  76. message(STATUS "Mac OS deployment target (SDK version): ${CMAKE_OSX_DEPLOYMENT_TARGET}")
  77. endif ()
  78. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  79. # Workaround for an old CMake, which does not understand CMAKE_CXX_STANDARD.
  80. add_compile_options(-std=c++11 -Wall -Wno-reorder)
  81. find_package(PkgConfig REQUIRED)
  82. endif()
  83. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX)
  84. # Adding -fext-numeric-literals to enable GCC extensions on definitions of quad float literals, which are required by Boost.
  85. add_compile_options(-fext-numeric-literals)
  86. if (SLIC3R_SYNTAXONLY)
  87. set(CMAKE_CXX_ARCHIVE_CREATE "true")
  88. set(CMAKE_C_ARCHIVE_CREATE "true")
  89. set(CMAKE_CXX_ARCHIVE_APPEND "true")
  90. set(CMAKE_C_ARCHIVE_APPEND "true")
  91. set(CMAKE_RANLIB "true")
  92. set(CMAKE_C_LINK_EXECUTABLE "true")
  93. set(CMAKE_CXX_LINK_EXECUTABLE "true")
  94. set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> -fsyntax-only <DEFINES> <INCLUDES> <FLAGS> -c <SOURCE> && touch <OBJECT>")
  95. set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -fsyntax-only <DEFINES> <INCLUDES> <FLAGS> -c <SOURCE> && touch <OBJECT>")
  96. endif ()
  97. endif()
  98. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  99. # On GCC and Clang, no return from a non-void function is a warning only. Here, we make it an error.
  100. add_compile_options(-Werror=return-type)
  101. if (SLIC3R_ASAN)
  102. add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
  103. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
  104. set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
  105. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
  106. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lasan")
  107. endif ()
  108. endif ()
  109. endif()
  110. # Where all the bundled libraries reside?
  111. set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/)
  112. # For the bundled boost libraries (boost::nowide)
  113. include_directories(${LIBDIR})
  114. # For libslic3r.h
  115. include_directories(${LIBDIR}/clipper ${LIBDIR}/polypartition)
  116. #set(CMAKE_INCLUDE_CURRENT_DIR ON)
  117. if(WIN32)
  118. # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking.
  119. add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -DBOOST_ALL_NO_LIB -DBOOST_USE_WINAPI_VERSION=0x601 -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)
  120. endif()
  121. add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE -DWXINTL_NO_GETTEXT_MACRO)
  122. if (SLIC3R_PROFILE)
  123. message("Slic3r will be built with a Shiny invasive profiler")
  124. add_definitions(-DSLIC3R_PROFILE)
  125. endif ()
  126. # Disable optimization even with debugging on.
  127. if (0)
  128. message(STATUS "Perl compiled without optimization. Disabling optimization for the Slic3r build.")
  129. message("Old CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
  130. message("Old CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELEASE}")
  131. message("Old CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS_RELEASE}")
  132. set(CMAKE_CXX_FLAGS_RELEASE "/MD /Od /Zi /EHsc /DWIN32 /DTBB_USE_ASSERT")
  133. set(CMAKE_C_FLAGS_RELEASE "/MD /Od /Zi /DWIN32 /DTBB_USE_ASSERT")
  134. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Od /Zi /EHsc /DWIN32 /DTBB_USE_ASSERT")
  135. set(CMAKE_C_FLAGS_RELWITHDEBINFO "/MD /Od /Zi /DWIN32 /DTBB_USE_ASSERT")
  136. set(CMAKE_CXX_FLAGS "/MD /Od /Zi /EHsc /DWIN32 /DTBB_USE_ASSERT")
  137. set(CMAKE_C_FLAGS "/MD /Od /Zi /DWIN32 /DTBB_USE_ASSERT")
  138. endif()
  139. # Find and configure boost
  140. if(SLIC3R_STATIC)
  141. # Use static boost libraries.
  142. set(Boost_USE_STATIC_LIBS ON)
  143. # Use boost libraries linked statically to the C++ runtime.
  144. # set(Boost_USE_STATIC_RUNTIME ON)
  145. endif()
  146. #set(Boost_DEBUG ON)
  147. # set(Boost_COMPILER "-vc120")
  148. find_package(Boost REQUIRED COMPONENTS system filesystem thread log locale regex)
  149. if(Boost_FOUND)
  150. include_directories(${Boost_INCLUDE_DIRS})
  151. if (APPLE)
  152. # BOOST_ASIO_DISABLE_KQUEUE : prevents a Boost ASIO bug on OS X: https://svn.boost.org/trac/boost/ticket/5339
  153. add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
  154. endif()
  155. if(NOT SLIC3R_STATIC)
  156. add_definitions(-DBOOST_LOG_DYN_LINK)
  157. endif()
  158. endif()
  159. # Find and configure intel-tbb
  160. if(SLIC3R_STATIC)
  161. set(TBB_STATIC 1)
  162. endif()
  163. set(TBB_DEBUG 1)
  164. find_package(TBB REQUIRED)
  165. include_directories(${TBB_INCLUDE_DIRS})
  166. add_definitions(${TBB_DEFINITIONS})
  167. if(MSVC)
  168. # Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
  169. add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE)
  170. endif()
  171. # The Intel TBB library will use the std::exception_ptr feature of C++11.
  172. add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)
  173. #set(CURL_DEBUG 1)
  174. find_package(CURL REQUIRED)
  175. include_directories(${CURL_INCLUDE_DIRS})
  176. if (SLIC3R_STATIC)
  177. if (NOT APPLE)
  178. # libcurl is always linked dynamically to the system libcurl on OSX.
  179. # On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
  180. add_definitions(-DCURL_STATICLIB)
  181. endif()
  182. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  183. # As of now, our build system produces a statically linked libcurl,
  184. # which links the OpenSSL library dynamically.
  185. find_package(OpenSSL REQUIRED)
  186. message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
  187. message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
  188. include_directories(${OPENSSL_INCLUDE_DIR})
  189. endif()
  190. endif()
  191. ## OPTIONAL packages
  192. # Find eigen3 or use bundled version
  193. if (NOT SLIC3R_STATIC)
  194. find_package(Eigen3)
  195. endif ()
  196. if (NOT Eigen3_FOUND)
  197. set(Eigen3_FOUND 1)
  198. set(EIGEN3_INCLUDE_DIR ${LIBDIR}/eigen/)
  199. endif ()
  200. include_directories(${EIGEN3_INCLUDE_DIR})
  201. # Find expat or use bundled version
  202. # Always use the system libexpat on Linux.
  203. if (NOT SLIC3R_STATIC OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
  204. find_package(EXPAT)
  205. endif ()
  206. if (NOT EXPAT_FOUND)
  207. add_library(expat STATIC
  208. ${LIBDIR}/expat/xmlparse.c
  209. ${LIBDIR}/expat/xmlrole.c
  210. ${LIBDIR}/expat/xmltok.c
  211. )
  212. set(EXPAT_FOUND 1)
  213. set(EXPAT_INCLUDE_DIRS ${LIBDIR}/expat/)
  214. set(EXPAT_LIBRARIES expat)
  215. endif ()
  216. include_directories(${EXPAT_INCLUDE_DIRS})
  217. # Find glew or use bundled version
  218. if (NOT SLIC3R_STATIC)
  219. find_package(GLEW)
  220. endif ()
  221. if (NOT GLEW_FOUND)
  222. add_library(glew STATIC ${LIBDIR}/glew/src/glew.c)
  223. set(GLEW_FOUND 1)
  224. set(GLEW_INCLUDE_DIRS ${LIBDIR}/glew/include/)
  225. set(GLEW_LIBRARIES glew)
  226. add_definitions(-DGLEW_STATIC)
  227. endif ()
  228. include_directories(${GLEW_INCLUDE_DIRS})
  229. # l10n
  230. set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization")
  231. add_custom_target(pot
  232. # FIXME: file list stale
  233. COMMAND xgettext --keyword=L --from-code=UTF-8 --debug
  234. -f "${L10N_DIR}/list.txt"
  235. -o "${L10N_DIR}/Slic3rPE.pot"
  236. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  237. COMMENT "Generate pot file from strings in the source tree"
  238. )
  239. # libslic3r, Slic3r GUI and the slic3r executable.
  240. add_subdirectory(src)
  241. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT slic3r_app_console)
  242. # Perl bindings, currently only used for the unit / integration tests of libslic3r.
  243. # Also runs the unit / integration tests.
  244. #FIXME Port the tests into C++ to finally get rid of the Perl!
  245. if (SLIC3R_PERL_XS)
  246. add_subdirectory(xs)
  247. endif ()
  248. if(SLIC3R_BUILD_SANDBOXES)
  249. add_subdirectory(sandboxes)
  250. endif()
  251. if(SLIC3R_BUILD_TESTS)
  252. add_subdirectory(tests)
  253. endif()
  254. file(GLOB MyVar var/*.png)
  255. install(FILES ${MyVar} DESTINATION share/slic3r-prusa3d)