Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
CMake one build directory for multiple projects with seperate context

I'm trying to build multiple projects within one build directory with the following structure:

  |------ CMakeLists.txt (The main Cmake)
  |
  |------ ProjectAPP
  |          |----- .c/h files
  |          |----- sdh_config.h
  |          |----- CMakeList.txt
  |
  |------ ProjectDFU
  |          |----- .c/h files
  |          |----- sdh_config.h
  |          |----- CMakeList.txt
  | 
  |-------- SDK
  |          |---- SDK used by both projects

The idea would be to build two independent projects, both built on top of one single SDK. Note that both projects rely on a different configuration of the SDK, done by their respective sdk_config.h.

The main CMakeList.txt looks like this:

cmake_minimum_required(VERSION 3.22)

project(project)

add_dependency(ProjectAPP)
add_dependency(ProjectDFU)

add_custom_target(app DEPENDS ${exec_target_app} 
    ...
)

add_custom_target(dfu DEPENDS ${exec_target_dfu} 
    ...
)

add_custom_target(merge DEPENDS app dfu
    ...
)

Basically my only use of building the two projects in the same place is that I'm then able to have targets depending on both executables so I can then do something with that.

My problem:

The SDK, cmake based, is fragmented in hundreds of small libraries like this:

add_library(lib INTERFACE
    "file1.c"
    "file2.c"
)

Most of theses libraries will be used by both projects but with different build parameters (cf. sdk_config.h).

Where I'm at right now, I'm getting the following error:

add_library cannot create target "lib" because another target with the same name already exists. 
The existing target is an interface library created in source directory "ProjectAPP". 
See documentation for policy CMP0002 for more details.

My question:

What would be the best way to isolate both projects in two different build contexts while still being able to have dependencies on each project at root level?

Thank you in advance for any help.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Answering my own question, I'm not sure if it'ss the best way to handle this but cmake ExternalProject solved my problem.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda