Project shared with Cmake

Asked

Viewed 77 times

1

I have a project with the following extrusion:

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 File of Project A is as follows:

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 don’t put this include the cmake finds all dependencies and compiles cute. But since I need to include he can’t even find the file, it’s like mine include_directories propagate to others cmake? Wanted to make a dependency system a little more dynamic.

  • (1) is confused... Projectob and Projectoc are really ? projects generate a lib ? in Cmakelists.txt of B and C projects there are "add_library(Projetob)" and "add_library(Projetoc)" commands? or actually there is only one "project", Project A, which uses the sources of "projects" B and C ? (2) Another thing, I find strange two commands "target_link_libraries"" for Project A, may even work, I don’t know, but the normal is that we use only one "target_link_libraries", and put the various libs in this command "target_link_libraries", instead of using a command "target_link_libraries" by lib

  • Another thing I found strange: it should not have commands "add_subdirectory(Projectob)" and "add_subdirectory(Projectoc)" ?

1 answer

0

I can not get a general idea of your project, but anyway will a suggestion of how I would do, assuming that Projetob and Projetoc generate two libs that are used by the project A...not tested, may have errors

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

Projetoc/Cmakelists.txt

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.