Index: openmp/trunk/CMakeLists.txt =================================================================== --- openmp/trunk/CMakeLists.txt +++ openmp/trunk/CMakeLists.txt @@ -1,5 +1,8 @@ cmake_minimum_required(VERSION 2.8 FATAL_ERROR) +# Add cmake directory to search for custom cmake functions. +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH}) + # llvm/runtimes/ will set OPENMP_STANDALONE_BUILD. if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") set(OPENMP_STANDALONE_BUILD TRUE) @@ -10,9 +13,25 @@ set(CMAKE_BUILD_TYPE Release) endif() + # Group common settings. + set(OPENMP_ENABLE_WERROR FALSE CACHE BOOL + "Enable -Werror flags to turn warnings into errors for supporting compilers.") + set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING + "suffix of lib installation directory, e.g. 64 => lib64") + set(OPENMP_LLVM_TOOLS_DIR "" CACHE PATH "Path to LLVM tools for testing.") +else() + set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + # If building in tree, we honor the same install suffix LLVM uses. + set(OPENMP_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX}) endif() +# Check and set up common compiler flags. +include(config-ix) +include(HandleOpenMPOptions) + + +# Build host runtime library. add_subdirectory(runtime) @@ -20,12 +39,19 @@ # 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 (WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +if (APPLE OR WIN32 OR NOT OPENMP_HAVE_STD_CPP11_FLAG) set(ENABLE_LIBOMPTARGET OFF) endif() option(OPENMP_ENABLE_LIBOMPTARGET "Enable building libomptarget for offloading." ${ENABLE_LIBOMPTARGET}) if (OPENMP_ENABLE_LIBOMPTARGET) + # Check that the library can acutally be built. + if (APPLE OR WIN32) + message(FATAL_ERROR "libomptarget cannot be built on Windows and MacOS X!") + elseif (NOT OPENMP_HAVE_STD_CPP11_FLAG) + message(FATAL_ERROR "Host compiler must support C++11 to build libomptarget!") + endif() + add_subdirectory(libomptarget) endif() Index: openmp/trunk/cmake/HandleOpenMPOptions.cmake =================================================================== --- openmp/trunk/cmake/HandleOpenMPOptions.cmake +++ openmp/trunk/cmake/HandleOpenMPOptions.cmake @@ -0,0 +1,16 @@ +if (${OPENMP_STANDALONE_BUILD}) + # From HandleLLVMOptions.cmake + function(append_if condition value) + if (${condition}) + foreach(variable ${ARGN}) + set(${variable} "${${variable}} ${value}" PARENT_SCOPE) + endforeach(variable) + endif() + endfunction() +endif() + +if (${OPENMP_ENABLE_WERROR}) + append_if(OPENMP_HAVE_WERROR_FLAG "-Werror" CMAKE_C_FLAGS CMAKE_CXX_FLAGS) +endif() + +append_if(OPENMP_HAVE_STD_CPP11_FLAG "-std=c++11" CMAKE_CXX_FLAGS) \ No newline at end of file Index: openmp/trunk/cmake/config-ix.cmake =================================================================== --- openmp/trunk/cmake/config-ix.cmake +++ openmp/trunk/cmake/config-ix.cmake @@ -0,0 +1,6 @@ +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) + +check_c_compiler_flag(-Werror OPENMP_HAVE_WERROR_FLAG) + +check_cxx_compiler_flag(-std=c++11 OPENMP_HAVE_STD_CPP11_FLAG) \ No newline at end of file Index: openmp/trunk/libomptarget/Build_With_CMake.txt =================================================================== --- openmp/trunk/libomptarget/Build_With_CMake.txt +++ openmp/trunk/libomptarget/Build_With_CMake.txt @@ -82,7 +82,7 @@ -DCMAKE_BUILD_TYPE=Release|Debug|RelWithDebInfo Build type can be Release, Debug, or RelWithDebInfo. --DLIBOMPTARGET_ENABLE_WERROR=true|false +-DOPENMP_ENABLE_WERROR=true|false Should consider warnings as errors. -DLIBOMPTARGET_LLVM_LIT_EXECUTABLE="" Index: openmp/trunk/libomptarget/CMakeLists.txt =================================================================== --- openmp/trunk/libomptarget/CMakeLists.txt +++ openmp/trunk/libomptarget/CMakeLists.txt @@ -19,22 +19,10 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH}) if(OPENMP_STANDALONE_BUILD) - set(LIBOMPTARGET_ENABLE_WERROR FALSE CACHE BOOL - "Enable -Werror flags to turn warnings into errors for supporting compilers.") - set(LIBOMPTARGET_LIBDIR_SUFFIX "" CACHE STRING - "suffix of lib installation directory, e.g. 64 => lib64") - # Build all libraries into a common place so that tests can find them. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -else() - set(LIBOMPTARGET_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) - # If building in tree, we honor the same install suffix LLVM uses. - set(LIBOMPTARGET_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX}) endif() -# Compiler flag checks. -include(config-ix) - # Message utilities. include(LibomptargetUtils) @@ -56,55 +44,41 @@ set(LIBOMPTARGET_BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(LIBOMPTARGET_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) -# We need C++11 support. -if(LIBOMPTARGET_HAVE_STD_CPP11_FLAG) - - libomptarget_say("Building offloading runtime library libomptarget.") - - # Enable support for C++11. - add_definitions(-std=c++11) - - if(LIBOMPTARGET_ENABLE_WERROR AND LIBOMPTARGET_HAVE_WERROR_FLAG) - add_definitions(-Werror) - endif() - - # If building this library in debug mode, we define a macro to enable - # dumping progress messages at runtime. - string( TOLOWER "${CMAKE_BUILD_TYPE}" LIBOMPTARGET_CMAKE_BUILD_TYPE) - if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug) - add_definitions(-DOMPTARGET_DEBUG) - add_definitions(-g) - add_definitions(-O0) - endif() - - set(src_files - src/omptarget.cpp - ) - - include_directories(src/) - - # Build libomptarget library with libdl dependency. - add_library(omptarget SHARED ${src_files}) - target_link_libraries(omptarget - ${CMAKE_DL_LIBS} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") - - # Install libomptarget under the lib destination folder. - install(TARGETS omptarget LIBRARY DESTINATION lib${LIBOMPTARGET_LIBDIR_SUFFIX}) - - # Retrieve the path to the resulting library so that it can be used for - # testing. - get_target_property(LIBOMPTARGET_LIBRARY_DIR omptarget LIBRARY_OUTPUT_DIRECTORY) - if(NOT LIBOMPTARGET_LIBRARY_DIR) - set(LIBOMPTARGET_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) - endif() - - # Build offloading plugins and device RTLs if they are available. - add_subdirectory(plugins) - - # Add tests. - add_subdirectory(test) - -else(LIBOMPTARGET_HAVE_STD_CPP11_FLAG) - libomptarget_say("Not building offloading runtime library libomptarget: host compiler must have c++11 support.") -endif(LIBOMPTARGET_HAVE_STD_CPP11_FLAG) +libomptarget_say("Building offloading runtime library libomptarget.") + +# If building this library in debug mode, we define a macro to enable +# dumping progress messages at runtime. +string( TOLOWER "${CMAKE_BUILD_TYPE}" LIBOMPTARGET_CMAKE_BUILD_TYPE) +if(LIBOMPTARGET_CMAKE_BUILD_TYPE MATCHES debug) + add_definitions(-DOMPTARGET_DEBUG) + add_definitions(-g) + add_definitions(-O0) +endif() + +set(src_files + src/omptarget.cpp +) + +include_directories(src/) + +# Build libomptarget library with libdl dependency. +add_library(omptarget SHARED ${src_files}) +target_link_libraries(omptarget + ${CMAKE_DL_LIBS} + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") + +# Install libomptarget under the lib destination folder. +install(TARGETS omptarget LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) + +# Retrieve the path to the resulting library so that it can be used for +# testing. +get_target_property(LIBOMPTARGET_LIBRARY_DIR omptarget LIBRARY_OUTPUT_DIRECTORY) +if(NOT LIBOMPTARGET_LIBRARY_DIR) + set(LIBOMPTARGET_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) +endif() + +# Build offloading plugins and device RTLs if they are available. +add_subdirectory(plugins) + +# Add tests. +add_subdirectory(test) Index: openmp/trunk/libomptarget/cmake/Modules/config-ix.cmake =================================================================== --- openmp/trunk/libomptarget/cmake/Modules/config-ix.cmake +++ openmp/trunk/libomptarget/cmake/Modules/config-ix.cmake @@ -1,17 +0,0 @@ -# -#//===----------------------------------------------------------------------===// -#// -#// The LLVM Compiler Infrastructure -#// -#// This file is dual licensed under the MIT and the University of Illinois Open -#// Source Licenses. See LICENSE.txt for details. -#// -#//===----------------------------------------------------------------------===// -# - -include(CheckCCompilerFlag) -include(CheckCXXCompilerFlag) - -# Checking C, CXX -check_cxx_compiler_flag(-std=c++11 LIBOMPTARGET_HAVE_STD_CPP11_FLAG) -check_c_compiler_flag(-Werror LIBOMPTARGET_HAVE_WERROR_FLAG) Index: openmp/trunk/libomptarget/plugins/CMakeLists.txt =================================================================== --- openmp/trunk/libomptarget/plugins/CMakeLists.txt +++ openmp/trunk/libomptarget/plugins/CMakeLists.txt @@ -37,7 +37,7 @@ # Install plugin under the lib destination folder. install(TARGETS "omptarget.rtl.${tmachine_libname}" - LIBRARY DESTINATION lib${LIBOMPTARGET_LIBDIR_SUFFIX}) + LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) target_link_libraries( "omptarget.rtl.${tmachine_libname}" Index: openmp/trunk/libomptarget/plugins/cuda/CMakeLists.txt =================================================================== --- openmp/trunk/libomptarget/plugins/cuda/CMakeLists.txt +++ openmp/trunk/libomptarget/plugins/cuda/CMakeLists.txt @@ -29,7 +29,7 @@ add_library(omptarget.rtl.cuda SHARED src/rtl.cpp) # Install plugin under the lib destination folder. - install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION lib${LIBOMPTARGET_LIBDIR_SUFFIX}) + install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) target_link_libraries(omptarget.rtl.cuda ${LIBOMPTARGET_DEP_CUDA_LIBRARIES} Index: openmp/trunk/runtime/CMakeLists.txt =================================================================== --- openmp/trunk/runtime/CMakeLists.txt +++ openmp/trunk/runtime/CMakeLists.txt @@ -32,14 +32,9 @@ libomp_get_architecture(LIBOMP_DETECTED_ARCH) set(LIBOMP_ARCH ${LIBOMP_DETECTED_ARCH} CACHE STRING "The architecture to build for (x86_64/i386/arm/ppc64/ppc64le/aarch64/mic/mips/mips64).") - # Allow user to choose a suffix for the installation directory. - set(LIBOMP_LIBDIR_SUFFIX "" CACHE STRING - "suffix of lib installation directory e.g., 64 => lib64") # Should assertions be enabled? They are on by default. set(LIBOMP_ENABLE_ASSERTIONS TRUE CACHE BOOL "enable assertions?") - set(LIBOMP_ENABLE_WERROR FALSE CACHE BOOL - "Enable -Werror flags to turn warnings into errors for supporting compilers.") else() # Part of LLVM build # Determine the native architecture from LLVM. string(TOLOWER "${LLVM_TARGET_ARCH}" LIBOMP_NATIVE_ARCH) @@ -68,9 +63,7 @@ # last ditch effort libomp_get_architecture(LIBOMP_ARCH) endif () - set(LIBOMP_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX}) set(LIBOMP_ENABLE_ASSERTIONS ${LLVM_ENABLE_ASSERTIONS}) - set(LIBOMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) endif() libomp_check_variable(LIBOMP_ARCH 32e x86_64 32 i386 arm ppc64 ppc64le aarch64 mic mips mips64) Index: openmp/trunk/runtime/cmake/LibompHandleFlags.cmake =================================================================== --- openmp/trunk/runtime/cmake/LibompHandleFlags.cmake +++ openmp/trunk/runtime/cmake/LibompHandleFlags.cmake @@ -26,12 +26,8 @@ # Gets flags common to both the C and C++ compiler function(libomp_get_c_and_cxxflags_common flags) set(flags_local) - libomp_append(flags_local -std=c++11 LIBOMP_HAVE_STD_CPP11_FLAG) libomp_append(flags_local -fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG) libomp_append(flags_local -fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG) - if(${LIBOMP_ENABLE_WERROR}) - libomp_append(flags_local -Werror LIBOMP_HAVE_WERROR_FLAG) - endif() libomp_append(flags_local -Wno-sign-compare LIBOMP_HAVE_WNO_SIGN_COMPARE_FLAG) libomp_append(flags_local -Wno-unused-function LIBOMP_HAVE_WNO_UNUSED_FUNCTION_FLAG) libomp_append(flags_local -Wno-unused-local-typedef LIBOMP_HAVE_WNO_UNUSED_LOCAL_TYPEDEF_FLAG) Index: openmp/trunk/runtime/cmake/config-ix.cmake =================================================================== --- openmp/trunk/runtime/cmake/config-ix.cmake +++ openmp/trunk/runtime/cmake/config-ix.cmake @@ -47,11 +47,9 @@ endfunction() # Checking C, CXX, Linker Flags -check_cxx_compiler_flag(-std=c++11 LIBOMP_HAVE_STD_CPP11_FLAG) check_cxx_compiler_flag(-fno-exceptions LIBOMP_HAVE_FNO_EXCEPTIONS_FLAG) check_cxx_compiler_flag(-fno-rtti LIBOMP_HAVE_FNO_RTTI_FLAG) check_c_compiler_flag("-x c++" LIBOMP_HAVE_X_CPP_FLAG) -check_c_compiler_flag(-Werror LIBOMP_HAVE_WERROR_FLAG) check_c_compiler_flag(-Wunused-function LIBOMP_HAVE_WNO_UNUSED_FUNCTION_FLAG) check_c_compiler_flag(-Wunused-local-typedef LIBOMP_HAVE_WNO_UNUSED_LOCAL_TYPEDEF_FLAG) check_c_compiler_flag(-Wunused-value LIBOMP_HAVE_WNO_UNUSED_VALUE_FLAG) Index: openmp/trunk/runtime/src/CMakeLists.txt =================================================================== --- openmp/trunk/runtime/src/CMakeLists.txt +++ openmp/trunk/runtime/src/CMakeLists.txt @@ -286,22 +286,22 @@ set(LIBOMP_HEADERS_INSTALL_PATH include) else() string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION ${PACKAGE_VERSION}) - set(LIBOMP_HEADERS_INSTALL_PATH lib${LIBOMP_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + set(LIBOMP_HEADERS_INSTALL_PATH lib${OPENMP_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) endif() if(WIN32) install(TARGETS omp RUNTIME DESTINATION bin) - install(TARGETS ompimp ARCHIVE DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) + install(TARGETS ompimp ARCHIVE DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) # Create aliases (regular copies) of the library for backwards compatibility set(LIBOMP_ALIASES "libiomp5md") foreach(alias IN LISTS LIBOMP_ALIASES) install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\" \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/bin)") install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\" - \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") + \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib${OPENMP_LIBDIR_SUFFIX})") endforeach() else() - install(TARGETS omp ${LIBOMP_INSTALL_KIND} DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) + install(TARGETS omp ${LIBOMP_INSTALL_KIND} DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) if(${LIBOMP_INSTALL_ALIASES}) # Create aliases (symlinks) of the library for backwards compatibility @@ -309,7 +309,7 @@ foreach(alias IN LISTS LIBOMP_ALIASES) install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\" \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY - \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") + \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/lib${OPENMP_LIBDIR_SUFFIX})") endforeach() endif() endif()