| 1 |
# |
| 2 |
#//===----------------------------------------------------------------------===// |
| 3 |
#// |
| 4 |
#// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 |
#// See https://llvm.org/LICENSE.txt for license information. |
| 6 |
#// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 |
#// |
| 8 |
#//===----------------------------------------------------------------------===// |
| 9 |
# |
| 10 |
|
| 11 |
# LibompExports.cmake |
| 12 |
# Copy library and header files into the exports/ subdirectory after library build |
| 13 |
|
| 14 |
# Create the suffix for the export directory |
| 15 |
# - Only add to suffix when not a default value |
| 16 |
# - Example suffix: .deb.s1 |
| 17 |
# final export directory: exports/lin_32e.deb.s1/lib |
| 18 |
# - These suffixes imply the build is a Debug, Stats-Gathering version of the library |
| 19 |
set(libomp_suffix) |
| 20 |
libomp_append(libomp_suffix .deb DEBUG_BUILD) |
| 21 |
libomp_append(libomp_suffix .dia RELWITHDEBINFO_BUILD) |
| 22 |
libomp_append(libomp_suffix .min MINSIZEREL_BUILD) |
| 23 |
libomp_append(libomp_suffix .s1 LIBOMP_STATS) |
| 24 |
libomp_append(libomp_suffix .ompt LIBOMP_OMPT_SUPPORT) |
| 25 |
if(${LIBOMP_OMPT_SUPPORT}) |
| 26 |
libomp_append(libomp_suffix .optional LIBOMP_OMPT_OPTIONAL) |
| 27 |
endif() |
| 28 |
string(REPLACE ";" "" libomp_suffix "${libomp_suffix}") |
| 29 |
|
| 30 |
# Set exports locations |
| 31 |
if(WIN32) |
| 32 |
set(LIBOMP_SHORT_OS win) |
| 33 |
elseif(APPLE) |
| 34 |
set(LIBOMP_SHORT_OS mac) |
| 35 |
else() |
| 36 |
set(LIBOMP_SHORT_OS lin) |
| 37 |
endif() |
| 38 |
if(${MIC}) |
| 39 |
set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_MIC_ARCH}") # e.g., lin_knf, lin_knc |
| 40 |
else() |
| 41 |
if(${IA32}) |
| 42 |
set(libomp_platform "${LIBOMP_SHORT_OS}_32") |
| 43 |
elseif(${INTEL64}) |
| 44 |
set(libomp_platform "${LIBOMP_SHORT_OS}_32e") |
| 45 |
else() |
| 46 |
set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_ARCH}") # e.g., lin_arm, lin_ppc64 |
| 47 |
endif() |
| 48 |
endif() |
| 49 |
set(LIBOMP_EXPORTS_DIR "${LIBOMP_BASE_DIR}/exports") |
| 50 |
set(LIBOMP_EXPORTS_PLATFORM_DIR "${LIBOMP_EXPORTS_DIR}/${libomp_platform}${libomp_suffix}") |
| 51 |
set(LIBOMP_EXPORTS_CMN_DIR "${LIBOMP_EXPORTS_DIR}/common${libomp_suffix}/include") |
| 52 |
set(LIBOMP_EXPORTS_INC_DIR "${LIBOMP_EXPORTS_PLATFORM_DIR}/include") |
| 53 |
set(LIBOMP_EXPORTS_MOD_DIR "${LIBOMP_EXPORTS_PLATFORM_DIR}/include_compat") |
| 54 |
set(LIBOMP_EXPORTS_LIB_DIR "${LIBOMP_EXPORTS_DIR}/${libomp_platform}${libomp_suffix}/lib") |
| 55 |
|
| 56 |
# Put headers in exports/ directory post build |
| 57 |
add_custom_command(TARGET omp POST_BUILD |
| 58 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_CMN_DIR} |
| 59 |
COMMAND ${CMAKE_COMMAND} -E copy omp.h ${LIBOMP_EXPORTS_CMN_DIR} |
| 60 |
COMMAND ${CMAKE_COMMAND} -E copy ompx.h ${LIBOMP_EXPORTS_CMN_DIR} |
| 61 |
) |
| 62 |
if(${LIBOMP_OMPT_SUPPORT}) |
| 63 |
add_custom_command(TARGET omp POST_BUILD |
| 64 |
COMMAND ${CMAKE_COMMAND} -E copy omp-tools.h ${LIBOMP_EXPORTS_CMN_DIR} |
| 65 |
) |
| 66 |
endif() |
| 67 |
if(${LIBOMP_FORTRAN_MODULES}) |
| 68 |
# We cannot attach a POST_BUILD command to libomp-mod, so instead attach it |
| 69 |
# to omp and ensure that libomp-mod is built before by adding a dependency |
| 70 |
add_custom_command(TARGET omp POST_BUILD |
| 71 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_MOD_DIR} |
| 72 |
COMMAND ${CMAKE_COMMAND} -E copy omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR} |
| 73 |
COMMAND ${CMAKE_COMMAND} -E copy omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR} |
| 74 |
) |
| 75 |
add_dependencies(omp libomp-mod) |
| 76 |
add_custom_command(TARGET omp POST_BUILD |
| 77 |
COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR} |
| 78 |
) |
| 79 |
endif() |
| 80 |
|
| 81 |
# Copy OpenMP library into exports/ directory post build |
| 82 |
if(WIN32) |
| 83 |
get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY) |
| 84 |
else() |
| 85 |
get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY) |
| 86 |
endif() |
| 87 |
if(NOT LIBOMP_OUTPUT_DIRECTORY) |
| 88 |
set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 89 |
endif() |
| 90 |
add_custom_command(TARGET omp POST_BUILD |
| 91 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_LIB_DIR} |
| 92 |
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:omp> ${LIBOMP_EXPORTS_LIB_DIR} |
| 93 |
) |
| 94 |
|
| 95 |
# Copy Windows import library into exports/ directory post build |
| 96 |
if(WIN32) |
| 97 |
get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY) |
| 98 |
if(NOT LIBOMPIMP_OUTPUT_DIRECTORY) |
| 99 |
set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 100 |
endif() |
| 101 |
add_custom_command(TARGET ${LIBOMP_IMP_LIB_TARGET} POST_BUILD |
| 102 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_LIB_DIR} |
| 103 |
COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMPIMP_OUTPUT_DIRECTORY}/${LIBOMP_IMP_LIB_FILE} ${LIBOMP_EXPORTS_LIB_DIR} |
| 104 |
) |
| 105 |
endif() |