[CMake] cmake buried in subdirectory?

J. Caleb Wherry calebwherry at gmail.com
Wed Oct 4 16:30:32 EDT 2017


There is no reason why this shouldn't work, I do something similar where
everything except my top-level CMakeLists is shoved into a subdirectory
(away from the src code location).

You don't have to muck with the project macro at all, not sure what you are
trying to accomplish with that? That just sets the name of the project.

All you have to be aware of is all the paths are now with respect to both
the CMakeLists and where ever you put your binary dir. So doing something
like the below allows you to reference things in your source tree
(depending on how far you away form the root, obviously):

get_filename_component(SourceRoot "${CMAKE_CURRENT_SOURCE_DIR}/../../"
ABSOLUTE)

The normal structure of the CMake file doesn't change, nothing special has
to be done with the project macro. Unless you have a more specific error,
that's about all the advice I have.

-Caleb


On Wed, Oct 4, 2017 at 3:16 PM, Randy Heiland <randy.heiland at gmail.com>
wrote:

> Hello,
>
> Simple question... can I/how can I keep my top-level cmake-related stuff
> in a subdirectory of my main project directory? E.g.:
>
> /myproj
>   /cmake
>     CMakeLists.txt
>
> and then in the /cmake, I create a /build from which I attempt:  cmake ..
>
> I tried something as simple as this in my CMakeLists.txt, but it didn't
> seem to work:
> project (../myproj)
>
>
> The primary reason I'd like to do this is to hide/make optional the cmake
> build approach (and keep in place an existing/traditional Makefile in the
> parent directory). Play along...
>
> thanks, Randy
>
> --
>
> 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
>



-- 
J. Caleb Wherry
*Scientific Software Engineer*

<http://www.calebwherry.com>
http://www.calebwherry.com
+1 (615) 708-5651
calebwherry at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20171004/7fc6b1d4/attachment.html>


More information about the CMake mailing list