mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-05 19:56:03 +08:00
195 lines
6.9 KiB
CMake
195 lines
6.9 KiB
CMake
#/|/ Copyright (c) Prusa Research 2018 - 2022 Lukáš Matěna @lukasmatena, Tomáš Mészáros @tamasmeszaros, Filip Sykala @Jony01, Vojtěch Bubník @bubnikv, Vojtěch Král @vojtechkral
|
|
#/|/
|
|
#/|/ PrusaSlicer is released under the terms of the AGPLv3 or higher
|
|
#/|/
|
|
#
|
|
# This CMake project downloads, configures and builds PrusaSlicer dependencies on Unix and Windows.
|
|
#
|
|
# When using this script, it's recommended to perform an out-of-source build using CMake.
|
|
#
|
|
# All the dependencies are installed in a `destdir` directory in the root of the build directory,
|
|
# in a traditional Unix-style prefix structure. The destdir can be used directly by CMake
|
|
# when building PrusaSlicer - to do this, set the CMAKE_PREFIX_PATH to ${destdir}/usr/local.
|
|
# Warning: On UNIX/Linux, you also need to set -DSLIC3R_STATIC=1 when building PrusaSlicer.
|
|
#
|
|
# For better clarity of console output, it's recommended to _not_ use a parallelized build
|
|
# for the top-level command, ie. use `make -j 1` or `ninja -j 1` to force single-threaded top-level
|
|
# build. This doesn't degrade performance as individual dependencies are built in parallel fashion
|
|
# if supported by the dependency.
|
|
#
|
|
# On Windows, architecture (64 vs 32 bits) is judged based on the compiler variant.
|
|
# To build dependencies for either 64 or 32 bit OS, use the respective compiler command line.
|
|
#
|
|
# WARNING: On UNIX platforms wxWidgets hardcode the destdir path into its `wx-conffig` utility,
|
|
# therefore, unfortunatelly, the installation cannot be copied/moved elsewhere without re-installing wxWidgets.
|
|
#
|
|
cmake_minimum_required(VERSION 3.12)
|
|
project(PrusaSlicer_deps)
|
|
|
|
if (MSVC)
|
|
option(DEP_DEBUG "Build in debug version of packages automatically" OFF)
|
|
endif ()
|
|
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
|
|
cmake_policy(SET CMP0135 NEW)
|
|
endif ()
|
|
|
|
include(${PROJECT_SOURCE_DIR}/../cmake/modules/AddCMakeProject.cmake)
|
|
|
|
macro(list_projects result curdir)
|
|
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
|
|
set(dirlist "")
|
|
foreach(child ${children})
|
|
if(IS_DIRECTORY ${curdir}/${child})
|
|
string(REGEX MATCH "^\\+([a-zA-Z0-9]+)" is_package ${child})
|
|
if(is_package)
|
|
list(APPEND dirlist ${CMAKE_MATCH_1})
|
|
endif()
|
|
endif()
|
|
endforeach()
|
|
set(${result} ${dirlist})
|
|
endmacro()
|
|
|
|
function(dep_message mode msg)
|
|
if (NOT DEP_MESSAGES_WRITTEN)
|
|
message(${mode} "${msg}")
|
|
endif()
|
|
endfunction ()
|
|
|
|
# Always ON options:
|
|
if (MSVC)
|
|
if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
|
|
dep_message(STATUS "Detected 64-bit compiler => building 64-bit deps bundle")
|
|
set(DEPS_BITS 64)
|
|
elseif ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
|
|
dep_message(STATUS "Detected 32-bit compiler => building 32-bit deps bundle")
|
|
set(DEPS_BITS 32)
|
|
else ()
|
|
dep_message(FATAL_ERROR "Unable to detect architecture!")
|
|
endif ()
|
|
else ()
|
|
set(DEP_CMAKE_OPTS "-DCMAKE_POSITION_INDEPENDENT_CODE=ON")
|
|
endif ()
|
|
|
|
if (APPLE)
|
|
# This ensures dependencies don't use SDK features which are not available in the version specified by Deployment target
|
|
# That can happen when one uses a recent SDK but specifies an older Deployment target
|
|
set(DEP_WERRORS_SDK "-Werror=partial-availability -Werror=unguarded-availability -Werror=unguarded-availability-new")
|
|
|
|
set(DEP_CMAKE_OPTS
|
|
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
|
|
"-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}"
|
|
"-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}"
|
|
"-DCMAKE_CXX_FLAGS=${DEP_WERRORS_SDK}"
|
|
"-DCMAKE_C_FLAGS=${DEP_WERRORS_SDK}"
|
|
"-DCMAKE_FIND_FRAMEWORK=LAST"
|
|
"-DCMAKE_FIND_APPBUNDLE=LAST"
|
|
)
|
|
endif ()
|
|
|
|
list_projects(SUPPORTED_PACKAGES ${CMAKE_CURRENT_LIST_DIR})
|
|
|
|
dep_message(STATUS "Found external package definitions: ${SUPPORTED_PACKAGES}")
|
|
|
|
set(REQUIRED_PACKAGES
|
|
Boost
|
|
Catch2
|
|
Cereal
|
|
CURL
|
|
EXPAT
|
|
NLopt
|
|
GLEW
|
|
TBB
|
|
Qhull
|
|
wxWidgets
|
|
OpenVDB
|
|
CGAL
|
|
OCCT
|
|
)
|
|
|
|
set(SYSTEM_PROVIDED_PACKAGES OpenGL)
|
|
|
|
if (MSVC)
|
|
list(APPEND REQUIRED_PACKAGES ZLIB)
|
|
elseif (UNIX)
|
|
# On UNIX systems (including Apple) ZLIB should be available
|
|
list(APPEND SYSTEM_PROVIDED_PACKAGES ZLIB)
|
|
endif ()
|
|
|
|
include(CMakeDependentOption)
|
|
option(${PROJECT_NAME}_SELECT_ALL "Choose all external projects to be built." ON)
|
|
|
|
find_package(Git REQUIRED)
|
|
|
|
# The default command line for patching. Only works for newer
|
|
set(PATCH_CMD ${GIT_EXECUTABLE} apply --verbose --ignore-space-change --whitespace=fix)
|
|
|
|
# all required package targets that have existing definitions will be gathered here
|
|
set(_dep_list "")
|
|
set(_build_list "")
|
|
|
|
foreach (pkg ${SUPPORTED_PACKAGES})
|
|
cmake_dependent_option(${PROJECT_NAME}_SELECT_${pkg} "Select package ${pkg} to be built." OFF "NOT ${PROJECT_NAME}_SELECT_ALL" OFF)
|
|
if (${PROJECT_NAME}_SELECT_ALL OR ${PROJECT_NAME}_SELECT_${pkg})
|
|
include(+${pkg}/${pkg}.cmake)
|
|
|
|
if (${pkg} IN_LIST REQUIRED_PACKAGES)
|
|
list(APPEND _dep_list dep_${pkg})
|
|
endif ()
|
|
endif ()
|
|
endforeach()
|
|
|
|
# Establish dependency graph
|
|
foreach (pkg ${SUPPORTED_PACKAGES})
|
|
foreach(deppkg ${DEP_${pkg}_DEPENDS})
|
|
if (${deppkg} IN_LIST SYSTEM_PROVIDED_PACKAGES)
|
|
find_package(${deppkg} QUIET)
|
|
if (NOT ${deppkg}_FOUND)
|
|
dep_message(WARNING "No ${deppkg} found in system altough marked as system provided. This might cause trouble building the dependencies on this platform")
|
|
endif ()
|
|
else ()
|
|
dep_message(STATUS "Mapping dep_${deppkg} => dep_${pkg}")
|
|
add_dependencies(dep_${pkg} dep_${deppkg})
|
|
if (${pkg} IN_LIST REQUIRED_PACKAGES)
|
|
list(APPEND _build_list dep_${deppkg})
|
|
endif ()
|
|
endif ()
|
|
endforeach()
|
|
endforeach()
|
|
|
|
list(APPEND _build_list ${_dep_list})
|
|
list(REMOVE_DUPLICATES _build_list)
|
|
dep_message(STATUS "Building dep targets (${CMAKE_BUILD_TYPE}): ${_build_list}")
|
|
add_custom_target(deps ALL DEPENDS ${_dep_list})
|
|
|
|
# Support legacy option DEP_DEBUG on MSVC to build debug libraries in the same cmake run as for Release:
|
|
if (DEP_DEBUG AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
set(_build_list_dbg "")
|
|
foreach (t ${_build_list})
|
|
list(APPEND _build_list_dbg ${t}_debug)
|
|
endforeach()
|
|
dep_message(STATUS "Building dep targets (Debug): ${_build_list_dbg}")
|
|
|
|
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DebugBuild)
|
|
execute_process(
|
|
COMMAND ${CMAKE_COMMAND} ${CMAKE_CURRENT_SOURCE_DIR} -G${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=Debug -DDEP_DOWNLOAD_DIR=${DEP_DOWNLOAD_DIR} -DDESTDIR=${DESTDIR} -DDEP_MESSAGES_WRITTEN=ON
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DebugBuild
|
|
)
|
|
|
|
# Can be used to build only the debug libs
|
|
add_custom_target(deps_debug ALL)
|
|
|
|
# Each lib will have a dep_<package>_debug target to build only the debug counterpart
|
|
foreach(pkgtgt ${_build_list})
|
|
add_custom_target(${pkgtgt}_debug
|
|
COMMAND ${CMAKE_COMMAND} --build . --target ${pkgtgt}
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DebugBuild
|
|
)
|
|
add_dependencies(deps_debug ${pkgtgt}_debug)
|
|
endforeach()
|
|
endif ()
|
|
|
|
set(DEP_MESSAGES_WRITTEN ON CACHE BOOL "")
|
|
|
|
install(CODE "message(STATUS \"Built packages succesfully.\")")
|