CMake4FPGA_add_dependency: 生成源依赖列表与依赖树文件读取

需积分: 5 0 下载量 63 浏览量 更新于2024-12-30 收藏 7KB ZIP 举报
资源摘要信息: "CMake4FPGA_add_dependency" 是一个为FPGA(现场可编程门阵列)设计的CMake扩展或自定义模块。CMake是一个跨平台的自动化构建系统,广泛应用于软件开发中。而在硬件设计领域,特别是使用Verilog这样的硬件描述语言进行FPGA开发时,构建过程可能需要特殊处理,以确保源代码依赖项被正确处理。本模块中的两个关键函数为“add_dependency_tree_file”和“get_list_from_dependency_tree”。 1. add_dependency_tree_file 函数: 这个函数的作用是读取一个文件,这个文件通常包含了项目中各个源文件依赖关系的树状结构信息。在FPGA项目中,源文件的依赖关系往往很复杂,一个顶层模块可能依赖于多个子模块,而每个子模块又可能有其自己的依赖项。这种依赖关系通常用树状结构来表示,以便于清晰地理解各个组件之间的关系。 add_dependency_tree_file 函数将解析这个树状结构文件,并将解析得到的源依赖项保存起来。这一过程对于CMake这样的构建系统来说至关重要,因为它需要知道哪些文件需要被编译,以及它们之间的依赖关系,这样才能生成正确的构建规则。 2. get_list_from_dependency_tree 函数: 一旦依赖项被读取并保存下来,get_list_from_dependency_tree 函数就会被用来处理这些依赖项。这个函数的任务是从解析出的依赖树中生成一个列表,该列表可能是一个CMake列表变量,包含了所有需要被编译的源文件路径。 这个列表将被用于指导构建过程中的编译器或工具链,以便它们能够找到所有必要的源文件,并按正确的顺序对它们进行编译。在Verilog项目中,这可能涉及到将源文件传递给Verilog编译器(如iverilog)或其他FPGA开发工具(如Xilinx Vivado或Intel Quartus)。 3. 关于Verilog标签: 提到的Verilog标签表明本模块专为Verilog项目设计。Verilog是一种硬件描述语言(HDL),用于模拟电子系统,特别是用于编写可编程逻辑设备如FPGA的代码。Verilog项目通常包含多个源文件和头文件,这些文件之间存在着复杂的依赖关系,因此,自动化构建系统如CMake需要能够理解和处理这些依赖关系,以保证构建过程的正确性和效率。 4. 关于压缩包子文件的文件名称列表: 提到的文件名称列表"CMake4FPGA_add_dependency-main"表示该模块的主要实现文件可能被包含在一个压缩包中,并且这个文件是包的主要入口点。在实际的项目中,这可能是一个CMake模块文件(如CMakeLists.txt),它包含了所有必要的CMake指令来集成和使用上述提到的函数。 总结来说,CMake4FPGA_add_dependency 模块通过对源文件依赖项的读取和处理,增强了CMake在FPGA开发项目中的构建能力。它通过读取依赖树文件,并生成相应的列表,帮助CMake理解复杂的源文件依赖关系,从而实现自动化、高效地构建FPGA项目。这对于Verilog开发者来说,可以极大地简化构建过程,减少出错的可能性,并提高开发效率。

cmake_minimum_required(VERSION 3.8.0 FATAL_ERROR) project(mcu_kit VERSION 0.1.0 DESCRIPTION "mcu-kit SDK" LANGUAGES C ) set(PROJECT_BRIEF "vDiscovery") set(CMAKE_C_STANDARD 11) set(CMAKE_C_EXTENSIONS ON) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_compile_options(-Wall) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") include(CMakePrintHelpers) include(ConfigureChecks) if(EXISTS "${PROJECT_SOURCE_DIR}/config.cmake") include(config.cmake) else() message(FATAL_ERROR "Can't find cmake.config file") endif() if(${CMAKE_CROSSCOMPILING}) set(LV_SIMULATOR_ON_PC OFF) else() set(LV_SIMULATOR_ON_PC ON) endif() configure_file( "${PROJECT_SOURCE_DIR}/base/base_sdk_version.h.in" "${PROJECT_SOURCE_DIR}/base/base_sdk_version.h" ) configure_file( "${PROJECT_SOURCE_DIR}/base/base_config.h.in" "${PROJECT_SOURCE_DIR}/base/base_config.h" ) set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX}/bin) set(CMAKE_INSTALL_SBINDIR ${CMAKE_INSTALL_PREFIX}/sbin) set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib) set(CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include) set(CMAKE_INSTALL_SYSCONFDIR ${CMAKE_INSTALL_PREFIX}/etc) set(CMAKE_INSTALL_SHARESTATEDIR ${CMAKE_INSTALL_PREFIX}/com) set(CMAKE_INSTALL_LOCALSTATEDIR ${CMAKE_INSTALL_PREFIX}/var) set(CMAKE_INSTALL_INFODIR ${CMAKE_INSTALL_PREFIX}/info) set(CMAKE_INSTALL_LOCALEDIR ${CMAKE_INSTALL_PREFIX}/locate) set(CMAKE_INSTALL_MANDIR ${CMAKE_INSTALL_PREFIX}/man) set(CMAKE_INSTALL_DOCDIR ${CMAKE_INSTALL_PREFIX}/doc) set(CMAKE_INSTALL_RESDIR ${CMAKE_INSTALL_PREFIX}) include(PrepareInstall) set(KIT_ROOT_DIR ${CMAKE_SOURCE_DIR}) add_subdirectory("base") # add_subdirectory("third-party") add_subdirectory("lib") add_subdirectory("drivers") add_subdirectory("framework") add_subdirectory("sysapp") add_subdirectory("app") include(GeneratePkgConfig) include(Linux-kitInfo)详细注释一下这段代码

