Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ 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) @@ -9,9 +12,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) Index: cmake/HandleOpenMPOptions.cmake =================================================================== --- /dev/null +++ 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: cmake/config-ix.cmake =================================================================== --- /dev/null +++ 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: libomptarget/Build_With_CMake.txt =================================================================== --- libomptarget/Build_With_CMake.txt +++ 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: libomptarget/CMakeLists.txt =================================================================== --- libomptarget/CMakeLists.txt +++ libomptarget/CMakeLists.txt @@ -20,26 +20,11 @@ if(OPENMP_STANDALONE_BUILD) project(libomptarget C CXX) -endif() - - -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) @@ -62,17 +47,10 @@ set(LIBOMPTARGET_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) # We need C++11 support. -if(LIBOMPTARGET_HAVE_STD_CPP11_FLAG) +if(OPENMP_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) @@ -95,7 +73,7 @@ "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") # Install libomptarget under the lib destination folder. - install(TARGETS omptarget LIBRARY DESTINATION lib${LIBOMPTARGET_LIBDIR_SUFFIX}) + install(TARGETS omptarget LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) # Retrieve the path to the resulting library so that it can be used for # testing. @@ -110,6 +88,6 @@ # Add tests. add_subdirectory(test) -else(LIBOMPTARGET_HAVE_STD_CPP11_FLAG) +else(OPENMP_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) +endif(OPENMP_HAVE_STD_CPP11_FLAG) Index: libomptarget/cmake/Modules/config-ix.cmake =================================================================== --- libomptarget/cmake/Modules/config-ix.cmake +++ /dev/null @@ -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: libomptarget/plugins/CMakeLists.txt =================================================================== --- libomptarget/plugins/CMakeLists.txt +++ 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: libomptarget/plugins/cuda/CMakeLists.txt =================================================================== --- libomptarget/plugins/cuda/CMakeLists.txt +++ 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: runtime/CMakeLists.txt =================================================================== --- runtime/CMakeLists.txt +++ runtime/CMakeLists.txt @@ -36,14 +36,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) @@ -72,9 +67,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: runtime/cmake/LibompHandleFlags.cmake =================================================================== --- runtime/cmake/LibompHandleFlags.cmake +++ 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: runtime/cmake/config-ix.cmake =================================================================== --- runtime/cmake/config-ix.cmake +++ 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: runtime/src/CMakeLists.txt =================================================================== --- runtime/src/CMakeLists.txt +++ 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()