blt icon indicating copy to clipboard operation
blt copied to clipboard

Surprising behavior with FetchContent

Open samuelpmish opened this issue 1 year ago • 0 comments

If I have a simple CMake project

cmake_minimum_required(VERSION 3.18)
project(example_project LANGUAGES CXX)
add_executable(main main.cpp)

it defaults to putting the executables in the build directory.

% cd build && make
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable main

When I tried adding RAJA as a dependency with FetchContent

cmake_minimum_required(VERSION 3.18)
project(example_project LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(
  raja
  URL            https://github.com/LLNL/RAJA/releases/download/v2024.07.0/RAJA-v2024.07.0.tar.gz
)
set(RAJA_ENABLE_TESTS OFF CACHE INTERNAL "")
set(RAJA_ENABLE_EXAMPLES OFF CACHE INTERNAL "")
set(RAJA_ENABLE_EXERCISES OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(raja)

add_executable(main main.cpp)

RAJA built just fine, but I couldn't find my executables any more. When I looked more closely, I saw that they were being put in RAJA's output directory, which surprised me.

% cd build && make
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable  _deps/raja-build/bin/main

I haven't looked into it too closely, but it seems like the cause is not RAJA after all, but BLT unconditionally setting the value of CMAKE_RUNTIME_OUTPUT_DIRECTORY here

https://github.com/LLNL/blt/blob/5468efd7d8c00e6ce4a18af187f66e6669ff1aae/SetupBLT.cmake#L158-L162


As a user, my expectation is that bringing in a child project through FetchContent shouldn't result in changing the global settings of the parent project.

samuelpmish avatar Dec 05 '24 15:12 samuelpmish