CMakeLists.txt 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. if (MSVC AND SLIC3R_MSVC_COMPILE_PARALLEL)
  25. add_compile_options(/MP)
  26. endif ()
  27. # CMAKE_PREFIX_PATH is used to point CMake to the remaining dependencies (Boost, TBB, ...)
  28. # We pick it from environment if it is not defined in another way
  29. if(NOT DEFINED CMAKE_PREFIX_PATH)
  30. if(DEFINED ENV{CMAKE_PREFIX_PATH})
  31. set(CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
  32. endif()
  33. endif()
  34. # Add our own cmake module path.
  35. list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules/)
  36. enable_testing ()
  37. # Enable C++11 language standard.
  38. set(CMAKE_CXX_STANDARD 11)
  39. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  40. set(CMAKE_C_STANDARD 11)
  41. set(CMAKE_C_STANDARD_REQUIRED ON)
  42. # To be able to link libslic3r with the Perl XS module.
  43. # Once we get rid of Perl and libslic3r is linked statically, we can get rid of -fPIC
  44. set(CMAKE_POSITION_INDEPENDENT_CODE ON)
  45. # WIN10SDK_PATH is used to point CMake to the WIN10 SDK installation directory.
  46. # We pick it from environment if it is not defined in another way
  47. if(WIN32)
  48. if(NOT DEFINED WIN10SDK_PATH)
  49. if(DEFINED ENV{WIN10SDK_PATH})
  50. set(WIN10SDK_PATH "$ENV{WIN10SDK_PATH}")
  51. endif()
  52. endif()
  53. if(DEFINED WIN10SDK_PATH AND NOT EXISTS "${WIN10SDK_PATH}/include/winrt/windows.graphics.printing3d.h")
  54. message("WIN10SDK_PATH is invalid: ${WIN10SDK_PATH}")
  55. message("${WIN10SDK_PATH}/include/winrt/windows.graphics.printing3d.h was not found")
  56. message("STL fixing by the Netfabb service will not be compiled")
  57. unset(WIN10SDK_PATH)
  58. endif()
  59. endif()
  60. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  61. # Workaround for an old CMake, which does not understand CMAKE_CXX_STANDARD.
  62. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-reorder" )
  63. find_package(PkgConfig REQUIRED)
  64. endif()
  65. if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUXX)
  66. # Adding -fext-numeric-literals to enable GCC extensions on definitions of quad float literals, which are required by Boost.
  67. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fext-numeric-literals" )
  68. endif()
  69. if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
  70. # On GCC and Clang, no return from a non-void function is a warning only. Here, we make it an error.
  71. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=return-type" )
  72. endif()
  73. # Where all the bundled libraries reside?
  74. set(LIBDIR ${CMAKE_CURRENT_SOURCE_DIR}/src/)
  75. # For the bundled boost libraries (boost::nowide)
  76. include_directories(${LIBDIR})
  77. # For libslic3r.h
  78. include_directories(${LIBDIR}/libslic3r ${LIBDIR}/clipper ${LIBDIR}/polypartition)
  79. #set(CMAKE_INCLUDE_CURRENT_DIR ON)
  80. if(WIN32)
  81. # BOOST_ALL_NO_LIB: Avoid the automatic linking of Boost libraries on Windows. Rather rely on explicit linking.
  82. add_definitions(-D_USE_MATH_DEFINES -D_WIN32 -DBOOST_ALL_NO_LIB -DBOOST_USE_WINAPI_VERSION=0x601 -D_CRT_SECURE_NO_WARNINGS)
  83. endif()
  84. add_definitions(-DwxUSE_UNICODE -D_UNICODE -DUNICODE -DWXINTL_NO_GETTEXT_MACRO)
  85. if (SLIC3R_PROFILE)
  86. message("Slic3r will be built with a Shiny invasive profiler")
  87. add_definitions(-DSLIC3R_PROFILE)
  88. endif ()
  89. # Disable optimization even with debugging on.
  90. if (0)
  91. message(STATUS "Perl compiled without optimization. Disabling optimization for the Slic3r build.")
  92. message("Old CMAKE_CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}")
  93. message("Old CMAKE_CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELEASE}")
  94. message("Old CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS_RELEASE}")
  95. set(CMAKE_CXX_FLAGS_RELEASE "/MD /Od /Zi /EHsc /DWIN32 /DTBB_USE_ASSERT")
  96. set(CMAKE_C_FLAGS_RELEASE "/MD /Od /Zi /DWIN32 /DTBB_USE_ASSERT")
  97. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Od /Zi /EHsc /DWIN32 /DTBB_USE_ASSERT")
  98. set(CMAKE_C_FLAGS_RELWITHDEBINFO "/MD /Od /Zi /DWIN32 /DTBB_USE_ASSERT")
  99. set(CMAKE_CXX_FLAGS "/MD /Od /Zi /EHsc /DWIN32 /DTBB_USE_ASSERT")
  100. set(CMAKE_C_FLAGS "/MD /Od /Zi /DWIN32 /DTBB_USE_ASSERT")
  101. endif()
  102. # Find and configure boost
  103. if(SLIC3R_STATIC)
  104. # Use static boost libraries.
  105. set(Boost_USE_STATIC_LIBS ON)
  106. # Use boost libraries linked statically to the C++ runtime.
  107. # set(Boost_USE_STATIC_RUNTIME ON)
  108. endif()
  109. #set(Boost_DEBUG ON)
  110. find_package(Boost REQUIRED COMPONENTS system filesystem thread log locale regex)
  111. if(Boost_FOUND)
  112. include_directories(${Boost_INCLUDE_DIRS})
  113. if (APPLE)
  114. # BOOST_ASIO_DISABLE_KQUEUE : prevents a Boost ASIO bug on OS X: https://svn.boost.org/trac/boost/ticket/5339
  115. add_definitions(-DBOOST_ASIO_DISABLE_KQUEUE)
  116. endif()
  117. if(NOT SLIC3R_STATIC)
  118. add_definitions(-DBOOST_LOG_DYN_LINK)
  119. endif()
  120. endif()
  121. # Find and configure intel-tbb
  122. if(SLIC3R_STATIC)
  123. set(TBB_STATIC 1)
  124. endif()
  125. set(TBB_DEBUG 1)
  126. find_package(TBB REQUIRED)
  127. include_directories(${TBB_INCLUDE_DIRS})
  128. add_definitions(${TBB_DEFINITIONS})
  129. if(MSVC)
  130. # Suppress implicit linking of the TBB libraries by the Visual Studio compiler.
  131. add_definitions(-D__TBB_NO_IMPLICIT_LINKAGE)
  132. endif()
  133. # The Intel TBB library will use the std::exception_ptr feature of C++11.
  134. add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)
  135. find_package(CURL REQUIRED)
  136. include_directories(${CURL_INCLUDE_DIRS})
  137. if (SLIC3R_STATIC)
  138. if (NOT APPLE)
  139. # libcurl is always linked dynamically to the system libcurl on OSX.
  140. # On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
  141. add_definitions(-DCURL_STATICLIB)
  142. endif()
  143. if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
  144. # As of now, our build system produces a statically linked libcurl,
  145. # which links the OpenSSL library dynamically.
  146. find_package(OpenSSL REQUIRED)
  147. message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
  148. message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
  149. include_directories(${OPENSSL_INCLUDE_DIR})
  150. endif()
  151. endif()
  152. ## OPTIONAL packages
  153. # Find eigen3 or use bundled version
  154. if (NOT SLIC3R_STATIC)
  155. find_package(Eigen3)
  156. endif ()
  157. if (NOT Eigen3_FOUND)
  158. set(Eigen3_FOUND 1)
  159. set(EIGEN3_INCLUDE_DIR ${LIBDIR}/eigen/)
  160. endif ()
  161. include_directories(${EIGEN3_INCLUDE_DIR})
  162. # Find expat or use bundled version
  163. # Always use the system libexpat on Linux.
  164. if (NOT SLIC3R_STATIC OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
  165. find_package(EXPAT)
  166. endif ()
  167. if (NOT EXPAT_FOUND)
  168. add_library(expat STATIC
  169. ${LIBDIR}/expat/xmlparse.c
  170. ${LIBDIR}/expat/xmlrole.c
  171. ${LIBDIR}/expat/xmltok.c
  172. )
  173. set(EXPAT_FOUND 1)
  174. set(EXPAT_INCLUDE_DIRS ${LIBDIR}/expat/)
  175. set(EXPAT_LIBRARIES expat)
  176. endif ()
  177. include_directories(${EXPAT_INCLUDE_DIRS})
  178. # Find glew or use bundled version
  179. if (NOT SLIC3R_STATIC)
  180. find_package(GLEW)
  181. endif ()
  182. if (NOT GLEW_FOUND)
  183. add_library(glew STATIC ${LIBDIR}/glew/src/glew.c)
  184. set(GLEW_FOUND 1)
  185. set(GLEW_INCLUDE_DIRS ${LIBDIR}/glew/include/)
  186. set(GLEW_LIBRARIES glew)
  187. add_definitions(-DGLEW_STATIC)
  188. endif ()
  189. include_directories(${GLEW_INCLUDE_DIRS})
  190. # l10n
  191. set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization")
  192. add_custom_target(pot
  193. # FIXME: file list stale
  194. COMMAND xgettext --keyword=L --from-code=UTF-8 --debug
  195. -f "${L10N_DIR}/list.txt"
  196. -o "${L10N_DIR}/Slic3rPE.pot"
  197. WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
  198. COMMENT "Generate pot file from strings in the source tree"
  199. )
  200. # libslic3r, Slic3r GUI and the slic3r executable.
  201. add_subdirectory(src)
  202. set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT slic3r)
  203. # Perl bindings, currently only used for the unit / integration tests of libslic3r.
  204. # Also runs the unit / integration tests.
  205. #FIXME Port the tests into C++ to finally get rid of the Perl!
  206. add_subdirectory(xs)
  207. file(GLOB MyVar var/*.png)
  208. install(FILES ${MyVar} DESTINATION share/slic3r-prusa3d)