[CMake] Using add_subdirectory to manage project dependencies that aren't actually in a subdirectory
Joe
jtcacct at gmail.com
Fri Sep 18 22:51:46 EDT 2015
Iosif Neitzke <iosif.neitzke+cmake at ...> writes:
>
> Why not just go one directory up? Add /path/to/CMakeLists.txt
> containing at least:
>
> add_subdirectory(A)
> add_subdirectory(B)
>
> https://github.com/toomuchatonce/cmake-examples/blob/master/staticlibs-
add_subdir/CMakeLists.txt
>
> On Fri, Sep 18, 2015 at 5:42 PM, Joe <jtcacct at ...> wrote:
> > Hi. I was hoping to get some guidance on if this is bad practice. I am
> > simply trying to find a way to manage internal dependencies of my project
> > but with a file structure that is distributed. It looks like this:
> >
> > /path/to/A
> >
> > /path/to/B
> >
> > B depends on A. I cannot change this directory structure. The solution we
> > have chose is to create the following:
> >
> > /path/to/modules/FindA.cmake:
> >
> > ...
> > if (NOT TARGET A)
> > set(PATH_TO_A ${CMAKE_CURRENT_LIST_DIR}../A)
> > add_subdirectory(${PATH_TO_A} ${PATH_TO_A}/build)
> > endif()
> > ...
> >
> > This way, A' CMakeLists is invoked and the library is compiled and built.
> > Then in B's CMakeLists.txt:
> >
> > ...
> > set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
> > ${CMAKE_CURRENT_LIST_DIR}/../modules)
> >
> > find_package(A)
> > add_executable(main_B src/main_B.cpp)
> > target_link_libraries(main_B A)
> > ...
> >
> > Is this bad practice? I tried to figure out find_package in CONFIG mode but
> > every example I've found seems complicated and obtuse. Thank you.
> >
> >
> >
> > --
> >
> > 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
Iosif, thanks for the reply. Unfortunately, I do not have control over that
(the long answer is that the projects are arranged in a Clearcase VOB
file structure). Honestly, what I really need is just a way to invoke a
CMakeLists.txt for a project that lives in a completely arbitrary place
on the filesystem. I tried to read the documentation, but I can't seem
to figure out if I'm supposed to use ExternalProject_Add or find_package.
If the answer is find_package, I can't seem to tell if I'm supposed to be
using it in MODULE mode or CONFIG mode. CONFIG mode seems really
confusing, which is why I came up with the approach used in the first post.
Basically, I use add_subdirectory() simply a mechanism to invoke another
project's CMakeLists.txt. I could have used include(), but I
liked the idea of distributing the build by using the second parameter of
add_subdirectory to build the project in it's own area.
More information about the CMake
mailing list