Project shared with CMake

1

I have a project with the following structure:

Projeto A:
|   CMakeLists.txt
|   main.cpp
    | #include "ProjetoB/ClassB.cpp"
    | #include "ProjetoC/ClassC.cpp"
|   vendor/
        |   Projeto B:
            |   CMakeLists.txt
            |   ClassB.cpp
            |   Helper.h
        |   Projeto C:
            |   CMakeLists.txt
            |   ClassC.cpp
                |   #include "ProjetoB/Helper.h"

My CMake Project A file looks like this:

cmake_minimum_required(VERSION 3.6)
project(ProjetoA)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/")

set(SOURCE_FILES main.cpp)
add_executable(ProjetoA ${SOURCE_FILES})

MACRO(LINK_PROJECT_LIBRARY lib)
    target_link_libraries(ProjetoA ${lib})
ENDMACRO()

include_directories(vendor/ProjetoB/)
LINK_PROJECT_LIBRARY(ProjetoB)

include_directories(vendor/ProjetoC/)
LINK_PROJECT_LIBRARY(ProjetoC)

My problem starts with me trying to include #include "ProjetoB/Helper.h" in ClassC, because if I do not put this include cmake finds all dependencies and compiles cute. But as I need to include it does not even find the file, does my include_directories propagate to the other cmake? I wanted to make a dependency system a little more dynamic.

    
asked by anonymous 30.03.2017 / 03:44

1 answer

0

I can not get a general idea of your project, but anyway a hint of how I would do, assuming that ProjectB and ProjectC generate two libs that are used by project A ... not tested, may have errors

ProjectA / CMakeLists.txt

cmake_minimum_required(VERSION 3.6)
project(ProjetoA)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/")

set(SOURCE_FILES main.cpp)

# INC_B e INC_C são exportados para os CMakeLists.txt dos sub-diretórios
set(INC_B vendor/ProjetoB)
set(INC_C vendor/ProjetoC)

add_subdirectory(ProjetoB)
add_subdirectory(ProjetoC)

add_executable(ProjetoA ${SOURCE_FILES})

target_link_libraries(ProjetoA ProjetoB ProjetoC)

ProjectC / CMakeLists.txt

...
...
# em ClassC.cpp utilizar apenas '#include "Helper.h"'
include_directories(${INC_B})
...
...
add_library(ProjetoC classC.cpp)
...
...
    
30.03.2017 / 04:37