浏览代码

feat: 取消静态库链接到动态库的代码

SongZihuan 3 年之前
父节点
当前提交
47b3e7dd69

+ 8 - 11
cmake/aFunHeader.cmake

@@ -4,27 +4,24 @@ generate_export_header(tool-shared
                        EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/aFunToolExport.h"  # 导出的位置
                        BASE_NAME "AFUN_TOOL")
 
-generate_export_header(core-shared-t
+generate_export_header(core-shared
                        EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/aFunCoreExport.h"  # 导出的位置
                        BASE_NAME "AFUN_CORE")
 
-generate_export_header(aFun-xx-libs
+generate_export_header(rt-shared
                        EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/aFunlangExport.h"  # 导出的位置
                        BASE_NAME "AFUN_LANG")
 
 target_compile_definitions(tool-static PUBLIC AFUN_TOOL_STATIC_DEFINE=1)  # 静态库需要定义 AFUN_TOOL_STATIC_DEFINE
-target_compile_definitions(core-static-s PUBLIC AFUN_CORE_STATIC_DEFINE=1)
+target_compile_definitions(core-static PUBLIC AFUN_CORE_STATIC_DEFINE=1)
+target_compile_definitions(rt-static PUBLIC AFUN_LANG_STATIC_DEFINE=1)
 
-target_compile_definitions(core-shared-s PRIVATE core_shared_t_EXPORTS)
-target_compile_definitions(aFun-cx-libs PRIVATE aFun_xx_libs_EXPORTS)
-target_compile_definitions(aFun-ct-libs PRIVATE aFun_xx_libs_EXPORTS)
-
-set_property(TARGET tool-shared core-shared-t core-shared-s aFun-xx-libs aFun-cx-libs aFun-ct-libs
+set_property(TARGET tool-shared core-shared rt-shared
              PROPERTY C_VISIBILITY_PRESET "hidden")
-set_property(TARGET tool-shared core-shared-t core-shared-s aFun-xx-libs aFun-cx-libs aFun-ct-libs
+set_property(TARGET tool-shared core-shared rt-shared
              PROPERTY VISIBILITY_INLINES_HIDDEN TRUE)
 
-set_property(TARGET tool-static core-static-s
+set_property(TARGET tool-static core-static rt-static
              PROPERTY C_VISIBILITY_PRESET "default")
-set_property(TARGET tool-static core-static-s
+set_property(TARGET tool-static core-static
              PROPERTY VISIBILITY_INLINES_HIDDEN FALSE)

+ 7 - 11
cmake/aFunlangConfig.cmake.in

@@ -16,16 +16,12 @@ if (TARGET aFunlang::tool-static)
     list(APPEND components_list tool-shared)
 endif()
 
-if (TARGET aFunlang::core-shared-t)
-    list(APPEND components_list core-shared-t)
+if (TARGET aFunlang::core-shared)
+    list(APPEND components_list core-shared)
 endif()
 
-if (TARGET aFunlang::core-shared-s)
-    list(APPEND components_list core-shared-s)
-endif()
-
-if (TARGET aFunlang::core-static-s)
-    list(APPEND components_list core-static-s)
+if (TARGET aFunlang::core-static)
+    list(APPEND components_list core-static)
 endif()
 
 # 查找可执行程序
@@ -39,9 +35,9 @@ else()
     set_and_check(aFunlang_RUNTIME_LIBRARIES_DIRS @PACKAGE_LIBDIR@)
 endif()
 
-find_program(aFunlang_EXECUTABLE NAMES aFun aFun-ct aFun-cx aFun-xx HINTS ${aFunlang_RUNTIME_DIRS} DOC "aFun executable" NO_DEFAULT_PATH)
+find_program(aFunlang_EXECUTABLE NAMES aFun aFun-ct aFun-ct aFun-xx HINTS ${aFunlang_RUNTIME_DIRS} DOC "aFun executable" NO_DEFAULT_PATH)
 find_program(aFunlang_ct_EXECUTABLE NAMES aFun-ct HINTS ${aFunlang_RUNTIME_DIRS} DOC "aFun-ct executable" NO_DEFAULT_PATH)
-find_program(aFunlang_cx_EXECUTABLE NAMES aFun-cx HINTS ${aFunlang_RUNTIME_DIRS} DOC "aFun-cx executable" NO_DEFAULT_PATH)
+find_program(aFunlang_cx_EXECUTABLE NAMES aFun-ct HINTS ${aFunlang_RUNTIME_DIRS} DOC "aFun-ct executable" NO_DEFAULT_PATH)
 find_program(aFunlang_xx_EXECUTABLE NAMES aFun-xx HINTS ${aFunlang_RUNTIME_DIRS} DOC "aFun-xx executable" NO_DEFAULT_PATH)
 
 if (aFunlang_EXECUTABLE)
@@ -53,7 +49,7 @@ if (aFunlang_ct_EXECUTABLE)
 endif()
 
 if (aFunlang_cx_EXECUTABLE)
-    list(APPEND components_list aFun-cx)
+    list(APPEND components_list aFun-ct)
 endif()
 
 if (aFunlang_xx_EXECUTABLE)

+ 8 - 34
src/CMakeLists.txt

@@ -40,18 +40,9 @@ file(GLOB include_h
      LIST_DIRECTORIES FALSE
      "${PROJECT_SOURCE_DIR}/include/*.h")
 
-option(AFUN_BUILD_ALL "Build all types of aFun" ON)
-set(_build_all ${AFUN_BUILD_ALL})
-
-add_executable(aFun "")
-if (${_build_all})
-    add_executable(aFun-xx "")  # xx表示均为动态链接
-    add_executable(aFun-cx "")  # cx表示仅core动态链接
-    add_executable(aFun-ct "")  # ct表示均静态链接
-    set(aFunList aFun aFun-xx aFun-cx aFun-ct)
-else()
-    set(aFunList aFun)
-endif()
+add_executable(aFun-xx "")  # xx表示均为动态链接
+add_executable(aFun-ct "")  # ct表示均静态链接
+set(aFunList aFun-xx aFun-ct)
 
 foreach(tgt IN LISTS aFunList)
     target_sources(${tgt} PRIVATE ${source} ${private_h} ${include_h})
@@ -60,27 +51,10 @@ foreach(tgt IN LISTS aFunList)
     define_FILENAME(${tgt})
 endforeach()
 
-set(AFUN_LIBRARY "aFunCore" CACHE STRING "Assign core to aFun")
-set(_afun_lib ${AFUN_LIBRARY})
-if (_afun_lib STREQUAL "aFunCore-t")
-    target_link_libraries(aFun PUBLIC aFun-xx-libs)
-elseif(_afun_lib STREQUAL "aFunCore-s")
-    target_link_libraries(aFun PUBLIC aFun-cx-libs)
-else()
-    target_link_libraries(aFun PUBLIC aFun-ct-libs)
-endif()
+target_link_libraries(aFun-xx PUBLIC rt-shared)
+target_link_libraries(aFun-ct PUBLIC rt-static)
 
-install(TARGETS aFun
-        RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT base-runtime
+install(TARGETS aFun-xx aFun-ct
+        RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT advanced-runtime
         PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev
-        PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT advanced-dev)  # 设定安装
-
-if (${_build_all})
-    target_link_libraries(aFun-xx PUBLIC aFun-xx-libs)
-    target_link_libraries(aFun-cx PUBLIC aFun-cx-libs)
-    target_link_libraries(aFun-ct PUBLIC aFun-ct-libs)
-    install(TARGETS aFun-xx aFun-cx aFun-ct
-            RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT advanced-runtime
-            PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev
-            PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT advanced-dev)
-endif()
+        PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT advanced-dev)

+ 8 - 11
src/core/CMakeLists.txt

@@ -31,11 +31,10 @@ foreach(h IN LISTS public_h_info)
     list(APPEND public_h_install "$<INSTALL_INTERFACE:${install_include_core}/${h}>")
 endforeach()
 
-add_library(core-shared-t SHARED "")  # core和tool动态库
-add_library(core-shared-s SHARED "")  # core动态库, tool静态库
-add_library(core-static-s STATIC "")  # core和tool静态库
+add_library(core-shared SHARED "")  # core和tool动态库
+add_library(core-static STATIC "")  # core和tool静态库
 
-foreach(tgt core-shared-t core-shared-s core-static-s)
+foreach(tgt core-shared core-static)
     target_sources(${tgt} PRIVATE ${source} ${private_h} PUBLIC ${public_h_build} ${public_h_install})
     target_include_directories(${tgt} PUBLIC ${build_include} ${install_include})
     set_target_properties(${tgt} PROPERTIES
@@ -44,15 +43,13 @@ foreach(tgt core-shared-t core-shared-s core-static-s)
     define_FILENAME(${tgt})
 endforeach()
 
-set_target_properties(core-shared-t PROPERTIES OUTPUT_NAME "aFunCore-t")
-set_target_properties(core-shared-s PROPERTIES OUTPUT_NAME "aFunCore")
-set_target_properties(core-static-s PROPERTIES OUTPUT_NAME "aFunCore-static")
+set_target_properties(core-shared PROPERTIES OUTPUT_NAME "aFuncore")
+set_target_properties(core-static PROPERTIES OUTPUT_NAME "aFuncore-s")
 
-target_link_libraries(core-shared-t PUBLIC tool-shared)
-target_link_libraries(core-shared-s PUBLIC tool-static)
-target_link_libraries(core-static-s PUBLIC tool-static)
+target_link_libraries(core-shared PUBLIC tool-shared)
+target_link_libraries(core-static PUBLIC tool-static)
 
-install(TARGETS core-shared-t core-shared-s core-static-s
+install(TARGETS core-shared core-static
         EXPORT aFunlang
         RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT base-runtime
         ARCHIVE DESTINATION ${INSTALL_LIBDIR} COMPONENT dev

+ 8 - 11
src/runtime/CMakeLists.txt

@@ -33,11 +33,10 @@ foreach(h IN LISTS public_h)
 endforeach()
 
 
-add_library(aFun-xx-libs SHARED "")  # xx表示均为动态链接 core-share-t
-add_library(aFun-cx-libs SHARED "")  # cx表示仅core动态链接 core-share-c
-add_library(aFun-ct-libs SHARED "")  # ct表示均静态链接 core-static-s
+add_library(rt-shared SHARED "")  # xx表示均为动态链接 core-share-t
+add_library(rt-static STATIC "")  # ct表示均静态链接 core-static
 
-foreach(tgt aFun-xx-libs aFun-cx-libs aFun-ct-libs)
+foreach(tgt rt-shared rt-static)
     target_sources(${tgt}
                    PRIVATE ${source} ${source_tool} ${private_h} ${private_tool_h} ${private_h_core}
                    PUBLIC ${public_h_build} ${public_h_install})
@@ -52,15 +51,13 @@ foreach(tgt aFun-xx-libs aFun-cx-libs aFun-ct-libs)
     define_FILENAME(${tgt})
 endforeach()
 
-set_target_properties(aFun-xx-libs PROPERTIES OUTPUT_NAME "aFun-xx")
-set_target_properties(aFun-cx-libs PROPERTIES OUTPUT_NAME "aFun-cx")
-set_target_properties(aFun-ct-libs PROPERTIES OUTPUT_NAME "aFun-ct")
+set_target_properties(rt-shared PROPERTIES OUTPUT_NAME "aFunrt")
+set_target_properties(rt-static PROPERTIES OUTPUT_NAME "aFunrt-s")
 
-target_link_libraries(aFun-xx-libs PUBLIC core-shared-t)
-target_link_libraries(aFun-cx-libs PUBLIC core-shared-s)
-target_link_libraries(aFun-ct-libs PUBLIC core-static-s)
+target_link_libraries(rt-shared PUBLIC core-shared)
+target_link_libraries(rt-static PUBLIC core-static)
 
-install(TARGETS aFun-xx-libs aFun-cx-libs aFun-ct-libs
+install(TARGETS rt-shared rt-static
         EXPORT aFunlang
         RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT base-runtime
         ARCHIVE DESTINATION ${INSTALL_LIBDIR} COMPONENT dev

+ 2 - 2
src/tool/CMakeLists.txt

@@ -40,8 +40,8 @@ endforeach()
 target_link_libraries(tool-shared PUBLIC ${hgt-lib} ${dlfcn_lib} ${pcre2_lib} ${fflags_lib} ${pthread_lib})
 target_link_libraries(tool-static PUBLIC ${hgt-lib} ${dlfcn_lib} ${pcre2_lib} ${fflags_lib} ${pthread_lib})
 
-set_target_properties(tool-shared PROPERTIES OUTPUT_NAME "aFunTool")
-set_target_properties(tool-static PROPERTIES OUTPUT_NAME "aFunTool-static")
+set_target_properties(tool-shared PROPERTIES OUTPUT_NAME "aFuntool")
+set_target_properties(tool-static PROPERTIES OUTPUT_NAME "aFuntool-s")
 
 install(TARGETS tool-shared tool-static
         EXPORT aFunlang

+ 1 - 1
test/export/CMakeLists.txt

@@ -6,7 +6,7 @@ set(CMAKE_C_STANDARD 11)
 find_package(aFunlang REQUIRED)
 add_executable(aFunTest main.c)
 
-target_link_libraries(aFunTest aFunlang::core-shared-t)
+target_link_libraries(aFunTest aFunlang::core-shared)
 
 file(GLOB _dll  # 遍历所有的.dll
      FOLLOW_SYMLINKS  # 遍历link

+ 1 - 1
test/src/CMakeLists.txt

@@ -5,7 +5,7 @@ foreach(src IN LISTS src_list)
     cmake_path(GET src STEM file_name)
     add_executable(${file_name})
     target_sources(${file_name} PRIVATE ${src})
-    target_link_libraries(${file_name} PUBLIC aFun-ct-libs)  # 链接静态库 (导出所有符号)
+    target_link_libraries(${file_name} PUBLIC rt-static)  # 链接静态库 (导出所有符号)
     set_target_properties(${file_name}
                           PROPERTIES OUTPUT_NAME "test_${file_name}")
     target_compile_definitions(${file_name} PRIVATE IN_CTEST)