优化cmake
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/../../composite/registry/registry.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/../../base/map/map.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/../../base/list/list.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/../../base/codec/codec.cmake")
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/../action/action.cmake")
|
||||
|
||||
set(__library_module_dir "${CMAKE_CURRENT_LIST_DIR}")
|
||||
get_filename_component(__library_project_root "${CMAKE_CURRENT_LIST_DIR}/../.." ABSOLUTE)
|
||||
set(__library_default_bash_script "${__library_project_root}/scripts/library/library.sh")
|
||||
@@ -14,7 +12,6 @@ if (CMAKE_HOST_WIN32)
|
||||
else ()
|
||||
set(__library_default_bash_executable "bash")
|
||||
endif ()
|
||||
|
||||
# INTERNAL: __library_read_file_head(<path> <out>)
|
||||
# 作用: 读取诊断用文件头部内容。
|
||||
# 参数: path 是文件路径;out 是接收文本的变量名。
|
||||
@@ -28,7 +25,6 @@ function(__library_read_file_head path out)
|
||||
set(${out} "<file not found: ${path}>" PARENT_SCOPE)
|
||||
endif ()
|
||||
endfunction()
|
||||
|
||||
# INTERNAL: __library_probe_bash(<bash> <out>)
|
||||
# 作用: 收集 Bash 可执行文件的诊断信息。
|
||||
# 参数: bash 是 Bash 可执行文件;out 是接收诊断文本的变量名。
|
||||
@@ -50,7 +46,6 @@ function(__library_probe_bash bash out)
|
||||
set(_detail "bash --version result: ${_version_result}\n[bash --version stdout]\n${_version_stdout}\n[bash --version stderr]\n${_version_stderr}\n\nbash -c probe result: ${_probe_result}\n[bash -c stdout]\n${_probe_stdout}\n[bash -c stderr]\n${_probe_stderr}")
|
||||
set(${out} "${_detail}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# INTERNAL: __library_fail_cache_operations(<message> <bash> <script> <result> <stdout> <stderr>)
|
||||
# 作用: 统一打印 library_cache_operations 的详细失败信息。
|
||||
# 参数: message 是错误说明;bash/script/result/stdout/stderr 是调用信息。
|
||||
@@ -66,7 +61,6 @@ function(__library_fail_cache_operations message_text bash script result stdout_
|
||||
set(_bash_exists "not checked: non-absolute command")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (EXISTS "${script}")
|
||||
set(_script_exists "YES")
|
||||
file(SIZE "${script}" _script_size)
|
||||
@@ -74,24 +68,20 @@ function(__library_fail_cache_operations message_text bash script result stdout_
|
||||
set(_script_exists "NO")
|
||||
set(_script_size "<missing>")
|
||||
endif ()
|
||||
|
||||
__library_read_file_head("${script}" _script_head)
|
||||
__library_probe_bash("${bash}" _bash_probe)
|
||||
|
||||
execute_process(
|
||||
COMMAND "${bash}" "${script}" --help
|
||||
RESULT_VARIABLE _help_result
|
||||
OUTPUT_VARIABLE _help_stdout
|
||||
ERROR_VARIABLE _help_stderr
|
||||
)
|
||||
|
||||
execute_process(
|
||||
COMMAND "${bash}" "${script}" list-ops
|
||||
RESULT_VARIABLE _retry_result
|
||||
OUTPUT_VARIABLE _retry_stdout
|
||||
ERROR_VARIABLE _retry_stderr
|
||||
)
|
||||
|
||||
message(FATAL_ERROR
|
||||
"${message_text}\n"
|
||||
"command:\n"
|
||||
@@ -111,8 +101,6 @@ function(__library_fail_cache_operations message_text bash script result stdout_
|
||||
"\n[script head]\n${_script_head}\n"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
|
||||
# library 业务层约定:
|
||||
# 1. CMake 端只做数据准备、导出目录和 custom target 生成。
|
||||
# 2. Bash 端读取 CMake 导出的目录,执行 source/build/install/auto/rebuild/clean 等核心逻辑。
|
||||
@@ -125,7 +113,6 @@ endfunction()
|
||||
# 9. 每个库的 map.txt、init.cmake、clear.cmake 统一由 registry 导出到 registry/nodes/<namespace>/<id>/。
|
||||
# 10. library_init_environment 和 library_clear_environment 是 macro,保证 init/clear 中设置或 unset 的变量作用到调用者作用域。
|
||||
# 11. OTHER_USE_OPT 是库导出给依赖方使用的 CMake configure 参数;Bash 构建依赖方时会按依赖闭包顺序自动追加。
|
||||
|
||||
# INTERNAL: __library_registry_id(self out)
|
||||
# 作用: 生成命名空间对应的 registry 对象 ID。
|
||||
# 参数: self 是命名空间;out 是接收 registry ID 的变量名。
|
||||
@@ -429,7 +416,6 @@ function(__library_namespace_storage_id self out)
|
||||
string(REGEX REPLACE "[^A-Za-z0-9_]" "_" _namespace_storage "${self}")
|
||||
set(${out} "${_namespace_storage}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# 经常修改的函数位置
|
||||
# INTERNAL: __library_set_default_dirs(self root_dir)
|
||||
# 作用: 根据根目录写入命名空间默认缓存和导出目录。
|
||||
@@ -687,28 +673,28 @@ endfunction()
|
||||
function(__library_collect_graph_nodes_with_depth dependency_depth out)
|
||||
set(_queue_items "${ARGN}")
|
||||
set(_queue_levels)
|
||||
foreach(_item IN LISTS ARGN)
|
||||
foreach (_item IN LISTS ARGN)
|
||||
list(APPEND _queue_levels 1)
|
||||
endforeach()
|
||||
endforeach ()
|
||||
set(_nodes)
|
||||
while(_queue_items)
|
||||
while (_queue_items)
|
||||
list(POP_FRONT _queue_items _item)
|
||||
list(POP_FRONT _queue_levels _level)
|
||||
list(FIND _nodes "${_item}" _index)
|
||||
if(NOT _index EQUAL -1)
|
||||
if (NOT _index EQUAL -1)
|
||||
continue()
|
||||
endif()
|
||||
endif ()
|
||||
list(APPEND _nodes "${_item}")
|
||||
if(dependency_depth EQUAL 0 OR _level LESS dependency_depth)
|
||||
if (dependency_depth EQUAL 0 OR _level LESS dependency_depth)
|
||||
__library_split_full_name("${_item}" _namespace _id)
|
||||
library_get("${_namespace}" "${_item}" RESOLVED_DEPENDENCIES _dependencies)
|
||||
math(EXPR _next_level "${_level} + 1")
|
||||
foreach(_dependency IN LISTS _dependencies)
|
||||
foreach (_dependency IN LISTS _dependencies)
|
||||
list(APPEND _queue_items "${_dependency}")
|
||||
list(APPEND _queue_levels "${_next_level}")
|
||||
endforeach()
|
||||
endif()
|
||||
endwhile()
|
||||
endforeach ()
|
||||
endif ()
|
||||
endwhile ()
|
||||
set(${out} "${_nodes}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
# INTERNAL: __library_collect_graph_nodes(<out> [full_names...])
|
||||
@@ -752,19 +738,19 @@ endfunction()
|
||||
function(__library_populate_registry_with_depth registry dependency_depth)
|
||||
registry_create("${registry}")
|
||||
__library_collect_graph_nodes_with_depth("${dependency_depth}" _nodes ${ARGN})
|
||||
foreach(_item IN LISTS _nodes)
|
||||
foreach (_item IN LISTS _nodes)
|
||||
__library_copy_to_registry("${_item}" "${registry}")
|
||||
endforeach()
|
||||
foreach(_item IN LISTS _nodes)
|
||||
endforeach ()
|
||||
foreach (_item IN LISTS _nodes)
|
||||
__library_split_full_name("${_item}" _namespace _id)
|
||||
library_get("${_namespace}" "${_item}" RESOLVED_DEPENDENCIES _dependencies)
|
||||
foreach(_dependency IN LISTS _dependencies)
|
||||
foreach (_dependency IN LISTS _dependencies)
|
||||
list(FIND _nodes "${_dependency}" _dependency_index)
|
||||
if(NOT _dependency_index EQUAL -1)
|
||||
if (NOT _dependency_index EQUAL -1)
|
||||
registry_depends("${registry}" "${_item}" "${_dependency}")
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif ()
|
||||
endforeach ()
|
||||
endforeach ()
|
||||
endfunction()
|
||||
# INTERNAL: __library_populate_registry(<registry> [full_names...])
|
||||
# 作用: 使用指定库及其完整递归依赖填充目标 registry。
|
||||
@@ -935,7 +921,6 @@ function(library_get_effective_data_export_dir self out)
|
||||
__library_data_export_dir("${self}" _dir)
|
||||
set(${out} "${_dir}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# API: library_cache_operations(<self> <out>)
|
||||
# 作用: 调用 Bash 端 list-ops,缓存并返回当前业务对象可用 action 列表。
|
||||
# 参数: self 是业务对象名称;out 是接收 action 列表的变量名。
|
||||
@@ -944,18 +929,14 @@ endfunction()
|
||||
function(library_cache_operations self out)
|
||||
__library_operations_id("${self}" _operations)
|
||||
list_clear("${_operations}")
|
||||
|
||||
__library_get_bash_executable("${self}" _bash)
|
||||
__library_get_bash_script("${self}" _script)
|
||||
action_cache_operations("${_bash}" "${_script}" _ops)
|
||||
|
||||
foreach (_op IN LISTS _ops)
|
||||
list_push_back("${_operations}" "${_op}")
|
||||
endforeach ()
|
||||
|
||||
set(${out} "${_ops}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# API: library_export_dir(<self> <dir>)
|
||||
# 作用: 将业务层数据导出成 Bash 可读取的目录。
|
||||
# 参数: self 是业务对象名称;dir 是输出目录。
|
||||
@@ -985,8 +966,6 @@ function(library_export_dir self dir)
|
||||
codec_write_text_file("${_node_dir}/dependencies.txt" "${_deps_text}\n")
|
||||
endforeach ()
|
||||
endfunction()
|
||||
|
||||
|
||||
# INTERNAL: __library_data_export_dir(<self> <out>)
|
||||
# 作用: 返回 library 默认数据导出目录。
|
||||
# 参数: self 是业务对象名称;out 是接收目录路径的变量名。
|
||||
@@ -1001,16 +980,15 @@ function(__library_data_export_dir self out)
|
||||
endif ()
|
||||
set(${out} "${_dir}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# API: library_dependency_order_with_depth(<dependency_depth> <output_variable> [library_names...])
|
||||
# 作用: 解析指定库在给定深度内的依赖闭包,统一完成完整库名归一化、去重、环检测和依赖优先排序。
|
||||
# 参数: dependency_depth 为 0 时无限递归,为 1 时只包含显式传入库,其他正整数表示最大层数;output_variable 是接收完整库名顺序的变量名;ARGN 是 namespace::id 格式的起始库列表。
|
||||
# 返回: 通过 PARENT_SCOPE 设置 output_variable,结果中每个库只出现一次,并保证依赖位于使用者之前。
|
||||
# 注意: 环境加载和 CMake target 加载必须复用该函数,不得分别实现依赖遍历与去重。
|
||||
function(library_dependency_order_with_depth dependency_depth output_variable)
|
||||
if(NOT "${dependency_depth}" MATCHES "^[0-9]+$")
|
||||
if (NOT "${dependency_depth}" MATCHES "^[0-9]+$")
|
||||
message(FATAL_ERROR "dependency_depth must be a non-negative integer: ${dependency_depth}")
|
||||
endif()
|
||||
endif ()
|
||||
string(SHA256 _registry_hash "dependency:${dependency_depth}:${ARGN}")
|
||||
set(_registry "__library_dependency_registry_${_registry_hash}")
|
||||
__library_populate_registry_with_depth("${_registry}" "${dependency_depth}" ${ARGN})
|
||||
@@ -1032,14 +1010,14 @@ endfunction()
|
||||
# 返回: 无。
|
||||
macro(library_init_environment_with_depth dependency_depth)
|
||||
library_dependency_order_with_depth("${dependency_depth}" _library_env_order ${ARGN})
|
||||
foreach(_library_env_item IN LISTS _library_env_order)
|
||||
foreach (_library_env_item IN LISTS _library_env_order)
|
||||
__library_split_full_name("${_library_env_item}" _library_env_namespace _library_env_id)
|
||||
library_get("${_library_env_namespace}" "${_library_env_item}" INIT_SCRIPT_CONTENT _library_env_script)
|
||||
if(NOT "${_library_env_script}" STREQUAL "")
|
||||
if (NOT "${_library_env_script}" STREQUAL "")
|
||||
message("library_init_environment load ${_library_env_item}")
|
||||
cmake_language(EVAL CODE "${_library_env_script}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif ()
|
||||
endforeach ()
|
||||
unset(_library_env_script)
|
||||
unset(_library_env_id)
|
||||
unset(_library_env_namespace)
|
||||
@@ -1067,13 +1045,13 @@ endmacro()
|
||||
macro(library_clear_environment_with_depth dependency_depth)
|
||||
library_dependency_order_with_depth("${dependency_depth}" _library_env_order ${ARGN})
|
||||
list(REVERSE _library_env_order)
|
||||
foreach(_library_env_item IN LISTS _library_env_order)
|
||||
foreach (_library_env_item IN LISTS _library_env_order)
|
||||
__library_split_full_name("${_library_env_item}" _library_env_namespace _library_env_id)
|
||||
library_get("${_library_env_namespace}" "${_library_env_item}" CLEAR_SCRIPT_CONTENT _library_env_script)
|
||||
if(NOT "${_library_env_script}" STREQUAL "")
|
||||
if (NOT "${_library_env_script}" STREQUAL "")
|
||||
cmake_language(EVAL CODE "${_library_env_script}")
|
||||
endif()
|
||||
endforeach()
|
||||
endif ()
|
||||
endforeach ()
|
||||
unset(_library_env_script)
|
||||
unset(_library_env_id)
|
||||
unset(_library_env_namespace)
|
||||
@@ -1106,7 +1084,6 @@ function(__library_target_folder_root self out)
|
||||
endif ()
|
||||
set(${out} "${_folder_root}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# INTERNAL: __library_set_target_folder(<self> <target> <subdir>)
|
||||
# 作用: 给 library 生成的 custom target 设置 IDE Folder 属性。
|
||||
# 参数: self 是业务对象名称;target 是已创建 target;subdir 是相对于 library/<self> 的子目录。
|
||||
@@ -1116,7 +1093,6 @@ function(__library_set_target_folder self target subdir)
|
||||
__library_target_folder_root("${self}" _folder_root)
|
||||
action_set_target_folder("${target}" "${_folder_root}" "${subdir}")
|
||||
endfunction()
|
||||
|
||||
# API: library_add_export_target(<namespace_name> <target_name> <data_export_dir>)
|
||||
# 作用: 生成一个导出数据目录的 CMake custom target。
|
||||
# 参数: namespace_name 是命名空间;target_name 是 custom target 名;data_export_dir 是导出目录。
|
||||
@@ -1174,16 +1150,38 @@ function(library_add_single_item_operation_targets library_name target_prefix da
|
||||
library_resolve("${_namespace_name}" "${library_name}" _resolved_library_name)
|
||||
action_add_item_operation_targets("${target_prefix}" "${data_export_dir}" "${_bash_executable}" "${_bash_script}" "${_resolved_library_name}" "${_operations}" "${_target_folder_root}")
|
||||
endfunction()
|
||||
|
||||
# API: library_is_installed_with_rely(<out> <full_names...>)
|
||||
# API: library_get_missing_with_rely(<out> <full_names...>)
|
||||
# 作用: 判断一组完整库名及其递归依赖库是否全部 install 成功。
|
||||
# 参数: out 是接收 TRUE/FALSE 的变量名;ARGN 是完整库名列表。
|
||||
# 返回: 通过 PARENT_SCOPE 设置 out。
|
||||
# 注意: 每个库名必须包含命名空间,例如 global::zlib。
|
||||
function(library_is_installed_with_rely out)
|
||||
#function(library_get_missing_with_rely out)
|
||||
# set(_queue "${ARGN}")
|
||||
# set(_visited "")
|
||||
# set(_installed TRUE)
|
||||
# while (_queue)
|
||||
# list(POP_FRONT _queue _item)
|
||||
# list(FIND _visited "${_item}" _visited_index)
|
||||
# if (NOT _visited_index EQUAL -1)
|
||||
# continue()
|
||||
# endif ()
|
||||
# list(APPEND _visited "${_item}")
|
||||
# __library_split_full_name("${_item}" _namespace _id)
|
||||
# library_resolve("${_namespace}" "${_item}" _full_name)
|
||||
# library_get("${_namespace}" "${_full_name}" RESOLVED_DEPENDENCIES _dependencies)
|
||||
# list(APPEND _queue ${_dependencies})
|
||||
# library_get_effective_install_dir("${_namespace}" "${_full_name}" _install_dir)
|
||||
# if (NOT EXISTS "${_install_dir}/install.success")
|
||||
# set(_installed FALSE)
|
||||
# break()
|
||||
# endif ()
|
||||
# endwhile ()
|
||||
# set(${out} "${_installed}" PARENT_SCOPE)
|
||||
#endfunction()
|
||||
function(library_get_missing_with_rely out)
|
||||
set(_queue "${ARGN}")
|
||||
set(_visited "")
|
||||
set(_installed TRUE)
|
||||
set(_missing "")
|
||||
while (_queue)
|
||||
list(POP_FRONT _queue _item)
|
||||
list(FIND _visited "${_item}" _visited_index)
|
||||
@@ -1197,9 +1195,8 @@ function(library_is_installed_with_rely out)
|
||||
list(APPEND _queue ${_dependencies})
|
||||
library_get_effective_install_dir("${_namespace}" "${_full_name}" _install_dir)
|
||||
if (NOT EXISTS "${_install_dir}/install.success")
|
||||
set(_installed FALSE)
|
||||
break()
|
||||
list(APPEND _missing "${_item}")
|
||||
endif ()
|
||||
endwhile ()
|
||||
set(${out} "${_installed}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
set(${out} "${_missing}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
@@ -0,0 +1,3 @@
|
||||
if (MSVC)
|
||||
add_compile_options("/FI${CMAKE_CURRENT_LIST_DIR}/trantor_windows_compat.h")
|
||||
endif ()
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
+12
-40
@@ -9,90 +9,62 @@ function(_load_sub_proj)
|
||||
endif ()
|
||||
_load_proj_impl("${PARENT_DIR}/projects" ${ARGN})
|
||||
endfunction()
|
||||
|
||||
# 加载核心项目
|
||||
function(_load_core_proj)
|
||||
get_filename_component(PARENT_DIR ${CMAKE_SOURCE_DIR} DIRECTORY)
|
||||
if (A_enable_register_library)
|
||||
return()
|
||||
endif ()
|
||||
|
||||
|
||||
_load_proj_impl("${PARENT_DIR}/core_library" ${ARGN})
|
||||
endfunction()
|
||||
|
||||
|
||||
_load_core_proj(Core)
|
||||
if (CMAKE_HOST_WIN32)
|
||||
|
||||
|
||||
if (WIN32)
|
||||
|
||||
if (0)
|
||||
_load_sub_proj(python_get_line)
|
||||
endif ()
|
||||
if (0)
|
||||
_load_sub_proj(WDK_Test)
|
||||
endif ()
|
||||
|
||||
# _load_sub_proj(Vulkan_Chart)
|
||||
# _load_sub_proj(opengl)
|
||||
|
||||
endif ()
|
||||
|
||||
if (1)
|
||||
_load_core_proj(Core)
|
||||
|
||||
_load_sub_proj(
|
||||
YSGraphic
|
||||
)
|
||||
#
|
||||
# _load_core_proj(Simple_Tier)
|
||||
endif ()
|
||||
|
||||
|
||||
set(ecap_rely global::drogon global::libarchive global::SQLiteCpp)
|
||||
|
||||
library_is_installed_with_rely(ok ${ecap_rely})
|
||||
|
||||
if (${ok})
|
||||
if (NOT MINGW)
|
||||
_load_core_proj(SSR)
|
||||
|
||||
_load_sub_proj(
|
||||
ECAP_Server
|
||||
)
|
||||
|
||||
_add_directory_to_clion(${CMAKE_SOURCE_DIR}/../projects/webapp)
|
||||
endif ()
|
||||
else ()
|
||||
message("ECAP_Server 依赖未安装!")
|
||||
rcl_add_dependency_action_targets("ecap_server_env" ${ecap_rely})
|
||||
rcl_add_dependency_action_targets("ecap_server_env" ${ecap_rely})
|
||||
library_get_missing_with_rely(ecap_missing_list ${ecap_rely})
|
||||
if (ecap_missing_list)
|
||||
rcl_log_append(${CMAKE_CURRENT_LIST_LINE} "[FATAL_ERROR] ecap dependencies\n${ecap_missing_list}\n are not installed. build ecap_server_env first")
|
||||
return()
|
||||
endif ()
|
||||
if (NOT MINGW)
|
||||
_load_core_proj(SSR)
|
||||
_load_sub_proj(
|
||||
ECAP_Server
|
||||
)
|
||||
_add_directory_to_clion(${CMAKE_SOURCE_DIR}/../projects/webapp)
|
||||
endif ()
|
||||
|
||||
#_load_sub_proj(reverse_engineering)
|
||||
|
||||
if (0)
|
||||
# _add_directory_to_clion(C:/Users/wyc/Desktop/cheng_du_env)
|
||||
|
||||
_add_directory_to_clion(D:/wyc/Environment/codex)
|
||||
# _add_directory_to_clion(C:/msys64/var/cache/pacman/pkg)
|
||||
_add_directory_to_clion(D:/wyc/Environment/jetbra)
|
||||
|
||||
endif ()
|
||||
|
||||
endif ()
|
||||
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
# _load_sub_proj(
|
||||
# linux_driver
|
||||
# )
|
||||
endif ()
|
||||
|
||||
|
||||
#_create_linux_driver_proj(ecap_server)
|
||||
|
||||
string(TIMESTAMP NOW "%Y-%m-%d %H:%M:%S")
|
||||
message("[${NOW}] 全局加载完毕!")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user