diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b56d75b0e..8639308cc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,6 +66,12 @@ set(SRC add_library(${PROJECT_NAME} ${SRC}) set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/) +# We need the module directory before we finish the configure stage since the +# build interface might resolve before the module directory is generated by CMake +if(NOT EXISTS "${LIB_MOD_DIR}") + make_directory("${LIB_MOD_DIR}") +endif() + set_target_properties(${PROJECT_NAME} PROPERTIES Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) target_include_directories(${PROJECT_NAME} PUBLIC