From fd74f90072f48a914df98ed46d0731c661149187 Mon Sep 17 00:00:00 2001 From: Jonathan Peyton Date: Thu, 4 Feb 2016 19:29:35 +0000 Subject: [PATCH] Add LIBOMP_ENABLE_SHARED option for CMake When building executables for Cray supercomputers, statically-linked executables are preferred. This patch makes it possible to build the OpenMP runtime as an archive for building statically-linked executables. The patch adds the flag LIBOMP_ENABLE_SHARED, which defaults to true. When true, a build of the OpenMP runtime yields dynamic libraries. When false, a build of the OpenMP runtime yields static libraries. There is no setting that allows both kinds of libraries to be built. Patch by John Mellor-Crummey Differential Revision: http://reviews.llvm.org/D16525 llvm-svn: 259817 --- openmp/runtime/Build_With_CMake.txt | 5 +++++ openmp/runtime/CMakeLists.txt | 24 ++++++++++++++++++++++-- openmp/runtime/src/CMakeLists.txt | 18 +++++++++++------- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/openmp/runtime/Build_With_CMake.txt b/openmp/runtime/Build_With_CMake.txt index 9c45430..3258624 100644 --- a/openmp/runtime/Build_With_CMake.txt +++ b/openmp/runtime/Build_With_CMake.txt @@ -143,6 +143,11 @@ symbols are supported (Linux, some BSD* variants). It is off by default for Windows and Mac, but on for other Unix based operating systems. +-DLIBOMP_ENABLE_SHARED=on|off +Shared library instead of static library? (Note: static libraries are not +supported on Windows). If LIBOMP_ENABLE_SHARED is off, then static OpenMP +libraries will be built instead of dynamic ones. + -DLIBOMP_OMPT_SUPPORT=off|on Should OMPT support be included in the build? (Not supported on Windows) If LIBOMP_OMPT_SUPPORT is off, then both ompt_blame and ompt_trace are ignored. diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt index 9380ab5..c4875f4 100644 --- a/openmp/runtime/CMakeLists.txt +++ b/openmp/runtime/CMakeLists.txt @@ -277,6 +277,14 @@ if(LIBOMP_STATS) set(LIBOMP_USE_STDCPPLIB TRUE) endif() +# Shared library can be switched to a static library +set(LIBOMP_ENABLE_SHARED TRUE CACHE BOOL + "Shared library instead of static library?") + +if(WIN32 AND NOT LIBOMP_ENABLE_SHARED) + libomp_error_say("Static libraries requested but not available on Windows") +endif() + # OMPT-support set(LIBOMP_OMPT_DEBUG FALSE CACHE BOOL "Trace OMPT initialization?") @@ -304,7 +312,18 @@ if(${STUBS_LIBRARY}) set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}stubs) endif() set(LIBOMP_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME} CACHE STRING "Base OMP library name") -set(LIBOMP_LIB_FILE ${LIBOMP_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}) + +if(${LIBOMP_ENABLE_SHARED}) + set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) + set(LIBOMP_LIBRARY_KIND SHARED) + set(LIBOMP_INSTALL_KIND LIBRARY) +else() + set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) + set(LIBOMP_LIBRARY_KIND STATIC) + set(LIBOMP_INSTALL_KIND ARCHIVE) +endif() + +set(LIBOMP_LIB_FILE ${LIBOMP_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX}) # Print configuration after all variables are set. if(${LIBOMP_STANDALONE_BUILD}) @@ -315,7 +334,8 @@ if(${LIBOMP_STANDALONE_BUILD}) endif() libomp_say("Build Type -- ${CMAKE_BUILD_TYPE}") libomp_say("OpenMP Version -- ${LIBOMP_OMP_VERSION}") - libomp_say("Lib Type -- ${LIBOMP_LIB_TYPE}") + libomp_say("Library Kind -- ${LIBOMP_LIBRARY_KIND}") + libomp_say("Library Type -- ${LIBOMP_LIB_TYPE}") libomp_say("Fortran Modules -- ${LIBOMP_FORTRAN_MODULES}") # will say development if all zeros if(${LIBOMP_VERSION_BUILD} STREQUAL 00000000) diff --git a/openmp/runtime/src/CMakeLists.txt b/openmp/runtime/src/CMakeLists.txt index 91a8336..a057030 100644 --- a/openmp/runtime/src/CMakeLists.txt +++ b/openmp/runtime/src/CMakeLists.txt @@ -136,7 +136,9 @@ endif() # Add the OpenMP library libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS) -add_library(omp SHARED ${LIBOMP_SOURCE_FILES}) + +add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES}) + set_target_properties(omp PROPERTIES PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}" LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}" @@ -156,9 +158,9 @@ endif() if(NOT WIN32) add_custom_command(TARGET omp POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE} - libgomp${CMAKE_SHARED_LIBRARY_SUFFIX} + libgomp${LIBOMP_LIBRARY_SUFFIX} COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE} - libiomp5${CMAKE_SHARED_LIBRARY_SUFFIX} + libiomp5${LIBOMP_LIBRARY_SUFFIX} WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR} ) endif() @@ -285,17 +287,19 @@ if(WIN32) set(LIBOMP_ALIASES "libiomp5md") foreach(alias IN LISTS LIBOMP_ALIASES) install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\" - \"${alias}${CMAKE_SHARED_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/bin)") + \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/bin)") install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\" - \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") + \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") endforeach() else() - install(TARGETS omp LIBRARY DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) + + install(TARGETS omp ${LIBOMP_INSTALL_KIND} DESTINATION lib${LIBOMP_LIBDIR_SUFFIX}) + # Create aliases (symlinks) of the library for backwards compatibility set(LIBOMP_ALIASES "libgomp;libiomp5") foreach(alias IN LISTS LIBOMP_ALIASES) install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\" - \"${alias}${CMAKE_SHARED_LIBRARY_SUFFIX}\" WORKING_DIRECTORY + \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/lib${LIBOMP_LIBDIR_SUFFIX})") endforeach() endif() -- 2.7.4