default build location changed with CMake when building HDF5 through fetch content

214 views Asked by At

I have been using CMake's fetch content functionality quite a bit recently to have self-containing build scripts. So far it works quite nicely, consider the following simplified CMakeLists.txt file:

cmake_minimum_required(VERSION 3.16.0)
project(hdf5test LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(
  googletest
  GIT_REPOSITORY https://github.com/google/googletest.git
  GIT_TAG release-1.11.0
)
if(WIN32)
  set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif()
FetchContent_MakeAvailable(googletest)

add_executable(hdf5test main.cpp)

This works nicely, googletest is build within my build/_deps/ directory and the final libraries are installed into build/lib/Debug (assuming a debug build here). No surprise here, and also my executable hdf5test (which is just a hello world file for the moment, i.e. no includes) compiles fine into build/Debug/.

I need to compile HDF5 now as well as one of my dependencies requires it in order to be compiled. So my CNakeLists.txt file would look like this (for simplicity, googletest is removed now):

cmake_minimum_required(VERSION 3.16.0)
project(hdf5test LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(
  hdf5
  GIT_REPOSITORY https://github.com/HDFGroup/hdf5.git
  GIT_TAG hdf5-1_13_1
)
FetchContent_MakeAvailable(hdf5)

add_executable(hdf5test main.cpp)

HDF5 is now built fine as well but messes up the build tree. First of all, the HDF5 libraries are all put into build/_deps/hdf5-build/bin/Debug but are no longer installed into the build/lib/Debug/ folder by default. THe more confusing thing, though, is that my defined executables like hdf5test are put in the same location (build/_deps/hdf5-build/bin/Debug) and this is messing with my build setup. As far as I can see, only HDF5 is changing this behaviour, googletest (and other tested libraries) do not change this.

Does anyone know how to force hdf5 to not change the default build directory and to install the libraries into build/lib/Debug once the build is completed (using fetch content, I can manage to get it installed correctly using the command line only with -DCMAKE_INSTALL_PREFIX) so that my executables are still put into build/Debug?

Note: After HDF5 is built, the CMakeCache.txt file now contains CMAKE_RUNTIME_OUTPUT_DIRECTORY:PATH=path/to/project/build/_deps/hdf5-build/bin

0

There are 0 answers