mercredi 2 décembre 2020

How to break a cyclic dependency in CMakeLists

I have the following directory structure with a set of c++ source files and header files which needs compiled using CMake.

FilmEvents
  FilmEventManagement
     a1.cpp a1.hpp a2.cpp a2.hpp 
  FilmEventProducers
     b1.cpp b1.hpp b2.cpp b2.hpp

apart from various other files. I am just adding the bits that matter both here and within the CMakeLists.txt files.

CMakeLists.txt for FilmEvents

add_subdirectory(FilmEventManagement)
add_subdirectory(FilmEventProducers)

CMakeLists.txt for FilmEventManagement

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} source)
project(film_event_management)
add_library(${PROJECT_NAME} STATIC ${source})
target_link_libraries(${PROJECT_NAME} PRIVATE film_event_producers)
target_include_directories(${PROJECT_NAME} PRIVATE ${film_event_producers_SOURCE_DIR})

CMakeLists.txt for FilmEventProducers

include_directories(${CMAKE_CURRENT_SOURCE_DIR})
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} source)
project(film_event_producers)
add_library(${PROJECT_NAME} STATIC ${source})
target_link_libraries(${PROJECT_NAME} PRIVATE film_event_management)
target_include_directories(${PROJECT_NAME} PRIVATE ${film_event_management_SOURCE_DIR})
When i try to compile, i get this error
In file included from /home/badri/dummy/a1.cpp:4:
/home/badri/dummy/a1.hpp:9:10: fatal error: b1.hpp: No such file or directory
 #include "b1.hpp"

But b2.cpp does use a1.hpp via b2.hpp and this path has no issues. There seems to be some cyclic dependency that I am unable to address.

Is there a way I could get CMake to fix it with, say, some keywords ?

Aucun commentaire:

Enregistrer un commentaire