Skip to content

Commit

Permalink
Add LIBOMP_ENABLE_SHARED option for CMake
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jpeyton52 committed Feb 4, 2016
1 parent 7823fd2 commit fd74f90
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
5 changes: 5 additions & 0 deletions openmp/runtime/Build_With_CMake.txt
Expand Up @@ -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.
Expand Down
24 changes: 22 additions & 2 deletions openmp/runtime/CMakeLists.txt
Expand Up @@ -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?")
Expand Down Expand Up @@ -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})
Expand All @@ -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)
Expand Down
18 changes: 11 additions & 7 deletions openmp/runtime/src/CMakeLists.txt
Expand Up @@ -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}"
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit fd74f90

Please sign in to comment.