[CMake] cmake buried in subdirectory?

Michael Jackson mike.jackson at bluequartz.net
Thu Oct 5 09:14:32 EDT 2017


You are over thinking it. As someone else stated, check if the build directory and the source directory are the same and if they are you FATAL_ERROR with a message. Otherwise you can put a single CMakeLists.txt file in the top level to kick things off.

Plus, I think it is starting to become fairly understood that using the source dir as the build dir is a "bad idea" at this point in software engineering. You are just complicating things.

--
Mike Jackson 

-----Original Message-----
From: CMake <cmake-bounces at cmake.org> on behalf of Randy Heiland <randy.heiland at gmail.com>
Date: Wednesday, October 4, 2017 at 9:23 PM
To: "J. Caleb Wherry" <calebwherry at gmail.com>
Cc: "cmake at cmake.org" <cmake at cmake.org>
Subject: Re: [CMake] cmake buried in subdirectory?

    Thanks for the reply. In my case, I didn't even want the CMakeLists in the top-level dir. I didn't want to contaminate my top-level dir with anything related to CMake. This would avoid, for example, an accidental overwrite of an existing Makefile if one was to do a 'cmake .' in the the top dir.
    It's quite possible I'm over-thinking this; I was just curious if it's even possible. Seems like it should be. 
    
    -Randy
    
    
    On Wed, Oct 4, 2017 at 4:30 PM, J. Caleb Wherry <calebwherry at gmail.com> wrote:
    
    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 <http://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 <tel:(615)%20708-5651>calebwherry at gmail.com
    
    
    
    
    
    
    
    
    
    -- 
    
    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




More information about the CMake mailing list