diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -381,6 +381,15 @@ return std::string(driverPath); } +// Generate the path to look for OpenMP headers +static std::string getOpenMPHeadersDir() { + llvm::SmallString<128> includePath; + includePath.assign(llvm::sys::fs::getMainExecutable(nullptr, nullptr)); + llvm::sys::path::remove_filename(includePath); + includePath.append("/../include/flang/OpenMP/"); + return std::string(includePath); +} + /// Parses all preprocessor input arguments and populates the preprocessor /// options accordingly. /// @@ -677,6 +686,10 @@ preprocessorOptions.searchDirectoriesFromDashI.begin(), preprocessorOptions.searchDirectoriesFromDashI.end()); + // Add the location of omp_lib.h to the search directories. Currently this is + // identical to the modules' directory. + fortranOptions.searchDirectories.emplace_back(getOpenMPHeadersDir()); + // Add the ordered list of -intrinsic-modules-path fortranOptions.searchDirectories.insert( fortranOptions.searchDirectories.end(), diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -57,3 +57,6 @@ add_custom_target(flang ALL DEPENDS ${CMAKE_BINARY_DIR}/bin/flang) install(PROGRAMS ${CMAKE_BINARY_DIR}/bin/flang DESTINATION "${CMAKE_INSTALL_BINDIR}") endif() + +# TODO Move this to a more suitable location +file(COPY ${FLANG_SOURCE_DIR}/module/omp_lib.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/flang/OpenMP/" FILE_PERMISSIONS OWNER_READ OWNER_WRITE)