[CMake] Question regarding project structure

David Cole david.cole at kitware.com
Thu Sep 16 06:57:31 EDT 2010


On Thu, Sep 16, 2010 at 6:45 AM, David Aldrich <David.Aldrich at eu.nec.com>wrote:

> Hi
>
> I have now successfully configured CMakeLists files to create some of our
> static and dynamic libraries using CMake.  I would now like some advice on
> how to configure these separate build files as a single project.
>
> Here's what our current folder structure is like:
>
> Trunk ------- Kernel      <==== a static library containing main()
>         |
>         |--- DynLibs     <==== containg multiple folders containing
>         |                      proprietary source code, each folder
>         |                      builds one shared library
>         |
>         |--- MyExe       <==== contains top-level makefile that
>                                a) links Kernel static library into an .exe
>                                b) calls makefiles for the dynamic libraries
>
> This structure may not be ideal from a CMake standpoint, but I would like
> to maintain it to ease the transition from pure gnu make to CMake.
>

CMake is flexible about where source files are located. This structure looks
perfectly reasonable.


> What would I need to put in the top-level CMakeLists file
> (MyExe/CMakeLists.txt) to reference the other CMakeLists files?
>

Something like this should work:

cmake_minimum_required(VERSION 2.8)
project(MyExe)

add_subdirectory(../Kernel Kernel)
add_subdirectory(../DynLibs DynLibs)

add_executable(MyExe exe.cxx)
target_link_libraries(MyExe Kernel)


If your DynLibs build dll files on Windows, the easiest way to get them to
load into the exe is to use the RUNTIME_OUTPUT_DIRECTORY target property.
(Just put the exe and the dlls all in the same folder with each other...)
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#prop_tgt:RUNTIME_OUTPUT_DIRECTORY

Or just once in your top level CMakeLists, the
CMAKE_RUNTIME_OUTPUT_DIRECTORY variable:
http://www.cmake.org/cmake/help/cmake-2-8-docs.html#variable:CMAKE_RUNTIME_OUTPUT_DIRECTORY



> Should each CMakeLists file have its own Project name, or should they all
> be the same?
>

Only the top one *needs* a project command, but if you do have project
commands in your other CMakeLists.txt files, they should definitely each be
unique.


> Any advice would be much appreciated.
>
> Best regards
>
> David
> _______________________________________________
> 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
>


HTH,
David C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100916/afd94f97/attachment.htm>


More information about the CMake mailing list