Hello,
I am working on a file structure with several CMakeLists.txt.
EDIT : Does it make sense to have this deep structure ? Visual Studio seems not to be able to mimic it in Solution / projects (tests wouldn’t be nested in the lib) ? If not, maybe I shoud review my structure before submitting my question.
I must do a .exe, a .lib, and tests associated to the .lib.
So here is the file structure :
├── MyEcutable
│ ├── CMakeLists.txt
│ └── src
│ ├── CMakeLists.txt
│ ├── x.h
│ ├── x.cpp
│ ├── y.h
│ ├── y.cpp
│ └── main.cpp
├── MyLibrary
│ ├── CMakeLists.txt
│ ├── include
│ │ └── a.h
│ ├── src
│ │ ├── CMakeLists.txt
│ │ ├── a.h
│ │ └── a.cpp
│ └── test
│ ├── CMakeLists.txt
│ └── test_a.cpp
└── CMakeLists.txt
As I need to link the test to the library, in MyLibrary/CMakeLists.txt, I did :
set(LIB_PROJECT_NAME "MyLib" PARENT_SCOPE)
The purpose was to make ${LIB_PROJECT_NAME}
visible in ./CMakeLists.txt
add_subdirectory(MyLib)
message(${LIB_PROJECT_NAME})
But then I get the message :
CMake Error at MyLib/src/CMakeLists.txt:5 (target_sources):
Cannot specify sources for target "PRIVATE" which is not built by this
project.
The concerned line is the second instruction in :
add_library(${LIB_PROJECT_NAME} STATIC)
target_sources(${LIB_PROJECT_NAME}
PRIVATE
a.cpp
PUBLIC
../include/a.h)
I have no error if I remove PARENT_SCOPE.