[CMake] CMakeLists.txt in different place than source

J Decker d3ck0r at gmail.com
Wed Jun 13 08:56:53 EDT 2018


On Tue, Jun 12, 2018 at 7:22 PM Andrew White <andrew.white at audinate.com>
wrote:

> I have a situation where I want my CMakeLists.txt in a different place
> than my source.
>
> e.g.:
>
> /some/path/project/CMakeLists.txt
> /other/path/source/src/a.c
> /other/path/source/include/a.h
>
> Is there an easy way to say "process this CMakeLists.txt as if it were in
> /other/path/source" (at least as far as file paths are concerned)?
>
> e.g.:
>
> add_library(my_lib
>         src/a.c
>         include/a.h
> )
>
> target_include_directories(my_lib PUBLIC include)
>
> I know I can add a full path prefix to every file, but there are a lot of
> them.  I'm hoping for a shortcut.
>

You can define a variable to define the base of the sources....
set( SOURCE_ROOT /some/path )

could be set relative to the current cmake path per cmake that uses those
souces... and then just prefix it

add_library(my_lib
        ${SOURCE_ROOT}/src/a.c
        ${SOURCE_ROOT}/include/a.h
)



>
> --
> Andrew
>
>
> --
>
> 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:
> https://cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180613/7d82130a/attachment.html>


More information about the CMake mailing list