[CMake] Linker Include Path

David Cole david.cole at kitware.com
Fri Oct 28 14:58:19 EDT 2011


Can you put a CMakeLists.txt in the xyz directory, like this?

add_library(xyz xyz.c)


And then in the src/CMakeLists file, do:

add_subdirectory(xyz)
...
add_library(src ${SOURCES})
target_link_libraries(src xyz)

Or is there some reason that xyz.c must be in a different directory,
but the same library/executable as the files listed in SOURCES?


On Fri, Oct 28, 2011 at 2:44 PM, Matthias Schweinoch
<matthias.schweinoch at gmx.de> wrote:
> Hi all,
>
>
> I'm using cmake (2.8.5) to build a set of C++ libraries. I have a project
> directory structure which is basically organized like this:
>
>
> package/component/CMakeLists.txt
> package/component/inc/foo.hpp
> package/component/src/foo.cpp
>
>
> Boiled down, my CMakeLists.txt for this component looks like this:
>
>
> SET(HEADERS inc/foo.hpp)
> SET(SOURCES src/foo.cpp)
> SET(LIBS whatever)
> INCLUDE_DIRECTORIES(inc)
> ADD_LIBRARY(MyLib ${HEADERS} ${SOURCES})
> TARGET_LINK_LIBRARIES(MyLib ${LIBRARIES})
>
>
> This has worked fine for me. Now, however, I would like to add another
> subdirectory to the src tree (this has organizational reasons), resulting in
> something like this:
>
>
> package/component/CMakeLists.txt
> package/component/inc/foo.hpp
> package/component/src/foo.cpp
> package/component/src/xyz/xyz.cpp
>
>
> I modified the SOURCES assignment in my CMakeLists.txt like so:
>
>
> SET(SOURCES src/foo.cpp src/xyz/xyz.cpp)
>
>
> While this does compile, it does not link. I assume that this is because the
> xyz.o is put in
>
>
> CURRENT_BINARY_OUTPUT/xyz/xyz.o
>
>
> and the linker does not include that subdirectory. If I move the source file
> up by one level (i.e. into the src directory), everything compiles and links
> just fine, but that's not really an acceptable solution. Is there some
> (portable) way to tell CMake to include the xyz output path so that xyz.o is
> found at link time?
>
>
>
> Thanks in advance for your help!
>
>
>  Matthias
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list