Hi Muhammad, > On 08.03.2016, at 06:17, Muhammad Osama <osam...@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