I have a directory structure as follows:
root
libA
CMakeLists.txt
ClassA.cpp
libB
CMakeLists.txt
ClassB.cpp
sharedCode
enums.h
AbstractClass.h
In the CMake file how can include the sharedCode directory? So that both classA (in libA) and classB (in libB) can use the enums.h and AbstractClass.h?
In the CMakeLists.txt I tried using:
add_subdirectory(../sharedCode)
but it gives the error
add_subdirectory not given a binary directory but the given source
directory "/root/sharedCode" is not
a subdirectory of "root/libA". When
specifying an out-of-tree source a binary directory must be explicitly
specified.
As the error says, when specifying a relative source directory outside of the current tree, you must also supply a 2nd argument that specifies the directory where the produced binary file will be placed.
Here's the documentation for add_subdirectory
:
The binary_dir specifies the directory in which to place the output files. If it is a relative path it will be evaluated with respect to the current output directory, but it may also be an absolute path. If binary_dir is not specified, the value of source_dir, before expanding any relative path, will be used (the typical usage). The CMakeLists.txt file in the specified source directory will be processed immediately by CMake before processing in the current input file continues beyond this command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With