[CMake] Disable linker / only build object files

Adolfo Rodríguez dofo79 at gmail.com
Thu Apr 30 03:21:27 EDT 2009


This is not what you were asking for explicitly, but may solve your problem:

- If your subdirectories are all at the same depth (e.g., they all hang from
src/) you could just populate your source list in a variable set with the
PARENT_SCOPE option, and then generate your library (in src/) with all the
collected sources.

- If your sources are scattered across an arbitrary subdirectory structure
with varying depths, then the above will be a big pain. In this case you can
either accumulate a list of your source files in an environment variable
using SET(ENV{myenv} value), or, more elegantly, create a custom property
for this.

This topic has popped on the list quite recently (maybe one or two months
ago), so it may be a good idea to browse the archives to get more details on
the subject.

Cheers!


On Wed, Apr 29, 2009 at 7:29 PM, Tyler Roscoe <tyler at cryptio.net> wrote:

> I have a fairly complex library with a bunch of small pieces scattered
> throughout subdirectories.
>
> Each subdirectory has its own CMakeLists.txt. This is nice because the
> list of .cpp files for each subdirectory is right there in the
> subdirectory, and because these subdirectories behave just like all the
> other subdirectories in the system (you can go to them and build them
> and get something useful dropped into a results directory).
>
> What I would like is for each subdirectory to compile its .cpp files
> into object files and then stop. There is no need for each subdir to
> generate a library because the object files will later be collected into
> a single higher-level library.
>
> Is there a way to tell CMake to only compile a list of source files and
> not to link them? I tried setting CMAKE_CXX_LINK_EXECUTABLE,
> CMAKE_LINKER, and LINKER_LANGUAGE to nothing but the generated Makefiles
> still happily call g++.
>
> Should I give up on this approach and just list all my .cpp files in the
> CMakeLists for the higher-level. Maybe I could include() stubs from the
> subdirectories into my higher-level CMakeLists?
>
> A related problem: how can I get the path to the object files that are
> created in my binary directory? We are currently using this, but it's
> kinda ugly and probably quite fragile:
>
> if (WIN32)
>    set (TEST_OBJ_LOC
> ${${local_project_name}_BINARY_DIR}/${local_project_name}.dir/debug)
>    set (OBJ_EXTENSION ${CMAKE_CXX_OUTPUT_EXTENSION})
> else ()
>    string(REPLACE "/_build/.." "/" ABS_OBJ_LOC
> ${${local_project_name}_SRC})
>    set (TEST_OBJ_LOC
> ${${local_project_name}_BINARY_DIR}/CMakeFiles/${local_project_name}.dir${ABS_OBJ_LOC})
>    set (OBJ_EXTENSION .cpp${CMAKE_CXX_OUTPUT_EXTENSION})
> endif ()
>
>
> thanks,
> tyler
> _______________________________________________
> 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
>



-- 
Adolfo Rodríguez Tsouroukdissian

Robotics engineer
PAL ROBOTICS S.L
http://www.pal-robotics.com
Tel. +34.93.414.53.47
Fax.+34.93.209.11.09
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20090430/d6c34fc0/attachment.htm>


More information about the CMake mailing list