[CMake] How to make a hierarchical application using CMake?

Fred Baksik fdk17 at ftml.net
Mon Oct 14 14:10:54 EDT 2019



On Mon, Oct 14, 2019, at 9:13 AM, David Aldrich wrote:
> Hi

> 

> I am trying to convert a large software project from makefiles to CMake. The project is organised as a set of shared ‘star’ libraries, linked to a static ‘kernel’ library. The current directory arrangement is:

> 

> |--stars

> | |-- star1_lib

> | |-- source files

> | |-- makefile

> | |-- star2_lib

> | |-- source files

> | |-- makefile

> | |-- solibs

> | |-- Release

> | |-- <star>.so files

> |

> |--kernel

> | |-- source files

> | |-- makefile

> | |-- Release

> | |-- kernel.a

> |

> |--application

>  |-- makefile

>  |-- Release

>  |-- myapp.exe

> 

> In high-level terms, how could I implement this using CMake, such that invoking ‘make’ in directory ‘application’ invokes a make of each shared and static library, and links them to form ‘myapp.exe’?

> 

> (I understand the basics of CMake, the issue here is how to handle the make of source code and libraries spread across a directory hierarchy).

> 

> Best regards

> 

> David

> 

> 
add_subdirectory() can accept relative paths to outside the "root" source tree.
So the main CMakeLists.txt would be located in ./application.
Then do:
 add_subdirectory(../kernel kernel)
add_subdirectory(../stars/stars1_lib stars1_lib)

./kernel/CMakeLists.txt would list it's files, and etcetera.

I've use this method in the past for handling applications that are meant to target Windows, Linux, and embedded systems.
Then by using variables to determine with platform / target ertain kernel and library characteristics are used.
Everything is built in the build directory for that particular platform / target.
This allows for app_target1, app_target2, app_target3, ..., build directories to be totally independent.

--
F
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20191014/c7a24570/attachment.html>


More information about the CMake mailing list