[CMake] CMake 3.5-CMAKE_BINARY_DIR is set to ${CMAKE_SOURCE_DIR} when calling add_subdirectory?

Attila Krasznahorkay attila.krasznahorkay at gmail.com
Mon Feb 22 05:17:13 EST 2016


Hi Gerry,

Setting these variables by hand sounds quite dangerous. I'm not sure how much this is meant to be supported.

There is a much more "native" way of doing this. You could do:

add_subdirectory( ${source_dir} ${binary_dir} )

, where "source_dir" would be the source directory relative to ${CMAKE_SOURCE_DIR}, and "binary_dir" could be any absolute path of your choice. You could for instance set it to:

set( binary_dir "${CMAKE_BINARY_DIR}/${source_dir}/build" )

Although all in all, this directory organisation of yours seems pretty "forced". :-/

Cheers,
              Attila

P.S. When calling add_subdirectory like this, ${CMAKE_CURRENT_BINARY_DIR} is definitely set correctly in the subdirectory. But ${CMAKE_BINARY_DIR} will still be the one that CMake sets automatically. You should really not be trying to modify this latter value.

> On 22 Feb 2016, at 05:45, Gerry Fan <gerry.fan at gmail.com> wrote:
> 
> before calling add_subdirectory, set up 2 variables like:
>   set(CMAKE_SOURCE_DIR /Users/test/proj/fplbase)
>   set(CMAKE_BINARY_DIR  /Users/test/proj/fplbase/build)
>   add_subdirectory(${sdl_dir} “/Users/test/proj/fplbase/obj”)
>   
> In module ${dl_dir}’s CMakeLists.txt, at the beginning, it has:
> if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
>   message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL source code and call cmake from there”)
> endif()
> 
> Somehow the above error is always triggered, does not matter what I set CMAKE_BINARY_DIR to. when printing out CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR, CMAKE_BINARY_DIR is set to the same path as CMAKE_SOURCE_DIR ( /Users/test/proj/fplbase ) in module ${dl_dir}
> 
> this only  happens with CMake 3.5-RCx, not happening with previous make versions ( 3.4, 3.3 ). 
> 
> seems this checkin began to have it:
> commit c4e1bc6ed24d57ef3136756802aa575642927ff1
> Merge: f9cc671 0aef6f2
>     Merge branch ‘release
> 
> 
> Is this a bug?
> 
> 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



More information about the CMake mailing list