1

我刚刚开始在 C 项目上使用 CMake 进行构建。

我的项目目录结构如下所示:

MainProject
   module1/
        src/
        include/
        CMakeLists.txt
   module1/
        src/
        include/
        CMakeLists.txt

....
   moduleN/
        src/
        include/
        CMakeLists.txt

目前,我正在正确构建我的模块,但是,我现在希望能够指定模块间的依赖关系,以便在我创建一个模块时,它的所有依赖模块都被重建(如果更改)。

我的 CMakeLists.txt 文件通常如下所示:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

PROJECT( basetypes )
FIND_PACKAGE( Threads )
SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-pthread")  
ADD_DEFINITIONS(-DE4C_THREADSAFE )

INCLUDE_DIRECTORIES ("include/")

SET( basetypes_SRCS
     src/btypes_1.c  
     src/btypes_2.c  
     src/btypes_3.c   
     src/btypes_4.c   
     src/btypes_5.c  
     src/vfuncs.c
     src/btypes_6.c    
     src/btypes_7.c   
     src/btypes_8.c  
     src/btypes_8.c  
     src/e4c.c )

ADD_LIBRARY(basetypes SHARED ${basetypes_SRCS})

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "bin/")

如何修改这样的 CMakeLists 文件以指定其他依赖项目?

4

1 回答 1

1

Try target_link_libraries command. However, it need to know module names, so I've suggest you to write one globale CMakeLists file, that include modules by add_subdirectory command.

于 2012-11-23T14:37:23.210 回答