Reputation: 28511
project/
CMakeList.txt // top level
src/
lib/
CMakeList.txt // lib folder, builds all libraries
lib1/
lib2/
lib2 depends on lib1, they are setup like this:
# Link the Unity library
include_directories(unity)
add_library(unity STATIC unity/unity.c unity/unity.h)
# Install the Unity library
install(TARGETS unity DESTINATION lib)
install(FILES unity.h DESTINATION includes)
# Include parallax libraries
include_directories(parallax)
# Simple text library
add_library(simpletext STATIC parallax/text/libsimpletext/libsimpletext.c parallax/libsimpletext/simpletext.h)
install(TARGETS simpletext DESTINATION lib)
install(FILES simpletext.h DESTINATION includes)
# Simple tools library
add_library(simpletools STATIC parallax/Utility/libsimpletools/libsimpletools.c)
target_link_libraries(simpletools simpletext)
target_link_libraries(unity simpletools)
install(TARGETS simpletools DESTINATION lib)
install(FILES simpletools.h DESTINATION includes)
But when compiled, the simpletext.h
header file is not found in simpletools
.
How do I add the header file in the correct way?
Upvotes: 0
Views: 756
Reputation: 13698
install
works as separate target. In make file it is make install
in Visual Studio it is separate project. So you shouldn't place anything your compilation depends on to install
. You can use file(copy ...)
if you need to copy file during cmake run. or you can just include the folder your header are contained in and not copy anything at all. I don't see any clue why do you copy the header at all.
If you need to copy your file every time the cmake command is run you need to have the following:
FILE(COPY simpletools.h DESTINATION includes)
But if you have, for example, simpletools.h
in lib1
and you need it included in lib2
you just need to include the lib2 folder in lib1 CMake file:
INCLUDE_DIRECTORIES(lib2)
Upvotes: 2