Files
FreeCADWasmDev/CMakeLists.txt
wangdequan 0a2e7ce7f5
Some checks failed
FreeCAD master CI / Prepare (push) Has been cancelled
CodeQL Advanced / Analyze (actions) (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
FreeCAD master CI / Pixi (push) Has been cancelled
FreeCAD master CI / Ubuntu (push) Has been cancelled
FreeCAD master CI / Windows (push) Has been cancelled
FreeCAD master CI / Lint (push) Has been cancelled
FreeCAD master CI / WrapUp (push) Has been cancelled
Stale Issues / stale (push) Has been cancelled
Push Crowdin Translations / update-crowdin (push) Has been cancelled
Fetch Crowdin Translations / update-crowdin (push) Has been cancelled
Add FreeCAD WebAssembly runtime probes
2026-08-23 17:48:10 +08:00

314 lines
12 KiB
CMake

# As of February 2025 we require CMake 3.22.0
cmake_minimum_required(VERSION 3.22.0 FATAL_ERROR)
# As of cMake 3.27, find_package() will look for both case-sensitive and all-uppercase versions
# of the package. This seems to affect FLANN as included by Pixi
if(POLICY CMP0144)
cmake_policy(SET CMP0144 NEW)
endif()
# FindPythonInterp and FindPythonLibs modules are deprecated, but are still in use by
# all versions of Shiboken2. This policy must be kept at OLD until Shiboken2 is no longer
# supported
if(POLICY CMP0148)
cmake_policy(SET CMP0148 OLD)
endif()
# The exec_program command was deprecated in cMake 3.0, and policy CMP0153 was added in cMake
# 3.28 to control whether this gives a warning (the OLD behavior) or a fatal error (NEW)
if(POLICY CMP0153)
cmake_policy(SET CMP0153 NEW)
endif()
# Suppress 'FindBoost module is removed' warning. Will use BoostConfig.cmake instead
if(POLICY CMP0167)
cmake_policy(SET CMP0167 NEW)
endif()
# As of cMake 3.31 add_custom_command() rejects invalid arguments
if(POLICY CMP0175)
cmake_policy(SET CMP0175 NEW)
endif()
# Added in cMake 3.31, enforce normalization of all DESTINATION paths given to install()
if(POLICY CMP0177)
cmake_policy(SET CMP0177 NEW)
endif()
option(FREECAD_USE_CCACHE "Auto detect and use ccache during compilation" ON)
if(FREECAD_USE_CCACHE)
find_program(CCACHE_PROGRAM ccache) #This check should occur before project()
if(CCACHE_PROGRAM)
message(STATUS "Using ccache found at: " ${CCACHE_PROGRAM})
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
endif()
project(FreeCAD)
# WebAssembly is an explicit, opt-in configuration. Desktop builds retain all
# existing defaults; the Web preset supplies the Emscripten toolchain and this
# block narrows the module graph to the first native-kernel probe.
option(FREECAD_WEB "Build the FreeCAD WebAssembly core configuration" OFF)
option(FREECAD_WEB_ENABLE_ASSEMBLY "Enable the Assembly Web probe and its dependency closure" OFF)
option(FREECAD_WEB_ENABLE_CAM "Enable the CAM Path App Web probe and its dependency closure" OFF)
option(FREECAD_WEB_ENABLE_CLOUD "Enable the Cloud App Web probe and its dependency closure" OFF)
option(FREECAD_WEB_ENABLE_INSPECTION "Enable the Inspection App Web probe and its dependency closure" OFF)
option(FREECAD_WEB_ENABLE_MESHPART "Enable the MeshPart App Web probe and its dependency closure" OFF)
option(FREECAD_WEB_ENABLE_OPENSCAD "Enable the OpenSCAD App Web probe and its dependency closure" OFF)
option(FREECAD_WEB_ENABLE_SANDBOX "Enable the Sandbox App Web probe and its dependency closure" OFF)
if(FREECAD_WEB)
if(NOT EMSCRIPTEN OR NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
message(FATAL_ERROR
"FREECAD_WEB requires the Emscripten CMake toolchain. "
"Use the freecad-web-core preset or pass -DCMAKE_TOOLCHAIN_FILE explicitly.")
endif()
set(BUILD_GUI OFF CACHE BOOL "Web core does not build the desktop GUI" FORCE)
set(BUILD_FORCE_DIRECTORY ON CACHE BOOL "Web builds must be out of source" FORCE)
set(BUILD_DYNAMIC_LINK_PYTHON OFF CACHE BOOL "Web core does not dynamically link Python" FORCE)
set(BUILD_TRACY_FRAME_PROFILER OFF CACHE BOOL "Web core does not build Tracy" FORCE)
set(ENABLE_DEVELOPER_TESTS OFF CACHE BOOL "Web core does not build desktop tests" FORCE)
set(FREECAD_USE_PCH OFF CACHE BOOL "Web core does not use desktop PCH defaults" FORCE)
set(FREECAD_USE_FREETYPE OFF CACHE BOOL "Web core leaves optional FreeType disabled" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -include${CMAKE_SOURCE_DIR}/src/FCWebRangesCompat.h")
add_compile_definitions(FREECAD_WEB_CORE)
set(_freecad_web_disabled_options
BUILD_ADDONMGR
BUILD_ASSEMBLY
BUILD_BIM
BUILD_CAM
BUILD_CLOUD
BUILD_DRAWING
BUILD_DRAFT
BUILD_FEM
BUILD_FLAT_MESH
BUILD_HELP
BUILD_INSPECTION
BUILD_MESH
BUILD_MESH_PART
BUILD_OPENSCAD
BUILD_PLOT
BUILD_POINTS
BUILD_REVERSEENGINEERING
BUILD_ROBOT
BUILD_SANDBOX
BUILD_SHOW
BUILD_SPREADSHEET
BUILD_START
BUILD_SURFACE
BUILD_TECHDRAW
BUILD_TEST
BUILD_TUX
BUILD_VR
BUILD_WEB)
if(FREECAD_WEB_ENABLE_ASSEMBLY)
# Assembly's App target requires Spreadsheet; the configured dependency
# graph also requires Draft and TechDraw. Keep this opt-in so the
# default viewer/kernel build remains unchanged.
list(REMOVE_ITEM _freecad_web_disabled_options
BUILD_ASSEMBLY BUILD_SPREADSHEET BUILD_DRAFT BUILD_TECHDRAW)
endif()
if(FREECAD_WEB_ENABLE_CAM)
# CAM's Path App target is GUI-free, but its build graph requires Mesh
# in addition to the existing Part and Import Web modules.
list(REMOVE_ITEM _freecad_web_disabled_options BUILD_CAM BUILD_MESH)
endif()
if(FREECAD_WEB_ENABLE_CLOUD)
list(REMOVE_ITEM _freecad_web_disabled_options BUILD_CLOUD)
endif()
if(FREECAD_WEB_ENABLE_INSPECTION)
list(REMOVE_ITEM _freecad_web_disabled_options BUILD_INSPECTION BUILD_MESH BUILD_POINTS)
endif()
if(FREECAD_WEB_ENABLE_MESHPART)
list(REMOVE_ITEM _freecad_web_disabled_options BUILD_MESH_PART BUILD_MESH)
endif()
if(FREECAD_WEB_ENABLE_OPENSCAD)
# OpenSCAD is a Python workbench whose source target depends on the
# Draft/TechDraw/Spreadsheet script closure, even when BUILD_GUI is OFF.
list(REMOVE_ITEM _freecad_web_disabled_options
BUILD_OPENSCAD BUILD_DRAFT BUILD_TECHDRAW BUILD_SPREADSHEET)
endif()
if(FREECAD_WEB_ENABLE_SANDBOX)
# Sandbox App is GUI-free only when its QtCore/PyCXX document protector
# is linked without SandboxGui. Mesh is its direct App dependency.
list(REMOVE_ITEM _freecad_web_disabled_options BUILD_SANDBOX BUILD_MESH)
endif()
foreach(_freecad_web_disabled_option IN LISTS _freecad_web_disabled_options)
set(${_freecad_web_disabled_option} OFF CACHE BOOL "Disabled by FREECAD_WEB core configuration" FORCE)
endforeach()
unset(_freecad_web_disabled_options)
foreach(_freecad_web_enabled_option BUILD_IMPORT BUILD_MATERIAL BUILD_MEASURE BUILD_PART BUILD_PART_DESIGN BUILD_SKETCHER)
set(${_freecad_web_enabled_option} ON CACHE BOOL "Enabled by FREECAD_WEB core configuration" FORCE)
endforeach()
if(FREECAD_WEB_ENABLE_ASSEMBLY)
foreach(_freecad_web_assembly_option BUILD_ASSEMBLY BUILD_SPREADSHEET BUILD_DRAFT BUILD_TECHDRAW)
set(${_freecad_web_assembly_option} ON CACHE BOOL "Enabled by FREECAD_WEB_ENABLE_ASSEMBLY" FORCE)
endforeach()
endif()
if(FREECAD_WEB_ENABLE_CAM)
foreach(_freecad_web_cam_option BUILD_CAM BUILD_MESH)
set(${_freecad_web_cam_option} ON CACHE BOOL "Enabled by FREECAD_WEB_ENABLE_CAM" FORCE)
endforeach()
endif()
if(FREECAD_WEB_ENABLE_CLOUD)
set(BUILD_CLOUD ON CACHE BOOL "Enabled by FREECAD_WEB_ENABLE_CLOUD" FORCE)
endif()
if(FREECAD_WEB_ENABLE_INSPECTION)
foreach(_freecad_web_inspection_option BUILD_INSPECTION BUILD_MESH BUILD_POINTS)
set(${_freecad_web_inspection_option} ON CACHE BOOL "Enabled by FREECAD_WEB_ENABLE_INSPECTION" FORCE)
endforeach()
endif()
if(FREECAD_WEB_ENABLE_MESHPART)
foreach(_freecad_web_meshpart_option BUILD_MESH_PART BUILD_MESH)
set(${_freecad_web_meshpart_option} ON CACHE BOOL "Enabled by FREECAD_WEB_ENABLE_MESHPART" FORCE)
endforeach()
endif()
if(FREECAD_WEB_ENABLE_OPENSCAD)
foreach(_freecad_web_openscad_option BUILD_OPENSCAD BUILD_DRAFT BUILD_TECHDRAW BUILD_SPREADSHEET)
set(${_freecad_web_openscad_option} ON CACHE BOOL "Enabled by FREECAD_WEB_ENABLE_OPENSCAD" FORCE)
endforeach()
endif()
if(FREECAD_WEB_ENABLE_SANDBOX)
foreach(_freecad_web_sandbox_option BUILD_SANDBOX BUILD_MESH)
set(${_freecad_web_sandbox_option} ON CACHE BOOL "Enabled by FREECAD_WEB_ENABLE_SANDBOX" FORCE)
endforeach()
endif()
include(cMake/FreeCADWebDependencies.cmake)
endif()
# Sanitizer support
option(FREECAD_USE_SANITIZER_ASAN "Enable AddressSanitizer ie. (ASan)" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
option(FREECAD_USE_SANITIZER_LSAN "Enable LeakSanitizer (LSan)" OFF)
option(FREECAD_USE_SANITIZER_TSAN "Enable ThreadSanitizer (TSan)" OFF)
option(FREECAD_USE_SANITIZER_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan)" OFF)
option(FREECAD_USE_SANITIZER_MSAN "Enable MemorySanitizer (MSan)" OFF)
endif()
mark_as_advanced(
FREECAD_USE_SANITIZER_ASAN
FREECAD_USE_SANITIZER_LSAN
FREECAD_USE_SANITIZER_TSAN
FREECAD_USE_SANITIZER_UBSAN
FREECAD_USE_SANITIZER_MSAN
)
set(PACKAGE_VERSION_MAJOR "1")
set(PACKAGE_VERSION_MINOR "2")
set(PACKAGE_VERSION_PATCH "0") # number of patch release (e.g. "4" for the 0.18.4 release)
set(PACKAGE_VERSION_SUFFIX "dev") # either "dev" for development snapshot or "" (empty string)
set(PACKAGE_BUILD_VERSION "0") # used when the same FreeCAD version will be re-released (for example using an updated LibPack)
string(TIMESTAMP PACKAGE_COPYRIGHT_YEAR "%Y")
set(PACKAGE_VERSION "${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}")
set(PACKAGE_STRING "${PROJECT_NAME} ${PACKAGE_VERSION}")
# include local modules
include(CheckCXXCompilerFlag)
include(AddFileDependencies)
include(cMake/FreeCadMacros.cmake)
# include helper functions/macros
add_subdirectory(cMake/FreeCAD_Helpers)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cMake")
CompilerChecksAndSetups()
ConfigureCMakeVariables()
InitializeFreeCADBuildOptions()
CheckInterModuleDependencies()
FreeCADLibpackChecks()
SetupDoxygen()
SetupLibFmt()
SetupSanitizers()
SetupYamlCpp()
SetupZipIos()
find_package(ICU REQUIRED COMPONENTS uc i18n)
if(FREECAD_WEB)
# Emscripten's ICU port keeps the data archive separate from uc/i18n.
# Keep it in the Web link interface without changing desktop discovery.
list(APPEND ICU_LIBRARIES "${FREECAD_WEB_ICU_DATA_LIBRARY}")
endif()
if(NOT FREECAD_LIBPACK_USE OR FREECAD_LIBPACK_CHECKFILE_CLBUNDLER OR FREECAD_LIBPACK_CHECKFILE_VERSION)
SetupPython()
SetupPCL()
SetupPybind11()
SetupXercesC()
find_package(ZLIB REQUIRED)
find_package(PyCXX REQUIRED)
SetupOpenCasCade()
if(BUILD_GUI)
# Do this before the check for SMESH because it depends on vtk
# that may have its own OpenGL check but possibly fails and leaves
# OPENGL_gl_LIBRARY empty that results into linker errors
SetupOpenGL()
endif(BUILD_GUI)
SetupSalomeSMESH()
if (BUILD_FEM_NETGEN)
set(NETGEN_DEFINITIONS -DNO_PARALLEL_THREADS -DOCCGEOMETRY)
if (NOT FREECAD_USE_EXTERNAL_SMESH)
find_package(NETGEN REQUIRED)
endif()
endif()
# not needed at the moment
#find_package(OpenCV REQUIRED)
SetupSwig()
SetupEigen()
# This file is included directly due to some cMake macros that are defined within.
# If these macro definitions are embedded within another macro, it causes problems.
include(cMake/FreeCAD_Helpers/SetupQt.cmake)
SetupFreetype()
if(BUILD_GUI)
SetupCoin3D()
SetupPivy()
SetupSpaceball()
SetupShibokenAndPyside()
SetupMatplotlib()
endif(BUILD_GUI)
# SetupCoin3D can overwrite find_package(Boost) output so keep this after.
SetupBoost()
if(BUILD_BIM)
SetupLark()
endif()
endif()
if(BUILD_VR)
find_package(Rift)
endif(BUILD_VR)
SetLibraryVersions()
SetGlobalCompilerAndLinkerSettings()
add_subdirectory(src)
add_subdirectory(data)
BuildAndInstallDesignerPlugin()
CreatePackagingTargets()
if(MSVC AND FREECAD_LIBPACK_USE AND LIBPACK_FOUND)
CopyLibpackDirectories()
endif()
if (ENABLE_DEVELOPER_TESTS)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
PrintFinalReport()
message("\n=================================================\n"
"Now run 'cmake --build ${CMAKE_BINARY_DIR}' to build ${PROJECT_NAME}\n"
"=================================================\n")