Skip to content

Surprising behavior with FetchContent #711

Open
@samuelpmish

Description

@samuelpmish

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

blt/SetupBLT.cmake

Lines 158 to 162 in 5468efd

# Set the path where all the installed executables will go
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY
${PROJECT_BINARY_DIR}/bin
CACHE PATH
"Directory where executables will go in the build tree")


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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions