<div dir="ltr">oh cool<div>adding target_include_directories(lib1 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/headers)</div><div><br></div><div>and then I can just use #include "lib1" where needed. No more of those very static paths!</div><div><br></div><div>Thank you very much!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 4:08 PM, iosif neitzke <span dir="ltr"><<a href="mailto:iosif.neitzke+cmake@gmail.com" target="_blank">iosif.neitzke+cmake@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I would think<br>
<span class=""><br>
add_library( lib1 SHARED lib1/lib1.c )<br>
</span>target_include_directories( lib1 PUBLIC lib1/headers )<br>
<br>
is simpler.  Are the generator expressions needed for target export<br>
install commands, and is exporting targets at install preferred to<br>
add_subdirectory() ?<br>
<br>
On Thu, Dec 10, 2015 at 1:48 AM, Owen Alanzo Hogarth<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:gurenchan@gmail.com">gurenchan@gmail.com</a>> wrote:<br>
> my main CMakeLists.txt file already has a few directives that move the libs<br>
> to an output folder so the binaries go to /bin while static and shared<br>
> libraries go to /lib<br>
><br>
> set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)<br>
> set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)<br>
> set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)<br>
><br>
><br>
> it seems like this line in your reply above<br>
> install( TARGETS lib1 lib2 DESTINATION lib )<br>
><br>
> moves the shared libraries to the lib folder and this line below moves the<br>
> header files to the newly created include directory.<br>
><br>
> install( FILES lib1/headers/lib1.h lib2/headers/lib2.h DESTINATION include )<br>
><br>
> is that right?<br>
><br>
> On Thu, Dec 10, 2015 at 1:46 PM, Attila Krasznahorkay<br>
> <<a href="mailto:attila.krasznahorkay@gmail.com">attila.krasznahorkay@gmail.com</a>> wrote:<br>
>><br>
>> Hi Owen,<br>
>><br>
>> This seems like a textbook example of using target_include_directories(…)<br>
>> with generator expressions. Let’s take the example where:<br>
>><br>
>> lib1/headers/lib1.h<br>
>> lib1/lib1.c<br>
>> lib2/headers/lib2.h<br>
>> lib2/lib2.c<br>
>><br>
>> If you want to be able to include lib1.h and lib2.h with simply<br>
>><br>
>> #include “lib1.h”<br>
>><br>
>> and<br>
>><br>
>> #include “lib2.h”<br>
>><br>
>> in your user code, and in the library code itself, you’d do something<br>
>> like:<br>
>><br>
>> add_library( lib1 SHARED lib1/lib1.c )<br>
>> target_include_directories( lib1 PUBLIC<br>
>>    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/lib1/headers><br>
>>    $<INSTALL_INTERFACE:include> )<br>
>><br>
>> add_library( lib2 SHARED lib2/lib2.c )<br>
>> target_include_directories( lib2 PUBLIC<br>
>>    $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/lib2/headers><br>
>>    $<INSTALL_INTERFACE:include> )<br>
>> target_link_libraries( lib2 lib1 )<br>
>><br>
>> install( FILES lib1/headers/lib1.h lib2/headers/lib2.h DESTINATION include<br>
>> )<br>
>> install( TARGETS lib1 lib2 DESTINATION lib )<br>
>><br>
>> In this setup “lib1” should get a -I${CMAKE_SOURCE_DIR}/lib1/headers flag,<br>
>> and “lib2” should get both -I${CMAKE_SOURCE_DIR}/lib1/headers and<br>
>> -I${CMAKE_SOURCE_DIR}/lib2/headers. Finally the headers both get installed<br>
>> into the same include directory, so an outside user will just have to be<br>
>> able to find that one directory. (Or if you export CMake’s targets, the<br>
>> lib1/2 imported targets will know that their header files are in that<br>
>> directory.)<br>
>><br>
>> Cheers,<br>
>>         Attila<br>
>><br>
>> > On Dec 10, 2015, at 12:07 AM, Owen Alanzo Hogarth <<a href="mailto:gurenchan@gmail.com">gurenchan@gmail.com</a>><br>
>> > wrote:<br>
>> ><br>
>> > hi<br>
>> ><br>
>> > I am building a shared library project that's composed of many smaller<br>
>> > shared library files.<br>
>> ><br>
>> > Here's the main shared library project and a list of all the sub<br>
>> > projects.<br>
>> ><br>
>> > SET(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/headers/main_lib.h)<br>
>> > SET(SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/main_lib.c)<br>
>> > SET(TARGET_LIBS core_math point2d line2d quad2d timer_utils)<br>
>> ><br>
>> > ADD_LIBRARY(main_lib SHARED ${SRC_FILES} ${HEADER_FILES})<br>
>> > TARGET_LINK_LIBRARIES(core_engine ${TARGET_LIBS})<br>
>> ><br>
>> > i have each module setup like this.<br>
>> > module<br>
>> > module/headers/module.h<br>
>> > module/module.c<br>
>> ><br>
>> > then the module.c will look like this<br>
>> > #include "headers/module.h"<br>
>> ><br>
>> > the file main_lib.h depends on all those target libs, which makes my<br>
>> > main_lib.h file's include statement look like this<br>
>> ><br>
>> > #include "../../module/headers/module.h"<br>
>> > #include "../../module1/headers/module1.h"<br>
>> > #include "../../module2/headers/module2.h"<br>
>> ><br>
>> ><br>
>> > is there any way that I can clean up these includes?<br>
>> ><br>
>> > For example if I want to use io functions I can just do #include<br>
>> > <stdio.h> or #include <math.h><br>
>> ><br>
>> > for math functions.<br>
>> ><br>
>> > I would like to make my include statements not relative to the files<br>
>> > actual location, the way it's currently hard coded.<br>
>> > --<br>
>> ><br>
>> > Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
>> ><br>
>> > Please keep messages on-topic and check the CMake FAQ at:<br>
>> > <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
>> ><br>
>> > Kitware offers various services to support the CMake community. For more<br>
>> > information on each offering, please visit:<br>
>> ><br>
>> > CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
>> > CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
>> > CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
>> ><br>
>> > Visit other Kitware open-source projects at<br>
>> > <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
>> ><br>
>> > Follow this link to subscribe/unsubscribe:<br>
>> > <a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
>><br>
><br>
><br>
> --<br>
><br>
> Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
><br>
> Please keep messages on-topic and check the CMake FAQ at:<br>
> <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
><br>
> Kitware offers various services to support the CMake community. For more<br>
> information on each offering, please visit:<br>
><br>
> CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
><br>
> Visit other Kitware open-source projects at<br>
> <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> <a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>
--<br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/cmake" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a></div></div></blockquote></div><br></div>