Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!