Przeglądaj źródła

feat: 添加runtime模块

SongZihuan 3 lat temu
rodzic
commit
ee0a32091d

+ 8 - 1
cmake/aFunHeader.cmake

@@ -8,7 +8,14 @@ generate_export_header(core-shared-t
                        EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/aFunCoreExport.h"  # 导出的位置
                        BASE_NAME "AFUN_CORE")
 
+generate_export_header(aFun-xx-libs
+                       EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/${INSTALL_INCLUDEDIR}/aFunlangExport.h"  # 导出的位置
+                       BASE_NAME "AFUN_LANG")
+
 target_compile_definitions(tool-static PUBLIC AFUN_TOOL_STATIC_DEFINE)  # 静态库需要定义 AFUN_TOOL_STATIC_DEFINE
 
 target_compile_definitions(core-shared-s PRIVATE core_shared_t_EXPORTS)
-target_compile_definitions(core-static-s PUBLIC AFUN_CORE_STATIC_DEFINE)
+target_compile_definitions(core-static-s PUBLIC AFUN_CORE_STATIC_DEFINE)
+
+target_compile_definitions(aFun-cx-libs PRIVATE aFun_xx_libs_EXPORTS)
+target_compile_definitions(aFun-ct-libs PRIVATE aFun_xx_libs_EXPORTS)

+ 1 - 0
include/aFun.h

@@ -1,6 +1,7 @@
 #ifndef AFUN_AFUN_H
 #define AFUN_AFUN_H
 #include "aFunCore.h"
+#include "aFunlang.h"
 #include "tool.h"
 
 #endif //AFUN_AFUN_H

+ 7 - 0
include/runtime/aFunlang.h

@@ -0,0 +1,7 @@
+#ifndef AFUN_AFUNLANG_H
+#define AFUN_AFUNLANG_H
+#include "aFunlangExport.h"
+
+AFUN_LANG_EXPORT void aFunInit();
+
+#endif //AFUN_AFUNLANG_H

+ 13 - 10
src/CMakeLists.txt

@@ -1,5 +1,6 @@
 add_subdirectory(tool)
 add_subdirectory(core)  # core 依赖 tool
+add_subdirectory(runtime)  # runtime 依赖 core
 
 # source在子目录中被使用, 为了避免子目录访问到source, 子目录将在此前面被执行
 file(GLOB source
@@ -19,9 +20,9 @@ set(_build_all ${AFUN_BUILD_ALL})
 
 add_executable(aFun "")
 if (${_build_all})
-    add_executable(aFun-xx "")  # xx表示均为动态链接 core-share-t
-    add_executable(aFun-cx "")  # cx表示仅core动态链接 core-share-c
-    add_executable(aFun-ct "")  # ct表示均静态链接 core-static-s
+    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)
@@ -36,11 +37,13 @@ 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 core-shared-t)
+    target_link_libraries(aFun PUBLIC aFun-xx-libs)
 elseif(_afun_lib STREQUAL "aFunCore-s")
-    target_link_libraries(aFun PUBLIC core-shared-s)
+    target_link_libraries(aFun PUBLIC aFun-cx-libs)
 else()
-    target_link_libraries(aFun PUBLIC core-static-s)
+    target_link_libraries(aFun PUBLIC aFun-ct-libs)
+    get_target_property(include_h aFun INCLUDE_DIRECTORIES)
+    message(STATUS "include_h = ${include_h}")
 endif()
 
 install(TARGETS aFun
@@ -49,11 +52,11 @@ install(TARGETS aFun
         PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT advanced-dev)  # 设定安装
 
 if (${_build_all})
-    target_link_libraries(aFun-xx PUBLIC core-shared-t)
-    target_link_libraries(aFun-cx PUBLIC core-shared-s)
-    target_link_libraries(aFun-ct PUBLIC core-static-s)
+    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-runtim
+            RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT advanced-runtime
             PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev
             PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT advanced-dev)
 endif()

+ 1 - 1
src/main.c

@@ -370,7 +370,7 @@ bool infixFunc(af_Object *obj) {
 }
 
 int main() {
-    aFunCoreInit();
+    aFunInit();
     printf("Hello World\n");
 
     af_Environment *env = makeEnvironment(grt_always);

+ 53 - 0
src/runtime/CMakeLists.txt

@@ -0,0 +1,53 @@
+file(GLOB source
+     LIST_DIRECTORIES FALSE
+     ${CMAKE_CURRENT_LIST_DIR}/*.c)
+
+file(GLOB private_h
+     LIST_DIRECTORIES FALSE
+     ${CMAKE_CURRENT_LIST_DIR}/*.h)
+
+set(build_include_runtime ${PROJECT_SOURCE_DIR}/include/runtime)
+set(install_include_runtime ${INSTALL_INCLUDEDIR})
+
+file(GLOB public_h
+     LIST_DIRECTORIES FALSE
+     RELATIVE "${build_include_runtime}"
+     "${build_include_runtime}/*.h")
+
+set(public_h_build)
+set(public_h_install)
+
+foreach(h IN LISTS public_h)
+    file(RELATIVE_PATH _path ${CMAKE_CURRENT_LIST_DIR} "${build_include_runtime}/${h}")
+    list(APPEND public_h_build   "$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${_path}>")  # 相对路径的转换, 此处只能使用相对路径
+    list(APPEND public_h_install "$<INSTALL_INTERFACE:${install_include_runtime}/${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
+
+foreach(tgt aFun-xx-libs aFun-cx-libs aFun-ct-libs)
+    target_sources(${tgt} PRIVATE ${source} ${private_h} PUBLIC ${public_h_build} ${public_h_install})
+    target_include_directories(${tgt} PUBLIC
+                               $<BUILD_INTERFACE:${build_include_runtime}>
+                               $<INSTALL_INTERFACE:${install_include_runtime}>)
+    set_target_properties(${tgt} PROPERTIES PUBLIC_HEADER "${public_h_build}")
+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")
+
+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)
+
+install(TARGETS aFun-xx-libs aFun-cx-libs aFun-ct-libs
+        EXPORT aFunlang
+        RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT base-runtime
+        ARCHIVE DESTINATION ${INSTALL_LIBDIR} COMPONENT dev
+        LIBRARY DESTINATION ${INSTALL_LIBDIR} COMPONENT base-runtime
+        PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev
+        PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT advanced-dev)

+ 5 - 0
src/runtime/__aFunlang.h

@@ -0,0 +1,5 @@
+#ifndef AFUN_AFUNLANG_H_
+#define AFUN_AFUNLANG_H_
+#include "aFunlang.h"
+
+#endif //AFUN_AFUNLANG_H_

+ 6 - 0
src/runtime/aFunlang.c

@@ -0,0 +1,6 @@
+#include "__aFunlang.h"
+#include "aFunCore.h"
+
+void aFunInit() {
+    aFunCoreInit();
+}

+ 1 - 1
test/src/CMakeLists.txt

@@ -4,7 +4,7 @@
 foreach(src IN LISTS src_list)
     cmake_path(GET src STEM file_name)
     add_executable(${file_name} ${src})
-    target_link_libraries(${file_name} core-static-s)  # 链接静态库 (导出所有符号)
+    target_link_libraries(${file_name} aFun-ct-libs)  # 链接静态库 (导出所有符号)
     set_target_properties(${file_name}
                           PROPERTIES OUTPUT_NAME "test_${file_name}")
     unset(file_name)