Files
dl/CMakeLists.txt
2026-09-16 14:07:40 +08:00

396 lines
16 KiB
CMake
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
cmake_minimum_required (VERSION 3.5)
# 使MT设置生效
if (POLICY CMP0091)
cmake_policy(SET CMP0091 NEW)
endif (POLICY CMP0091)
# LTO链接时优化
if(POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif()
project ("dlx")
set(LIBTYPE STATIC)
message("生成目标平台:${CMAKE_SYSTEM}")
message("------------------dl option------------------")
set(DL_VULKAN_DIR AUTO)
#set(DL_VULKAN_DIR D:/VulkanSDK/1.3.268.0)
#set(DL_VULKAN_DIR D:/VulkanSDK/1.3.250.0)
message("------------------dl option------------------")
# 传递 DL_EASY 禁用绘图
#set(DL_EASY false)
if(NOT DEFINED DL_EASY)
set(DL_EASY false)
endif()
if(DL_EASY)
set(DL_DISABLE_RENDER true)
set(DL_DISABLE_AUDIO true)
set(DL_USE_MT true)
#set(DL_USE_MT false)
else()
set(DL_DISABLE_RENDER false)
set(DL_DISABLE_AUDIO false)
set(DL_USE_MT true)
endif()
if(DL_USE_MT)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# 输出使clangd可以智能提示的 compile_commands.json
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
if(MSVC)
# 关闭 /showIncludes
# string(REPLACE "/showIncludes" "" CMAKE_DEPFILE_FLAGS_C "${CMAKE_DEPFILE_FLAGS_C}")
# string(REPLACE "/showIncludes" "" CMAKE_DEPFILE_FLAGS_CXX "${CMAKE_DEPFILE_FLAGS_CXX}")
endif()
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Zi")
# release生成pdb
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
endif()
# 使用C++最新标准
set(CMAKE_CXX_STANDARD 23)
if (APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -lc++abi")
endif()
# JoltPhysic 安卓编译需要
set(CPP_RTTI_ENABLED ON)
# 预编译Jolt需要此定义
set(CPP_EXCEPTIONS_ENABLED ON)
set(CMAKE_DISABLE_PRECOMPILE_HEADERS ON)
# Jolt在linux使用了LTO,需要全局开启
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
# 暂时不太清楚以下哪个变量导致jolt安卓异常
set(USE_SSE4_1 OFF CACHE BOOL "" FORCE)
set(USE_SSE4_2 OFF CACHE BOOL "" FORCE)
set(USE_AVX OFF CACHE BOOL "" FORCE)
set(USE_AVX2 OFF CACHE BOOL "" FORCE)
set(USE_AVX512 OFF CACHE BOOL "" FORCE)
set(USE_LZCNT OFF CACHE BOOL "" FORCE)
set(USE_TZCNT OFF CACHE BOOL "" FORCE)
set(USE_F16C OFF CACHE BOOL "" FORCE)
set(USE_FMADD OFF CACHE BOOL "" FORCE)
#set(FLOATING_POINT_EXCEPTIONS_ENABLED OFF CACHE BOOL "" FORCE)
#set(CROSS_COMPILE_ARM OFF CACHE BOOL "" FORCE)
message("------------------第三方库option------------------")
option(BUILD_DOCS "关闭第三方库的文档生成" OFF)
option(INSTALL_MANPAGES "解决flac报错" OFF)
if (CMAKE_SYSTEM_NAME MATCHES "Android")
option(ALSOFT_INSTALL "解决安卓openal报错" OFF)
endif()
option(FT_DISABLE_ZLIB "freetype禁用内部zlib" ON)
option(FT_REQUIRE_ZLIB "freetype查找外部zlib" ON)
option(CURL_USE_LIBPSL "不使用libpsl" OFF)
option(CURL_USE_OPENSSL "使用openssl" ON)
# 关闭第三方库的额外生成
option(ALSOFT_UTILS "Build utility programs" OFF)
option(ALSOFT_NO_CONFIG_UTIL "Disable building the alsoft-config utility" ON)
option(ALSOFT_EXAMPLES "Build example programs" OFF)
option(RTMIDI_BUILD_TESTING "Build test programs" OFF)
option(WEBP_BUILD_ANIM_UTILS "Build animation utilities." OFF)
option(WEBP_BUILD_CWEBP "Build the cwebp command line tool." OFF)
option(WEBP_BUILD_DWEBP "Build the dwebp command line tool." OFF)
option(WEBP_BUILD_GIF2WEBP "Build the gif2webp conversion tool." OFF)
option(WEBP_BUILD_IMG2WEBP "Build the img2webp animation tool." OFF)
option(WEBP_BUILD_VWEBP "Build the vwebp viewer tool." OFF)
option(WEBP_BUILD_WEBPINFO "Build the webpinfo command line tool." OFF)
option(WEBP_BUILD_LIBWEBPMUX "Build the libwebpmux library." OFF)
option(WEBP_BUILD_WEBPMUX "Build the webpmux command line tool." OFF)
option(WEBP_BUILD_EXTRAS "Build extras." OFF)
option(WEBP_BUILD_WEBP_JS "Emscripten build of webp.js." OFF)
option(BUILD_PROGRAMS "Build and install programs" OFF)
option(BUILD_EXAMPLES "Build and install examples" OFF)
option(BUILD_TESTING "Build tests" OFF)
option(BUILD_DOCS "Build and install doxygen documents" OFF)
option(INSTALL_MANPAGES "Install MAN pages" OFF)
option(INSTALL_PKGCONFIG_MODULES "Install PkgConfig modules" OFF)
option(INSTALL_CMAKE_CONFIG_MODULE "Install CMake package-config module" OFF)
option(INFOWARE_EXAMPLES "Add infoware examples to the build." OFF)
option(INFOWARE_TESTS "Input tests for infoware." OFF)
option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" OFF)
option(TINYGLTF_BUILD_LOADER_EXAMPLE "Build loader_example(load glTF and dump infos)" OFF)
option(TINYGLTF_BUILD_GL_EXAMPLES "Build GL exampels(requires glfw, OpenGL, etc)" OFF)
option(TINYGLTF_BUILD_TESTS "Build unit tests" OFF)
option(TINYGLTF_INSTALL "Install tinygltf files during install step. Usually set to OFF if you include tinygltf through add_subdirectory()" ON)
option(TINYGLTF_INSTALL_VENDOR "Install vendored nlohmann/json and nothings/stb headers" OFF)
option(LUNASVG_BUILD_EXAMPLES "Build examples" OFF)
option(BUILD_CURL_EXE "Build curl executable" OFF)
option(CURL_DISABLE_INSTALL "Disable installation targets" OFF)
# mimalloc 只使用静态库;强制关闭共享库/重定向,避免生成 mimalloc-debug.dll 与 mimalloc-redirect.lib
set(MI_BUILD_SHARED OFF CACHE BOOL "Build shared library" FORCE)
set(MI_BUILD_STATIC ON CACHE BOOL "Build static library" FORCE)
set(MI_BUILD_OBJECT OFF CACHE BOOL "Build object library" FORCE)
set(MI_BUILD_TESTS OFF CACHE BOOL "Build test executables" FORCE)
set(MI_WIN_REDIRECT OFF CACHE BOOL "Use redirection module on Windows" FORCE)
message("------------------解析第三方库------------------")
message("------------------lz4 压缩库-------------------")
add_subdirectory ("third/lz4")
message("------------------zlib 压缩库---------")
add_subdirectory ("third/zlib")
message("------------------fmt 文本格式化库--------------")
option(FMT_INSTALL "开启fmt的安装" ON)
add_subdirectory ("third/fmt")
message("------------------lunasvg svg格式库-----------")
add_subdirectory ("third/lunasvg")
message("------------------libwebp webp格式库-----------")
add_subdirectory ("third/libwebp")
message("------------------OpenXLSX xlsx格式库-----------")
add_subdirectory ("third/OpenXLSX")
if (NOT CMAKE_SYSTEM_NAME MATCHES "Android"
AND NOT DL_DISABLE_RENDER)
message("------------------glfw 窗口库------------------")
add_subdirectory ("third/glfw")
endif()
if(NOT DL_DISABLE_RENDER)
message("------------------freetype 字体解析库-----------")
add_subdirectory ("third/freetype")
message("------------------tinygltf gltf格式库-----------")
add_subdirectory ("third/tinygltf")
endif()
message("------------------ogg vorbis 音频格式库-----------")
add_subdirectory ("third/ogg")
set (OGG_LIBRARY "third/ogg")
set (OGG_INCLUDE_DIR "third/ogg")
add_subdirectory ("third/vorbis")
message("------------------flac 音频格式库-----------")
add_subdirectory ("third/flac")
message("------------------openal-soft 音频库-----------")
if (NOT CMAKE_SYSTEM_NAME MATCHES "Linux")
# Mac系统(Darwin)下,先修复openal-soft的dl依赖问题
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
# 定义CMAKE_DL_LIBSMac下指向系统dl库),避免openal-soft找不到dl目标
set(CMAKE_DL_LIBS "-ldl")
# 强制跳过openal-soft的export/install(核心报错点)
set(OPENAL_BUILD_INSTALL OFF CACHE BOOL "Disable OpenAL install" FORCE)
set(OPENAL_BUILD_EXAMPLES OFF CACHE BOOL "Disable OpenAL examples" FORCE)
endif()
# 再添加openal-soft子目录
add_subdirectory ("third/openal-soft")
endif()
message("------------------rtmidi midi库-----------")
if (NOT CMAKE_SYSTEM_NAME MATCHES "Android")
add_subdirectory ("third/rtmidi")
endif()
if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows")
message("------------------iconv 文本编码转换库-----------")
#add_subdirectory ("third/libiconv")
endif()
message("------------------angelscript 脚本语言库-----------")
add_subdirectory ("third/angelscript/angelscript/projects/cmake")
message("------------------lua 脚本语言库-----------")
add_subdirectory ("third/lua")
add_subdirectory ("third/LuaBridge3")
message("------------------infoware 硬件信息库-----------")
if (CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "AMD64")
set(INFOWARE_PCI_IDS_PATH ${CMAKE_SOURCE_DIR}/third/infoware/pci.ids CACHE FILEPATH "使用本地piiids" FORCE)
add_subdirectory ("third/infoware")
endif()
message("------------------wcwidth 字符宽度检测-----------")
add_subdirectory ("third/wcwidth")
message("------------------simde 向量化计算-----------")
add_subdirectory ("third/simde")
message("------------------magic_enum 枚举静态反射-----------")
add_subdirectory ("third/magic_enum")
message("------------------cpp-subprocess 进程库-----------")
add_subdirectory ("third/cpp-subprocess")
message("------------------ktx ktx格式库-----------")
add_subdirectory ("third/ktx")
message("------------------JoltPhysics 物理引擎-----------")
add_subdirectory ("third/JoltPhysics/Build")
message("------------------mimalloc 内存分配-----------")
add_subdirectory ("third/mimalloc")
message("------------------GoogleTest 单元测试库-----------")
add_subdirectory ("third/googletest")
message("------------------curl http协议库-----------")
set(OPENSSL_ROOT_DIR ${CMAKE_SOURCE_DIR}/third/openssl)
# 先锁死 libcurl 编译选项
set(CURL_USE_OPENSSL ON CACHE BOOL "" FORCE)
set(CURL_USE_SCHANNEL OFF CACHE BOOL "" FORCE)
set(CURL_USE_LIBPSL OFF CACHE BOOL "" FORCE)
set(CURL_USE_LIBSSH2 OFF CACHE BOOL "" FORCE)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
if(WIN32)
# 1. 自动判断架构 x64/x86
if(CMAKE_CL_64)
set(ARCH x64)
else()
set(ARCH x86)
endif()
# 2. 自动判断运行库 MT/MD
if(DL_USE_MT)
set(RT MT)
else()
set(RT MD)
endif()
# 3. 自动路径
set(OPENSSL_INCLUDE_DIR ${OPENSSL_ROOT_DIR}/include)
set(OPENSSL_LIB_DIR ${OPENSSL_ROOT_DIR}/${ARCH}/${RT})
# 4. 精确 lib 文件
set(OPENSSL_SSL_LIBRARY ${OPENSSL_LIB_DIR}/libssl_static.lib)
set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_LIB_DIR}/libcrypto_static.lib)
# ==============================
# 关键:创建 OpenSSL::SSL OpenSSL::Crypto 目标
# ==============================
if(NOT TARGET OpenSSL::SSL)
add_library(OpenSSL::SSL UNKNOWN IMPORTED)
set_target_properties(OpenSSL::SSL PROPERTIES
IMPORTED_LOCATION ${OPENSSL_SSL_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
endif()
if(NOT TARGET OpenSSL::Crypto)
add_library(OpenSSL::Crypto UNKNOWN IMPORTED)
set_target_properties(OpenSSL::Crypto PROPERTIES
IMPORTED_LOCATION ${OPENSSL_CRYPTO_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
endif()
# 强制写入缓存
set(OPENSSL_FOUND TRUE CACHE BOOL "" FORCE)
set(OPENSSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR} CACHE PATH "" FORCE)
set(OPENSSL_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY} CACHE FILEPATH "" FORCE)
set(OPENSSL_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY} CACHE FILEPATH "" FORCE)
include_directories(${OPENSSL_INCLUDE_DIR})
link_directories(${OPENSSL_LIB_DIR})
endif()
# Linux / Mac
if(UNIX AND NOT APPLE AND NOT ANDROID)
find_package(OpenSSL REQUIRED)
endif()
if(APPLE)
set(OPENSSL_ROOT_DIR "/opt/homebrew/opt/openssl@3")
find_package(OpenSSL REQUIRED)
endif()
# Android
if(ANDROID)
set(OPENSSL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/third/openssl/android/${ANDROID_ABI}/include)
set(OPENSSL_SSL_LIBRARY ${CMAKE_SOURCE_DIR}/third/openssl/android/${ANDROID_ABI}/lib/libssl.a)
set(OPENSSL_CRYPTO_LIBRARY ${CMAKE_SOURCE_DIR}/third/openssl/android/${ANDROID_ABI}/lib/libcrypto.a)
add_library(OpenSSL::SSL UNKNOWN IMPORTED)
set_target_properties(OpenSSL::SSL PROPERTIES IMPORTED_LOCATION ${OPENSSL_SSL_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
add_library(OpenSSL::Crypto UNKNOWN IMPORTED)
set_target_properties(OpenSSL::Crypto PROPERTIES IMPORTED_LOCATION ${OPENSSL_CRYPTO_LIBRARY} INTERFACE_INCLUDE_DIRECTORIES ${OPENSSL_INCLUDE_DIR})
endif()
# 最后编译 libcurl
add_subdirectory(third/libcurl)
message("------------------其余库以其他形式链接----------")
message("------------------nlohmann-json json库---------")
message("------------------stb_image 图像解析库----------")
message("------------------qrcodegen 二维码生成库-----------")
message("------------------vld 内存泄漏检测库----------")
message("------------------asio 网络库-----------")
message("------------------tinyxml2 xml格式库-----------")
message("------------------openssl 库-----------")
message("------------------curl 库-----------")
message("------------------sqlite 数据库-----------")
message("------------------tinyobjloader obj格式库-----------")
message("------------------mp3 音频格式库-----------")
message("------------------ktx 解析库-----------")
message("------------------CrashRpt 崩溃采集库-----------")
message("------------------解析dl-----------------------")
add_subdirectory ("dl")
if(NOT DL_DISABLE_RENDER)
message("------------------解析dl_test-----------------------")
add_subdirectory ("project/dl_test")
message("------------------解析dl_unit_test(此项目由ai生成)-----------")
add_subdirectory ("project/dl_unit_test")
if(NOT CMAKE_SYSTEM_NAME MATCHES "Android")
message("------------------解析dl_console-----------------------")
add_subdirectory ("project/dl_console")
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/project/dl_editor/CMakeLists.txt)
message("------------------解析dl_editor-----------------------")
add_subdirectory ("project/dl_editor")
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/project/dl_midi/CMakeLists.txt)
message("------------------解析dl_midi-----------------------")
add_subdirectory ("project/dl_midi")
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/project/dl_chess/CMakeLists.txt)
message("------------------解析dl_chess-----------------------")
add_subdirectory ("project/dl_chess")
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/project/dl_snake/CMakeLists.txt)
message("------------------解析dl_snake-----------------------")
add_subdirectory ("project/dl_snake")
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/project/hs/CMakeLists.txt)
message("------------------解析HistorySim-----------------------")
add_subdirectory ("project/hs")
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/project/ds/CMakeLists.txt)
message("------------------解析DreamSandbox-----------------------")
add_subdirectory ("project/ds")
endif()
endif()
# 无界面程序
if(EXISTS ${CMAKE_SOURCE_DIR}/project/dl_config/CMakeLists.txt AND
NOT CMAKE_SYSTEM_NAME MATCHES "Android")
message("------------------解析dl_config-----------------------")
add_subdirectory ("project/dl_config")
endif()
if(EXISTS ${CMAKE_SOURCE_DIR}/project/dl_chess_server/CMakeLists.txt)
message("------------------解析dl_chess_server-----------------------")
add_subdirectory ("project/dl_chess_server")
endif()
message("若解析Cmake失败,有以下几个常见原因:")
message("1.未安装VulkanSDK")
message("CMake生成完成后,可选择dl_test项目调试")