Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with Multiple Projects in CMake

Tags:

c++

cmake

I am currently working on transitioning over a Visual C++ project (that has multiple subprojects inside of it) over to CMake.

There is one thing that I am not sure about – basically, to include the subprojects from the top level CMakeLists.txt file, I just utilize the add_subdirectory command, and reference the directories that these various subprojects are stored under.

However, I have one project that is in the same directory as my top level CMakeLists.txt file, and so I am wondering if it is still possible to include this file somehow? CMake does not allow me to call add_subdirectory on the existing PROJECT_BINARY_DIR (see below):

add_subdirectory(${PROJECT_BINARY_DIR}) #not allowed in CMake

I cannot think of another way for me to include this subproject into my CMake build. Any ideas?

like image 446
user1202422 Avatar asked Mar 19 '12 15:03

user1202422


1 Answers

All add_subdirectory does is add a subdirectory with a CMakeLists.txt file in it, and so it would not make sense to allow you to add the current directory. You can simply add the CMake logic to build that part of your project in the CMakeLists.txt file. If you would like to separate the logic, then you could put it in build_project.cmake, and then use include,

include(build_project.cmake)

You can include as many other CMake files as you like, and that CMake code will be evaluated as if it was pasted inline. So all the normal add_executable and similar commands would work.

like image 126
Marcus D. Hanwell Avatar answered Sep 24 '22 07:09

Marcus D. Hanwell