175 浏览量

同一目录下cmakelist.txt文件为cmake_minimum_required(VERSION 3.16) # 声明该项目的名称和版本号 project(MyLib VERSION 1.0) # 添加库代码文件到该库 add_library(mylib STATIC src/header.cpp) add_library(mylib_shared SHARED src/header.cpp) include_directories(include) # set(PUBLIC_HEADER) # 指定install路径,以便于其他项目找到该库 install(TARGETS mylib mylib_shared EXPORT MyLibConfig ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include) install(FILES include/header.h DESTINATION include) # 生成MyLibConfig.cmake文件 include(CMakePackageConfigHelpers) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" VERSION ${MyLib_VERSION} COMPATIBILITY AnyNewerVersion ) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/MyLibConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" INSTALL_DESTINATION cmake ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" DESTINATION cmake ),而MyLibConfig.cmake.in文件中的代码为# 指定该项目的名称和版本号 set(MyLib_VERSION @MyLib_VERSION@) set(MyLib_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include") set(MyLib_LIBRARIES "@CMAKE_INSTALL_PREFIX@/lib/libmylib.a") set(MyLib_LIBRARIES_SHARED "@CMAKE_INSTALL_PREFIX@/lib/libmylib_shared.so") # 导入MyLib的目标 include("${CMAKE_CURRENT_LIST_DIR}/MyLibTargets.cmake"),而MyLibTargets.cmake文件中的代码为# 导入mylib静态库 add_library(MyLib::mylib STATIC IMPORTED) set_target_properties(MyLib::mylib PROPERTIES IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/lib/libmylib.a" ) # 导入mylib_shared动态库 add_library(MyLib::mylib_shared SHARED IMPORTED) set_target_properties(MyLib::mylib_shared PROPERTIES IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/lib/libmylib_shared.so" ) # 导出MyLib的目标 install( EXPORT MyLibConfig NAMESPACE MyLib:: DESTINATION cmake ),以上代码哪里存在错误,为什么不能正确导出MyLibConfig.cmake文件

2023-05-28 上传

cmakelist.txt中代码为cmake_minimum_required(VERSION 3.16) # 声明该项目的名称和版本号 project(MyLib VERSION 1.0) # 添加库代码文件到该库 add_library(mylib STATIC src/header.cpp) add_library(mylib_shared SHARED src/header.cpp) include_directories(include) # set(PUBLIC_HEADER) # 指定install路径,以便于其他项目找到该库 install(TARGETS mylib mylib_shared EXPORT MyLibConfig ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include) install(FILES include/header.h DESTINATION include) # 生成MyLibConfig.cmake文件 include(CMakePackageConfigHelpers) write_basic_packMyLibConfigage_version_file( "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" VERSION ${MyLib_VERSION} COMPATIBILITY AnyNewerVersion ) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/MyLibConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" INSTALL_DESTINATION cmake ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" DESTINATION cmake ),同级目录下的MyLibConfig.cmake.in代码为# 指定该项目的名称和版本号 set(MyLib_VERSION @MyLib_VERSION@) set(MyLib_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include") set(MyLib_LIBRARIES "@CMAKE_INSTALL_PREFIX@/lib/libmylib.a") set(MyLib_LIBRARIES_SHARED "@CMAKE_INSTALL_PREFIX@/lib/libmylib_shared.so") # 导入MyLib的目标 include("${CMAKE_CURRENT_LIST_DIR}/MyLibTargets.cmake"),同级目录下的MyLibTargets.cmake代码为# 导入mylib静态库 add_library(MyLib::mylib STATIC IMPORTED) set_target_properties(MyLib::mylib PROPERTIES IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/lib/libmylib.a" ) # 导入mylib_shared动态库 add_library(MyLib::mylib_shared SHARED IMPORTED) set_target_properties(MyLib::mylib_shared PROPERTIES IMPORTED_LOCATION "@CMAKE_INSTALL_PREFIX@/lib/libmylib_shared.so" ) # 导出MyLib的目标 install( EXPORT MyLibConfig NAMESPACE MyLib:: DESTINATION cmake ),为什么执行make install命令后的cmake目录下没有MyLibTargets.cmake文件

2023-05-28 上传

cmake_minimum_required(VERSION 3.16) # 声明该项目的名称和版本号 project(MyLib VERSION 1.0) # 添加库代码文件到该库 add_library(mylib STATIC src/header.cpp) target_include_directories(mylib INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> ) add_library(mylib_shared SHARED src/header.cpp) target_include_directories(mylib_shared INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> ) # include_directories(include) # 指定install路径,以便于其他项目找到该库 install(TARGETS mylib mylib_shared EXPORT MyLibTargets ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) install(FILES include/header.h DESTINATION include) # 生成MyLibConfig.cmake文件 include(CMakePackageConfigHelpers) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" VERSION ${MyLib_VERSION} COMPATIBILITY AnyNewerVersion ) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/MyLibConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" INSTALL_DESTINATION cmake ) install( EXPORT MyLibTargets NAMESPACE MyLib:: DESTINATION cmake ) # export(EXPORT MyLibTargets # NAMESPACE MyLib:: # FILE MyLibTargets.cmake) # install(FILES ${CMAKE_CURRENT_BINARY_DIR}/MyLibTargets.cmake DESTINATION cmake) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" DESTINATION cmake )为什么执行时,提醒/home/czl/cmake_lib/src/header.cpp:1:10: fatal error: header.h: 没有那个文件或目录

191 浏览量
171 浏览量
2023-05-30 上传