0

I have a project that I am porting to cmake. The architecture of the sources is as follow:

src
 |- FolderA
     |-fileAa.cpp
     |-fileAb.cpp
     ...
 |- fileA.cpp
 |-CMakeLists.txt
 ...

The file fileA.cpp is as follow:

#include <FolderA/fileAa.cpp>
#include <FolderA/fileAb.cpp>

//etc

My CMakeFiles.txt is as follow (the files from FolderA ARE NOT included in the add_library function)

#...
add_library(... fileA.cpp ...)
#...

And it works well. When I tried to build the library, if I modify any files inside FolderA, only the file fileA.cpp is rebuilt and the library is remade.

However, when I generate my project for Xcode, the files inside FolderA are not shown. Is there a way to tell cmake that I want it to include the files inside FolderA in my Xcode project (and any other supported IDE) but without adding them to the list of files to compile for the add_library function?

I tried to set the property of the files in FolderA as HEADER and still include them in add_library (as mentioned here) and it sort of worked, but in Xcode the files were displayed in a flat hierarchy and I would like to keep the same structure:

What I want in Xcode:

|-FolderA
   |-fileAa.cpp
   |-fileAb.cpp
     ...
|- fileA.cpp

What I have in Xcode:

|-fileAa.cpp
|-fileAb.cpp
|-fileA.cpp
...

I there a way to tell cmake to include a folder and its content to the project generated for an IDE, without adding the files I want to the list of files to compile ?

Adrien
  • 439
  • 4
  • 15

1 Answers1

0

I solved my problem.

As mentioned here I need to use the files in a target for source_group to work. I used the trick that I mentionned of setting the sources of FolderA as header files and it worked perfectly:

file(GLOB COMPILED_SOURCES "*.cpp")
file(GLOB FOLDERA_SOURCES "FolderA/*.cpp")

set_source_files_properties(${FOLDERA_SOURCES} PROPERTIES HEADER_FILES_ONLY TRUE)

source_group(TREE ${PROJECT_SOURCE_DIR}/src FILES ${COMPILED_SOURCES} ${FOLDERA_SOURCES})

#...

<any function that create a target>(... ${COMPILED_SOURCES} ${FOLDERA_SOURCES} ... )

#...

Adrien
  • 439
  • 4
  • 15