[CMake] Create main and sub-projects; be able to compile them together and individually.

Nicholas Braden nicholas11braden at gmail.com
Tue Mar 8 20:19:25 EST 2016


Yep, just make each project act independently with no knowledge of the
superproject, and have the superproject glue it all together as a
convenience for the user if they don't want to manually build things
separately or if they don't have existing installs. That's what I am doing
with my projects.

On Tue, Mar 8, 2016 at 7:17 PM, Muhammad Osama <osama94 at gmail.com> wrote:

> Wow, this is powerful! Question; Will I be able to compile the sub-project
> individually?
> Because as I see this is what we will use in the root/CMakeLists.txt, but
> what about the sub-dirs which I really want to be "independent" if the user
> wants.
>
> On Tue, Mar 8, 2016 at 5:13 PM, Nicholas Braden <
> nicholas11braden at gmail.com> wrote:
>
>> Example simple usages from my personal projects:
>>
>> https://github.com/LB--/events/blob/499ba78b923b40f77cc832b6a5d414240209ac96/CMakeLists.txt
>>
>> https://github.com/LB--/simple-platformer/blob/1bba3dd2d8ed1cdae74ce1b77c4ab99878fa59a6/CMakeLists.txt
>>
>> More complex usage in hunter:
>> https://github.com/ruslo/hunter
>>
>> With ExternalProject you can have it either download from version control
>> / source archive, or you can use a local existing folder. I think in your
>> case you just need to point it to your existing project folders and forward
>> the appropriate arguments. There is a lot of customizability to it
>> (customizing each step, for example). If you want I could make an example
>> exactly like your provided example directory structure, but I think both of
>> my personal usages closely match what you are wanting to do.
>>
>> On Tue, Mar 8, 2016 at 7:02 PM, Muhammad Osama <osama94 at gmail.com> wrote:
>>
>>> Thank you for your suggestion Nicholas, I have never used
>>> ExternalProject_Add before and can't find a related example to my project.
>>> Would you know an example that uses it?
>>>
>>> On Tue, Mar 8, 2016 at 10:38 AM, Nicholas Braden <
>>> nicholas11braden at gmail.com> wrote:
>>>
>>>> Have you looked into ExternalProject_Add? It allows just using a local
>>>> path instead of downloading a remote repository:
>>>>
>>>> https://cmake.org/cmake/help/latest/module/ExternalProject.html
>>>>
>>>> On Tue, Mar 8, 2016 at 12:12 PM, Muhammad Osama <osama94 at gmail.com>
>>>> wrote:
>>>>
>>>>> Hi Jan,
>>>>>
>>>>> Thank you for your reply, I am in the similar situation, have a very
>>>>> similar implementation using *target_*** *but since I don't do that
>>>>> for ALL the dependencies, I am unable to cmake or compile individual
>>>>> projects in the sub directories. So, few questions;
>>>>>
>>>>> 1. This still requires me to run cmake on the root CMakeLists.txt to
>>>>> set the flags and what not before I run the sub project to make it correct?
>>>>> 1a. If so, how can I make the CMakeLists.txts in the sub directories
>>>>> independent of the root one if I want to just compile the sub-project and
>>>>> not cmake the whole thing?
>>>>> 2. Another question is that your implementation, does it not include a
>>>>> config file? In theory you're copy pasting most of the dependencies in the
>>>>> CMakeLists.txt of root into the sub-dir ones? Is there a better way to do
>>>>> this?
>>>>>
>>>>> Thank you!
>>>>>
>>>>> On Tue, Mar 8, 2016 at 2:02 AM, 🐋 Jan Hegewald <jan.hegewald at awi.de>
>>>>> wrote:
>>>>>
>>>>>> Hi Muhammad,
>>>>>>
>>>>>> > On 08.03.2016, at 06:17, Muhammad Osama <osama94 at gmail.com> wrote:
>>>>>> >
>>>>>> > Hi, I am new to cmake and really hope am doing this correctly. I
>>>>>> asked stackoverflow but didn't get a good enough answer for my specific
>>>>>> problem here;
>>>>>> >
>>>>>> > If I want root/sub-directories/ as separate sub-projects that can
>>>>>> be compiled using the individualCMakeLists.txts in their folders I find
>>>>>> myself literally copy pasting almost the entire root file CMakeLists.txt
>>>>>> per sub-directory.
>>>>>> >
>>>>>> > I was wondering if there is a better way to have a main project and
>>>>>> then sub-projects that get the shared dependencies from main project and
>>>>>> can be compiled without cmake-ing the root CMakeLists.txt. My directory
>>>>>> structure is;
>>>>>> >
>>>>>> > CMakeLists.txt (root project)
>>>>>> > | __ sub_dir-1
>>>>>> > | __ | __ CMakeLists.txt (sub-project)
>>>>>> > | __ sub_dir-2
>>>>>> > | __ | __ CMakeLists.txt (sub-project)
>>>>>> > | __ sub_dir-3
>>>>>> > | __ | __ CMakeLists.txt (sub-project)
>>>>>>
>>>>>> I basically have the same project structure as you describe. I am
>>>>>> also not sure what the best practice is here, but this is what I currently
>>>>>> do:
>>>>>> I set all dependencies where they are required: right in the local
>>>>>> CMakeLists.txt, i.e. sub_dir-1/CMakeLists.txt. Then "export" all required
>>>>>> include/define/compiler flags dependencies via INTERFACE or PUBLIC flags of
>>>>>> the various target_*** cmake functions, as appropriate. The sub-projects
>>>>>> are added via add_subdirectory in cmake.
>>>>>> This way I can build each CMakeLists.txt individually if needed but
>>>>>> still have everything DRYish.
>>>>>>
>>>>>> HTH,
>>>>>> Jan
>>>>>>
>>>>>> --
>>>>>>
>>>>>> Powered by www.kitware.com
>>>>>>
>>>>>> Please keep messages on-topic and check the CMake FAQ at:
>>>>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>>>>
>>>>>> Kitware offers various services to support the CMake community. For
>>>>>> more information on each offering, please visit:
>>>>>>
>>>>>> CMake Support: http://cmake.org/cmake/help/support.html
>>>>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>>>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>>>>
>>>>>> Visit other Kitware open-source projects at
>>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>>
>>>>>> Follow this link to subscribe/unsubscribe:
>>>>>> http://public.kitware.com/mailman/listinfo/cmake
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> *Muhammad Osama*
>>>>> Graduate Student
>>>>> Department of Electrical and Computer Engineering
>>>>> University of California, Davis
>>>>>
>>>>> --
>>>>>
>>>>> Powered by www.kitware.com
>>>>>
>>>>> Please keep messages on-topic and check the CMake FAQ at:
>>>>> http://www.cmake.org/Wiki/CMake_FAQ
>>>>>
>>>>> Kitware offers various services to support the CMake community. For
>>>>> more information on each offering, please visit:
>>>>>
>>>>> CMake Support: http://cmake.org/cmake/help/support.html
>>>>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>>>>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>>>>
>>>>> Visit other Kitware open-source projects at
>>>>> http://www.kitware.com/opensource/opensource.html
>>>>>
>>>>> Follow this link to subscribe/unsubscribe:
>>>>> http://public.kitware.com/mailman/listinfo/cmake
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> *Muhammad Osama*
>>> Graduate Student
>>> Department of Electrical and Computer Engineering
>>> University of California, Davis
>>>
>>
>>
>
>
> --
> *Muhammad Osama*
> Graduate Student
> Department of Electrical and Computer Engineering
> University of California, Davis
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160308/32752844/attachment.html>


More information about the CMake mailing list