Hi,
how can I set up a source folder that is shared between different cmake projects?
I’d like to have a folder structure like that inside my repository
- Main application (CMake project)
- Data viewer tool (CMake project)
- Data import library for other applications (CMake project)
- Data structure (shared source)
- Special functions (shared source)
We’ve had it that way before we started to use CMake and of course I have to admit that it is not best practice to blow up a repository like that, but it was working perfectly.
When we started to use CMake, we didn’t see a way around splitting the repository up and turn the shared folders into static libraries. However, I think our development state is not ready for that yet. There’s still too much debugging going on and those static libraries in extra repositories checked out automatically by CMake are making it unnecessarily complicated. I do think that it’s a totally neat feature and I’d like to have it that way once we publish. But right now it’s slowing us down way too much and I’d really like to have my single repository with shared source folders back.
How can I set up a source folder without making it exclusive to one CMake project?
target_sources(
PROJECT_NAME PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/source1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source1.h
${CMAKE_CURRENT_SOURCE_DIR}/source2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source2.h
${CMAKE_CURRENT_SOURCE_DIR}/source3.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source3.h
)
I’ve tried to replace PROJECT_NAME with variable ${CMAKE_PROJECT_NAME}, but that didn’t work.
Best regards
edit: Of course I played around with PRIVATE keyword as well still I didn’t find the right combination. Maybe I was doing it wrong.
edit2: I’m beginning to think that code section would be a better place for this question. Sorry for the confusion.