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 19set(libomp_suffix) 20libomp_append(libomp_suffix .deb DEBUG_BUILD) 21libomp_append(libomp_suffix .dia RELWITHDEBINFO_BUILD) 22libomp_append(libomp_suffix .min MINSIZEREL_BUILD) 23libomp_append(libomp_suffix .s1 LIBOMP_STATS) 24libomp_append(libomp_suffix .ompt LIBOMP_OMPT_SUPPORT) 25if(${LIBOMP_OMPT_SUPPORT}) 26 libomp_append(libomp_suffix .optional LIBOMP_OMPT_OPTIONAL) 27endif() 28string(REPLACE ";" "" libomp_suffix "${libomp_suffix}") 29 30# Set exports locations 31if(${MIC}) 32 set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_${LIBOMP_MIC_ARCH}") # e.g., lin_knf, lin_knc 33else() 34 if(${IA32}) 35 set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_32") 36 elseif(${INTEL64}) 37 set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_32e") 38 else() 39 set(libomp_platform "${LIBOMP_PERL_SCRIPT_OS}_${LIBOMP_ARCH}") # e.g., lin_arm, lin_ppc64 40 endif() 41endif() 42set(LIBOMP_EXPORTS_DIR "${LIBOMP_BASE_DIR}/exports") 43set(LIBOMP_EXPORTS_PLATFORM_DIR "${LIBOMP_EXPORTS_DIR}/${libomp_platform}${libomp_suffix}") 44set(LIBOMP_EXPORTS_CMN_DIR "${LIBOMP_EXPORTS_DIR}/common${libomp_suffix}/include") 45set(LIBOMP_EXPORTS_INC_DIR "${LIBOMP_EXPORTS_PLATFORM_DIR}/include") 46set(LIBOMP_EXPORTS_MOD_DIR "${LIBOMP_EXPORTS_PLATFORM_DIR}/include_compat") 47set(LIBOMP_EXPORTS_LIB_DIR "${LIBOMP_EXPORTS_DIR}/${libomp_platform}${libomp_suffix}/lib") 48 49# Put headers in exports/ directory post build 50add_custom_command(TARGET omp POST_BUILD 51 COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_CMN_DIR} 52 COMMAND ${CMAKE_COMMAND} -E copy omp.h ${LIBOMP_EXPORTS_CMN_DIR} 53) 54if(${LIBOMP_OMPT_SUPPORT}) 55 add_custom_command(TARGET omp POST_BUILD 56 COMMAND ${CMAKE_COMMAND} -E copy omp-tools.h ${LIBOMP_EXPORTS_CMN_DIR} 57 ) 58endif() 59if(${LIBOMP_FORTRAN_MODULES}) 60 add_custom_command(TARGET libomp-mod POST_BUILD 61 COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_MOD_DIR} 62 COMMAND ${CMAKE_COMMAND} -E copy omp_lib.mod ${LIBOMP_EXPORTS_MOD_DIR} 63 COMMAND ${CMAKE_COMMAND} -E copy omp_lib_kinds.mod ${LIBOMP_EXPORTS_MOD_DIR} 64 ) 65 add_custom_command(TARGET omp POST_BUILD 66 COMMAND ${CMAKE_COMMAND} -E copy omp_lib.h ${LIBOMP_EXPORTS_CMN_DIR} 67 ) 68endif() 69 70# Copy OpenMP library into exports/ directory post build 71if(WIN32) 72 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp RUNTIME_OUTPUT_DIRECTORY) 73else() 74 get_target_property(LIBOMP_OUTPUT_DIRECTORY omp LIBRARY_OUTPUT_DIRECTORY) 75endif() 76if(NOT LIBOMP_OUTPUT_DIRECTORY) 77 set(LIBOMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 78endif() 79add_custom_command(TARGET omp POST_BUILD 80 COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_LIB_DIR} 81 COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:omp> ${LIBOMP_EXPORTS_LIB_DIR} 82) 83 84# Copy Windows import library into exports/ directory post build 85if(WIN32) 86 get_target_property(LIBOMPIMP_OUTPUT_DIRECTORY ${LIBOMP_IMP_LIB_TARGET} ARCHIVE_OUTPUT_DIRECTORY) 87 if(NOT LIBOMPIMP_OUTPUT_DIRECTORY) 88 set(LIBOMPIMP_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 89 endif() 90 add_custom_command(TARGET ${LIBOMP_IMP_LIB_TARGET} POST_BUILD 91 COMMAND ${CMAKE_COMMAND} -E make_directory ${LIBOMP_EXPORTS_LIB_DIR} 92 COMMAND ${CMAKE_COMMAND} -E copy ${LIBOMPIMP_OUTPUT_DIRECTORY}/${LIBOMP_IMP_LIB_FILE} ${LIBOMP_EXPORTS_LIB_DIR} 93 ) 94endif() 95