Index: openmp/CMakeLists.txt =================================================================== --- openmp/CMakeLists.txt +++ openmp/CMakeLists.txt @@ -39,8 +39,6 @@ set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe) set(OPENMP_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe) endif() - - list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include) endif() # Check and set up common compiler flags. @@ -63,20 +61,6 @@ set(ENABLE_LIBOMPTARGET OFF) endif() -# Attempt to locate LLVM source, required by libomptarget -if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS) - if (LLVM_MAIN_INCLUDE_DIR) - list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_MAIN_INCLUDE_DIR}) - elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include) - list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../llvm/include) - endif() -endif() - -if (NOT LIBOMPTARGET_LLVM_INCLUDE_DIRS) - message(STATUS "Missing definition for LIBOMPTARGET_LLVM_INCLUDE_DIRS, disabling libomptarget") - set(ENABLE_LIBOMPTARGET OFF) -endif() - option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading." ${ENABLE_LIBOMPTARGET}) option(OPENMP_ENABLE_LIBOMPTARGET_PROFILING "Enable time profiling for libomptarget." Index: openmp/README.rst =================================================================== --- openmp/README.rst +++ openmp/README.rst @@ -243,6 +243,15 @@ Options for ``libomptarget`` ---------------------------- +An installed LLVM package is a prerequisite for building ``libomptarget`` +library. So ``libomptarget`` may only be built in two cases: + +- As a project of a regular LLVM build via **LLVM_ENABLE_PROJECTS** or + **LLVM_EXTERNAL_PROJECTS**, or +- as a standalone project build that uses a pre-installed LLVM package. + In this mode one has to make sure that the default CMake + ``find_package(LLVM)`` call `succeeds `_. + **LIBOMPTARGET_OPENMP_HEADER_FOLDER** = ``""`` Path of the folder that contains ``omp.h``. This is required for testing out-of-tree builds. Index: openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake =================================================================== --- openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake +++ openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake @@ -19,6 +19,25 @@ include (FindPackageHandleStandardArgs) +################################################################################ +# Looking for LLVM... +################################################################################ + +if (OPENMP_STANDALONE_BUILD) + # Complete LLVM package is required for building libomptarget + # in an out-of-tree mode. + find_package(LLVM REQUIRED) + message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") + message(STATUS "Using LLVM in: ${LLVM_DIR}") + list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + list(APPEND CMAKE_MODULE_PATH ${LLVM_CMAKE_DIR}) + include(AddLLVM) +else() + list(APPEND LIBOMPTARGET_LLVM_INCLUDE_DIRS + ${LLVM_MAIN_INCLUDE_DIR} ${LLVM_BINARY_DIR}/include + ) +endif() + ################################################################################ # Looking for libelf... ################################################################################ @@ -250,27 +269,4 @@ endif() endif() -if (OPENMP_STANDALONE_BUILD) - # This duplicates code from llvm/cmake/config-ix.cmake - if( WIN32 AND NOT CYGWIN ) - # We consider Cygwin as another Unix - set(PURE_WINDOWS 1) - endif() - - # library checks - if( NOT PURE_WINDOWS ) - check_library_exists(pthread pthread_create "" HAVE_LIBPTHREAD) - endif() - - if(HAVE_LIBPTHREAD) - # We want to find pthreads library and at the moment we do want to - # have it reported as '-l' instead of '-pthread'. - # TODO: switch to -pthread once the rest of the build system can deal with it. - set(CMAKE_THREAD_PREFER_PTHREAD TRUE) - set(THREADS_HAVE_PTHREAD_ARG Off) - find_package(Threads REQUIRED) - set(OPENMP_PTHREAD_LIB ${CMAKE_THREAD_LIBS_INIT}) - endif() -else() - set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB}) -endif() +set(OPENMP_PTHREAD_LIB ${LLVM_PTHREAD_LIB}) Index: openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt =================================================================== --- openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt +++ openmp/libomptarget/deviceRTLs/amdgcn/CMakeLists.txt @@ -10,20 +10,8 @@ # ##===----------------------------------------------------------------------===## -find_package(LLVM QUIET CONFIG - PATHS - $ENV{AOMP} - $ENV{HOME}/rocm/aomp - /opt/rocm/aomp - /usr/lib/rocm/aomp - ${LIBOMPTARGET_NVPTX_CUDA_COMPILER_DIR} - ${LIBOMPTARGET_NVPTX_CUDA_LINKER_DIR} - ${CMAKE_CXX_COMPILER_DIR} - NO_DEFAULT_PATH) - -if (LLVM_DIR) - libomptarget_say("Found LLVM ${LLVM_PACKAGE_VERSION}. Configure: ${LLVM_DIR}/LLVMConfig.cmake") -else() +# An installed LLVM package should have been discovered before. +if (NOT LLVM_DIR) libomptarget_say("Not building AMDGCN device RTL: AOMP not found") return() endif() Index: openmp/libomptarget/src/CMakeLists.txt =================================================================== --- openmp/libomptarget/src/CMakeLists.txt +++ openmp/libomptarget/src/CMakeLists.txt @@ -24,23 +24,19 @@ include_directories(${LIBOMPTARGET_LLVM_INCLUDE_DIRS}) -# Build libomptarget library with libdl dependency. Add LLVMSupport -# dependency if building in-tree with profiling enabled. -if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMPTARGET_PROFILING)) - add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES}) - target_link_libraries(omptarget - ${CMAKE_DL_LIBS} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") -else() - set(LLVM_LINK_COMPONENTS - Support - ) - add_llvm_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES} - LINK_LIBS ${CMAKE_DL_LIBS} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports" - ) +# Build libomptarget library with libdl dependency. +add_library(omptarget SHARED ${LIBOMPTARGET_SRC_FILES}) +if (OPENMP_ENABLE_LIBOMPTARGET_PROFILING) + # Add LLVMSupport dependency if profiling is enabled. + # Linking with LLVM component libraries also requires + # aligning the compile flags. + llvm_update_compile_flags(omptarget) target_compile_definitions(omptarget PUBLIC OMPTARGET_PROFILE_ENABLED) + target_link_libraries(omptarget PRIVATE LLVMSupport) endif() +target_link_libraries(omptarget PRIVATE + ${CMAKE_DL_LIBS} + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") # libomptarget needs to be set separately because add_llvm_library doesn't # conform with location configuration of its parent scope.