Homunculus Reticulli
Homunculus Reticulli

Reputation: 68436

Specifying project dependencies in a CMake project

I have just started using CMake for my builds on a C project.

My project dir structure looks like this:

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

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

At the moment, I am building my modules correctly, However, I now want to be able to specify intermodule dependencies so that when I make a module, all of its dependent modules are rebuilt (if changed).

My CMakeLists.txt file typically looks like this:

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/")

How can I modify such a CMakeLists file to specify other dependent project(s)?

Upvotes: 1

Views: 446

Answers (1)

hate-engine
hate-engine

Reputation: 2350

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.

Upvotes: 1

Related Questions