517 lines · plain
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-exception7#//8#//===----------------------------------------------------------------------===//9#10 11include(ExtendPath)12 13# The generated headers will be placed in clang's resource if using it to14# compile openmp in a runtimes-bootstrapping build.15if(LLVM_TREE_AVAILABLE AND LLVM_RUNTIMES_BUILD)16 set(LIBOMP_HEADERS_INTDIR ${LLVM_BINARY_DIR}/${LIBOMP_HEADERS_INSTALL_PATH})17else()18 set(LIBOMP_HEADERS_INTDIR ${CMAKE_CURRENT_BINARY_DIR})19endif()20 21# Configure omp.h, kmp_config.h and omp-tools.h if necessary22configure_file(${LIBOMP_INC_DIR}/omp.h.var ${LIBOMP_HEADERS_INTDIR}/omp.h @ONLY)23configure_file(${LIBOMP_INC_DIR}/ompx.h.var ${LIBOMP_HEADERS_INTDIR}/ompx.h @ONLY)24configure_file(kmp_config.h.cmake kmp_config.h @ONLY)25if(${LIBOMP_OMPT_SUPPORT})26 configure_file(${LIBOMP_INC_DIR}/omp-tools.h.var ${LIBOMP_HEADERS_INTDIR}/omp-tools.h @ONLY)27endif()28 29# Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc30set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS "")31if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")32 # Required as Python doesn't inherit CMake's environment setup and uses the host system as the target system by default33 set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} --target-system-override=${CMAKE_SYSTEM_NAME})34endif()35 36add_custom_command(37 OUTPUT kmp_i18n_id.inc38 COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py39 --enum=kmp_i18n_id.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt40 DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py41)42add_custom_command(43 OUTPUT kmp_i18n_default.inc44 COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py45 --default=kmp_i18n_default.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt46 DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py47)48 49# Set the -D definitions for all sources50# UNICODE and _UNICODE are set in LLVM's CMake system. They affect the51# ittnotify code and should only be set when compiling ittnotify_static.cpp52# on Windows (done below).53# TODO: Fix the UNICODE usage in ittnotify code for Windows.54remove_definitions(-DUNICODE -D_UNICODE)55libomp_get_definitions_flags(LIBOMP_CONFIGURED_DEFINITIONS_FLAGS)56add_definitions(${LIBOMP_CONFIGURED_DEFINITIONS_FLAGS})57 58# Set the -I includes for all sources59include_directories(60 ${CMAKE_CURRENT_BINARY_DIR}61 ${LIBOMP_SRC_DIR}62 ${LIBOMP_SRC_DIR}/i18n63 ${LIBOMP_INC_DIR}64 ${LIBOMP_SRC_DIR}/thirdparty/ittnotify65)66 67# Building with time profiling support requires LLVM directory includes.68if(LIBOMP_PROFILING_SUPPORT)69 include_directories(70 ${LLVM_MAIN_INCLUDE_DIR}71 ${LLVM_INCLUDE_DIR}72 )73endif()74 75# Getting correct source files to build library76set(LIBOMP_CXXFILES)77set(LIBOMP_ASMFILES)78set(LIBOMP_GNUASMFILES)79if(STUBS_LIBRARY)80 set(LIBOMP_CXXFILES kmp_stub.cpp)81else()82 # Get C++ files83 set(LIBOMP_CXXFILES84 kmp_alloc.cpp85 kmp_atomic.cpp86 kmp_csupport.cpp87 kmp_debug.cpp88 kmp_itt.cpp89 kmp_environment.cpp90 kmp_error.cpp91 kmp_global.cpp92 kmp_i18n.cpp93 kmp_io.cpp94 kmp_runtime.cpp95 kmp_settings.cpp96 kmp_str.cpp97 kmp_tasking.cpp98 kmp_threadprivate.cpp99 kmp_utility.cpp100 kmp_barrier.cpp101 kmp_wait_release.cpp102 kmp_affinity.cpp103 kmp_dispatch.cpp104 kmp_lock.cpp105 kmp_sched.cpp106 kmp_collapse.cpp107 )108 if(WIN32)109 # Windows specific files110 libomp_append(LIBOMP_CXXFILES z_Windows_NT_util.cpp)111 libomp_append(LIBOMP_CXXFILES z_Windows_NT-586_util.cpp)112 if(${LIBOMP_ARCH} STREQUAL "i386" OR ${LIBOMP_ARCH} STREQUAL "x86_64")113 libomp_append(LIBOMP_ASMFILES z_Windows_NT-586_asm.asm) # Windows assembly file114 elseif((${LIBOMP_ARCH} STREQUAL "aarch64" OR ${LIBOMP_ARCH} STREQUAL "arm") AND (NOT MSVC OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))115 # z_Linux_asm.S works for AArch64 and ARM Windows too.116 libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S)117 else()118 # AArch64 with MSVC gets implementations of the functions from119 # ifdeffed sections in z_Windows_NT-586_util.cpp.120 endif()121 else()122 # Unix specific files123 libomp_append(LIBOMP_CXXFILES z_Linux_util.cpp)124 libomp_append(LIBOMP_CXXFILES kmp_gsupport.cpp)125 if("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")126 libomp_append(LIBOMP_GNUASMFILES z_AIX_asm.S) # AIX assembly file127 else()128 libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S) # Unix assembly file129 endif()130 endif()131 libomp_append(LIBOMP_CXXFILES thirdparty/ittnotify/ittnotify_static.cpp LIBOMP_USE_ITT_NOTIFY)132 libomp_append(LIBOMP_CXXFILES kmp_debugger.cpp LIBOMP_USE_DEBUGGER)133 libomp_append(LIBOMP_CXXFILES kmp_stats.cpp LIBOMP_STATS)134 libomp_append(LIBOMP_CXXFILES kmp_stats_timing.cpp LIBOMP_STATS)135 libomp_append(LIBOMP_CXXFILES kmp_taskdeps.cpp)136 libomp_append(LIBOMP_CXXFILES kmp_cancel.cpp)137endif()138# Files common to stubs and normal library139libomp_append(LIBOMP_CXXFILES kmp_ftn_cdecl.cpp)140libomp_append(LIBOMP_CXXFILES kmp_ftn_extra.cpp)141libomp_append(LIBOMP_CXXFILES kmp_version.cpp)142libomp_append(LIBOMP_CXXFILES ompt-general.cpp IF_TRUE LIBOMP_OMPT_SUPPORT)143libomp_append(LIBOMP_CXXFILES ompd-specific.cpp IF_TRUE LIBOMP_OMPD_SUPPORT)144 145set(LIBOMP_SOURCE_FILES ${LIBOMP_CXXFILES} ${LIBOMP_ASMFILES} ${LIBOMP_GNUASMFILES})146# For Windows, there is a resource file (.rc -> .res) that is also compiled147libomp_append(LIBOMP_SOURCE_FILES libomp.rc WIN32)148 149# Get compiler and assembler flags150libomp_get_cxxflags(LIBOMP_CONFIGURED_CXXFLAGS)151libomp_get_asmflags(LIBOMP_CONFIGURED_ASMFLAGS)152# Set the compiler flags for each type of source153set_source_files_properties(${LIBOMP_CXXFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CXXFLAGS}")154set_source_files_properties(${LIBOMP_ASMFILES} ${LIBOMP_GNUASMFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_ASMFLAGS}")155 156# Remove any cmake-automatic linking of the standard C++ library.157# We neither need (nor want) the standard C++ library dependency even though we compile c++ files.158if(NOT ${LIBOMP_USE_STDCPPLIB})159 set(LIBOMP_LINKER_LANGUAGE C)160 set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)161else()162 set(LIBOMP_LINKER_LANGUAGE CXX)163endif()164 165if(UNIX)166 set(LIBOMP_DL_LIBS ${CMAKE_DL_LIBS})167endif()168 169# Disable libstdc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, to170# avoid an unwanted dependency on libstdc++.so.171add_compile_definitions(_GLIBCXX_NO_ASSERTIONS)172if(NOT WIN32)173 add_definitions(-U_GLIBCXX_ASSERTIONS)174endif()175 176# Add the OpenMP library177libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)178 179libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS)180# Build libomp library. Add LLVMSupport dependency if building in-tree with libomptarget profiling enabled.181if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING))182 add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES})183 set_property(TARGET omp PROPERTY FOLDER "OpenMP/Libraries")184 # Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS185 target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS})186else()187 add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED188 LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}189 LINK_COMPONENTS Support190 BUILDTREE_ONLY191 )192 # libomp must be a C++ library such that it can link libLLVMSupport193 set(LIBOMP_LINKER_LANGUAGE CXX)194endif()195if(${LIBOMP_USE_HWLOC})196 target_include_directories(omp197 PUBLIC198 "$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"199 "$<INSTALL_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"200 )201endif()202 203if(OPENMP_MSVC_NAME_SCHEME)204 if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")205 set(LIBOMP_PDB_NAME ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH})206 set(LIBOMP_LIB_FILE ${LIBOMP_PDB_NAME}${LIBOMP_LIBRARY_SUFFIX})207 else()208 # ${LIBOMP_LIB_NAME} is ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}.${LIBOMP_ARCH}209 set(LIBOMP_PDB_NAME ${LIBOMP_LIB_NAME})210 endif()211 212 # in debug213 # LIBOMP_LIB_FILE should be LIBOMP_LIB_FILE_DBG = ${LIBOMP_LIB_NAME_DBG}${LIBOMP_LIBRARY_SUFFIX}214 # = ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH}${LIBOMP_LIBRARY_SUFFIX}215 # COMPILE_PDB_NAME/PDB_NAME should be LIBOMP_LIB_NAME_DBG = ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH}216 set_target_properties(omp PROPERTIES217 PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}"218 PDB_NAME "${LIBOMP_PDB_NAME}"219 COMPILE_PDB_NAME "${LIBOMP_PDB_NAME}"220 LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"221 LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}222 )223elseif("${CMAKE_SYSTEM_NAME}" MATCHES "AIX")224 set(LIBOMP_SHARED_OUTPUT_NAME "omp" CACHE STRING "Output name for the shared libomp runtime library.")225 set_target_properties(omp PROPERTIES226 OUTPUT_NAME "${LIBOMP_SHARED_OUTPUT_NAME}"227 LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"228 LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}229 VERSION "1.0"230 SOVERSION "1"231 )232else()233 set_target_properties(omp PROPERTIES234 PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}"235 LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"236 LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}237 )238endif()239 240# Get the library's location within the build tree for the unit tester241if(NOT WIN32)242 get_target_property(LIBOMP_LIBRARY_DIR omp LIBRARY_OUTPUT_DIRECTORY)243else()244 get_target_property(LIBOMP_LIBRARY_DIR omp RUNTIME_OUTPUT_DIRECTORY)245endif()246if(NOT LIBOMP_LIBRARY_DIR)247 set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})248 set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)249else()250 set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)251endif()252set(LIBOMP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})253set(LIBOMP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)254 255# Add symbolic links to libomp256if(NOT WIN32)257 if(AIX)258 # On AIX, libomp.a is the name for both static and shared objects.259 set(LIBOMP_AIX_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})260 add_custom_command(TARGET omp POST_BUILD261 COMMAND ${CMAKE_COMMAND} -E create_symlink262 ${LIBOMP_LIB_NAME}${LIBOMP_AIX_SUFFIX} libgomp${LIBOMP_AIX_SUFFIX}263 COMMAND ${CMAKE_COMMAND} -E create_symlink264 ${LIBOMP_LIB_NAME}${LIBOMP_AIX_SUFFIX} libiomp5${LIBOMP_AIX_SUFFIX}265 WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}266 )267 else()268 add_custom_command(TARGET omp POST_BUILD269 COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE}270 libiomp5${LIBOMP_LIBRARY_SUFFIX}271 COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE}272 libgomp${LIBOMP_LIBRARY_SUFFIX}273 WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}274 )275 if(LIBOMP_ENABLE_SHARED)276 if(APPLE)277 set(VERSIONED_LIBGOMP_NAME libgomp.1${LIBOMP_LIBRARY_SUFFIX})278 else()279 set(VERSIONED_LIBGOMP_NAME libgomp${LIBOMP_LIBRARY_SUFFIX}.1)280 endif()281 add_custom_command(TARGET omp POST_BUILD282 COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE} ${VERSIONED_LIBGOMP_NAME}283 WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}284 )285 endif()286 endif()287endif()288 289# Definitions for testing, for reuse when testing libomptarget-nvptx.290set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING291 "Path to folder containing omp.h")292set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING293 "Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled")294 295# Create *.inc before compiling any sources296# objects depend on : .inc files297add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc)298set_target_properties(libomp-needed-headers PROPERTIES FOLDER "OpenMP/Sourcegenning")299add_dependencies(omp libomp-needed-headers)300 301# Windows specific build rules302if(WIN32)303 configure_file(libomp.rc.var libomp.rc @ONLY)304 # z_Windows_NT-586_asm.asm requires definitions to be sent via command line305 # It only needs the architecture macro and OMPT_SUPPORT=0|1306 libomp_append(LIBOMP_MASM_DEFINITIONS "-D_M_IA32" IF_TRUE IA32)307 libomp_append(LIBOMP_MASM_DEFINITIONS "-D_M_AMD64" IF_TRUE INTEL64)308 libomp_append(LIBOMP_MASM_DEFINITIONS "-DOMPT_SUPPORT" IF_TRUE_1_0 LIBOMP_OMPT_SUPPORT)309 libomp_append(LIBOMP_MASM_DEFINITIONS "-DOMPD_SUPPORT" IF_TRUE_1_0 LIBOMP_OMPD_SUPPORT)310 libomp_list_to_string("${LIBOMP_MASM_DEFINITIONS}" LIBOMP_MASM_DEFINITIONS)311 set_property(SOURCE z_Windows_NT-586_asm.asm APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBOMP_MASM_DEFINITIONS}")312 set_source_files_properties(thirdparty/ittnotify/ittnotify_static.cpp PROPERTIES COMPILE_DEFINITIONS "UNICODE")313 314 # Create Windows import library315 # On debug LIBOMP_IMP_LIB_FILE should be LIBOMP_IMP_LIB_FILE_DBG = ${LIBOMP_DEFAULT_LIB_NAME_DBG}${CMAKE_STATIC_LIBRARY_SUFFIX}316 # ${LIBOMP_DEFAULT_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX}317 # and the ARCHIVE_OUTPUT_NAME of ompdbg should be ${LIBOMP_DEFAULT_LIB_NAME_DBG}${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}318 319 if(OPENMP_MSVC_NAME_SCHEME)320 if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")321 set(LIBOMP_IMP_LIB_FILE ${LIBOMP_DEFAULT_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX})322 set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_DEFAULT_LIB_NAME}d${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})323 else()324 set(LIBOMP_IMP_LIB_FILE ${LIBOMP_DEFAULT_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})325 set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_DEFAULT_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})326 endif()327 else()328 set(LIBOMP_IMP_LIB_FILE ${LIBOMP_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})329 set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_LIB_FILE}${CMAKE_STATIC_LIBRARY_SUFFIX})330 endif()331 set_target_properties(omp PROPERTIES332 VERSION ${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR} # uses /version flag333 IMPORT_PREFIX "" IMPORT_SUFFIX "" # control generated import library name when building omp334 ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME}335 )336 337 set(LIBOMP_IMP_LIB_TARGET omp)338 set(LIBOMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.def)339 add_custom_target(libomp-needed-def-file DEPENDS ${LIBOMP_GENERATED_DEF_FILE})340 set_target_properties(libomp-needed-def-file PROPERTIES FOLDER "OpenMP/Sourcegenning")341 add_dependencies(omp libomp-needed-def-file)342 343 # Create the main def file with ordinals to use for building the runtime dll to maintain backwards compatible exports order344 libomp_get_gdflags(LIBOMP_GDFLAGS)345 libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)346 347 add_custom_command(348 OUTPUT ${LIBOMP_GENERATED_DEF_FILE}349 COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.py ${LIBOMP_GDFLAGS} --name ${LIBOMP_LIB_FILE}350 -o ${LIBOMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports351 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.py352 )353 354 if(MSVC)355 # For toolchains that generated the import library importing by ordinal, re-generate it to import by name356 set(LIBOMP_IMP_LIB_TARGET ompimp)357 # Create the auxiliary def file without ordinals to use for building the import library to import by name358 set(LIBOMPIMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.imp.def)359 add_custom_target(libompimp-needed-def-file DEPENDS ${LIBOMPIMP_GENERATED_DEF_FILE})360 set_target_properties(libompimp-needed-def-file PROPERTIES FOLDER "OpenMP/Resources")361 add_custom_command(362 OUTPUT ${LIBOMPIMP_GENERATED_DEF_FILE}363 COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.py ${LIBOMP_GDFLAGS}364 --name ${LIBOMP_LIB_FILE} --no-ordinals365 -o ${LIBOMPIMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports366 DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.py367 )368 # while this merely generates an import library off a def file, CMAKE still requires it to have a "source" so feed it a dummy one,369 # making it a .txt which CMAKE will filter out from the librarian (a .cpp will make lib.exe punt trying to resolve the .def symbols)370 add_library(${LIBOMP_IMP_LIB_TARGET} STATIC kmp_dummy.txt)371 set_target_properties(${LIBOMP_IMP_LIB_TARGET} PROPERTIES FOLDER "OpenMP/Libraries")372 set_target_properties(${LIBOMP_IMP_LIB_TARGET} PROPERTIES373 PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}" LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}374 STATIC_LIBRARY_OPTIONS "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE}")375 add_dependencies(${LIBOMP_IMP_LIB_TARGET} libompimp-needed-def-file)376 add_dependencies(omp ${LIBOMP_IMP_LIB_TARGET})377 endif()378endif()379 380# Building the Fortran module files381# One compilation step creates both omp_lib.mod and omp_lib_kinds.mod382configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)383configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)384 385set(BUILD_FORTRAN_MODULES False)386if (NOT ${LIBOMP_FORTRAN_MODULES_COMPILER} STREQUAL "")387 # If libomp is built as an LLVM runtime and the flang compiler is available,388 # compile the Fortran module files.389 message(STATUS "configuring openmp to build Fortran module files using ${LIBOMP_FORTRAN_MODULES_COMPILER}")390 set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)391 add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)392 add_custom_command(393 OUTPUT omp_lib.mod omp_lib_kinds.mod394 COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE}395 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}396 ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h397 )398 set(BUILD_FORTRAN_MODULES True)399elseif(${LIBOMP_FORTRAN_MODULES})400 # The following requests explicit building of the Fortran module files401 # Workaround for gfortran to build modules with the402 # omp_sched_monotonic integer parameter403 if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")404 set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")405 endif()406 add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)407 set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")408 libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)409 if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)410 set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)411 else()412 message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")413 endif()414 add_custom_command(415 OUTPUT omp_lib.mod omp_lib_kinds.mod416 COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}417 ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE}418 DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}419 ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h420 )421 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${CMAKE_C_OUTPUT_EXTENSION})422 set(BUILD_FORTRAN_MODULES True)423endif()424 425# Move files to exports/ directory if requested426if(${LIBOMP_COPY_EXPORTS})427 include(LibompExports)428endif()429 430# Micro test rules for after library has been built (cmake/LibompMicroTests.cmake)431include(LibompMicroTests)432add_custom_target(libomp-micro-tests)433set_target_properties(libomp-micro-tests PROPERTIES FOLDER "OpenMP/Tests")434if(NOT ${MIC} AND NOT CMAKE_CROSSCOMPILING)435 add_dependencies(libomp-micro-tests libomp-test-touch)436endif()437if(NOT WIN32 AND NOT APPLE)438 add_dependencies(libomp-micro-tests libomp-test-relo)439endif()440if(NOT WIN32 AND NOT APPLE)441 add_dependencies(libomp-micro-tests libomp-test-execstack)442endif()443add_dependencies(libomp-micro-tests libomp-test-deps)444 445# `omp` needs to be exported if in-tree build.446set(export_to_llvmexports)447if (NOT OPENMP_STANDALONE_BUILD)448 get_target_export_arg(omp LLVM export_to_llvmexports)449 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS omp)450endif()451 452# Install rules453# We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR}454# We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}455if(WIN32)456 install(TARGETS omp ${export_to_llvmexports} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")457 install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")458 # Create aliases (regular copies) of the library for backwards compatibility459 set(LIBOMP_ALIASES "libiomp5md")460 foreach(alias IN LISTS LIBOMP_ALIASES)461 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\"462 \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${CMAKE_INSTALL_FULL_BINDIR}\")")463 extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")464 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\"465 \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${outdir}\")")466 endforeach()467else()468 469 install(TARGETS omp ${export_to_llvmexports} ${LIBOMP_INSTALL_KIND} DESTINATION "${OPENMP_INSTALL_LIBDIR}")470 471 if(${LIBOMP_INSTALL_ALIASES})472 # Create aliases (symlinks) of the library for backwards compatibility473 extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")474 if(AIX)475 # On AIX, libomp.a is the name for both static and shared objects.476 set(LIBRARY_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX})477 else()478 set(LIBRARY_SUFFIX ${LIBOMP_LIBRARY_SUFFIX})479 endif()480 set(LIBOMP_ALIASES "libgomp;libiomp5")481 foreach(alias IN LISTS LIBOMP_ALIASES)482 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_NAME}${LIBRARY_SUFFIX}\"483 \"${alias}${LIBRARY_SUFFIX}\" WORKING_DIRECTORY484 \"\$ENV{DESTDIR}${outdir}\")")485 endforeach()486 if(LIBOMP_ENABLE_SHARED AND NOT AIX)487 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"488 \"${VERSIONED_LIBGOMP_NAME}\" WORKING_DIRECTORY489 \"\$ENV{DESTDIR}${outdir}\")")490 endif()491 endif()492endif()493install(494 FILES495 ${LIBOMP_HEADERS_INTDIR}/omp.h496 ${LIBOMP_HEADERS_INTDIR}/ompx.h497 DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}498)499if(${LIBOMP_OMPT_SUPPORT})500 install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH})501 # install under legacy name ompt.h502 install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)503 set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)504endif()505if(${BUILD_FORTRAN_MODULES})506 set (destination ${LIBOMP_HEADERS_INSTALL_PATH})507 if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")508 set (destination ${LIBOMP_MODULES_INSTALL_PATH})509 endif()510 install(FILES511 ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h512 ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod513 ${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod514 DESTINATION ${destination}515 )516endif()517