[CMake] Question regarding source tree structure and how to find libraries easily within that structure

Michael Hertling mhertling at online.de
Tue Mar 6 01:25:15 EST 2012


On 03/04/2012 11:01 AM, Andreas Guther wrote:
> Hello,
> 
> thanks for the responses. The problem I have is, that we have more than one application in the directory. So if I put an CMakeLists.txt in the Src directory I do not have the choice (only by options). I would prefer a solution where I change into the application directory I want to build and create workspace etc. from there. The created workspace should then also build all necessary libraries for the application.
> 
> Any ideas on this?

In Application_1/CMakeLists.txt, e.g., do:

SET(Library_1_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../Library_1
    CACHE PATH "Library_1 source directory")
...
ADD_SUBDIRECTORY(${Library_1_SOURCE_DIR} Library_1)

Do the same for Library_2 and every other prerequisite project which

- has a source tree external to Application_1
- you want to be built along with the latter

and finally: TARGET_LINK_LIBRARIES(Application_1 Library_1 ...)

If the fallback value of Library_1_SOURCE_DIR once doesn't suit, you
can set it on the command line or in the GUI before (re)configuring.

Regards,

Michael


More information about the CMake mailing list