diff --git a/openmp/CMakeLists.txt b/openmp/CMakeLists.txt --- a/openmp/CMakeLists.txt +++ b/openmp/CMakeLists.txt @@ -59,19 +59,11 @@ # Currently libomptarget cannot be compiled on Windows or MacOS X. # Since the device plugins are only supported on Linux anyway, # there is no point in trying to compile libomptarget on other OSes. -if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP14_FLAG) +if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP14_FLAG OR + OPENMP_STANDALONE_BUILD) 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) @@ -93,6 +85,8 @@ message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!") elseif (NOT OPENMP_HAVE_STD_CPP14_FLAG) message(FATAL_ERROR "Host compiler must support C++14 to build libomptarget!") + elseif (OPENMP_STANDALONE_BUILD) + message(FATAL_ERROR "libomptarget cannot be built out of LLVM tree!") endif() add_subdirectory(libomptarget) diff --git a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake --- a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake +++ b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake @@ -250,27 +250,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}) diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt --- a/openmp/libomptarget/src/CMakeLists.txt +++ b/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.