cmake buried in subdirectory?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

cmake buried in subdirectory?

Randy Heiland-2
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
Reply | Threaded
Open this post in threaded view
|

Re: cmake buried in subdirectory?

J. Caleb Wherry
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 <[hidden email]> 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

--

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
Reply | Threaded
Open this post in threaded view
|

Re: cmake buried in subdirectory?

Randy Heiland-2
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 <[hidden email]> 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 <[hidden email]> 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
<a href="tel:(615)%20708-5651" value="+16157085651" target="_blank">+1 (615) 708-5651


--

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
Reply | Threaded
Open this post in threaded view
|

Re: cmake buried in subdirectory?

J Decker


On Wed, Oct 4, 2017 at 6:22 PM, Randy Heiland <[hidden email]> wrote:
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.

:) they could still 'cmake cmake' in the top dir :) 

you could add something like

if( ${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_SOURCE_DIR} )
  message( FATAL_ERROR "dont' run cmake in this directory" ) # or something
endif() 

but you don't need to add the .. in the project() just in the sources added to add_library() or add_executable()

I'd probably SET( SOURCE_ROOT ${CMAKE_SOURCE_DIR}/.. ) if it was in a location where you were... and then add sources as... 
add_executable ( mySimpleProgram ${SOURCE_ROOT}/main.c )


 
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 <[hidden email]> 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 <[hidden email]> 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
<a href="tel:(615)%20708-5651" value="+16157085651" target="_blank">+1 (615) 708-5651


--

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


--

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
Reply | Threaded
Open this post in threaded view
|

Re: cmake buried in subdirectory?

Michael Jackson
In reply to this post by Randy Heiland-2
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 <[hidden email]> on behalf of Randy Heiland <[hidden email]>
Date: Wednesday, October 4, 2017 at 9:23 PM
To: "J. Caleb Wherry" <[hidden email]>
Cc: "[hidden email]" <[hidden email]>
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 <[hidden email]> 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 <[hidden email]> 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>[hidden email]
   
   
   
   
   
   
   
   
   
    --
   
    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


--

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