Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / runtime / src / CMakeLists.txt
blob8b2445ac58bf0ca97996f6be0530e76c141a080b
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 #//===----------------------------------------------------------------------===//
11 include(ExtendPath)
13 # Configure omp.h, kmp_config.h and omp-tools.h if necessary
14 configure_file(${LIBOMP_INC_DIR}/omp.h.var omp.h @ONLY)
15 configure_file(${LIBOMP_INC_DIR}/ompx.h.var ompx.h @ONLY)
16 configure_file(kmp_config.h.cmake kmp_config.h @ONLY)
17 if(${LIBOMP_OMPT_SUPPORT})
18   configure_file(${LIBOMP_INC_DIR}/omp-tools.h.var omp-tools.h @ONLY)
19 endif()
21 # Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc
22 add_custom_command(
23   OUTPUT  kmp_i18n_id.inc
24   COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.pl --os=${LIBOMP_PERL_SCRIPT_OS}
25     --prefix=kmp_i18n --enum=kmp_i18n_id.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
26   DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.pl
28 add_custom_command(
29   OUTPUT  kmp_i18n_default.inc
30   COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.pl --os=${LIBOMP_PERL_SCRIPT_OS}
31     --prefix=kmp_i18n --default=kmp_i18n_default.inc ${LIBOMP_SRC_DIR}/i18n/en_US.txt
32   DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.pl
35 # Set the -D definitions for all sources
36 # UNICODE and _UNICODE are set in LLVM's CMake system.  They affect the
37 # ittnotify code and should only be set when compiling ittnotify_static.cpp
38 # on Windows (done below).
39 # TODO: Fix the UNICODE usage in ittnotify code for Windows.
40 remove_definitions(-DUNICODE -D_UNICODE)
41 libomp_get_definitions_flags(LIBOMP_CONFIGURED_DEFINITIONS_FLAGS)
42 add_definitions(${LIBOMP_CONFIGURED_DEFINITIONS_FLAGS})
44 # Set the -I includes for all sources
45 include_directories(
46   ${CMAKE_CURRENT_BINARY_DIR}
47   ${LIBOMP_SRC_DIR}
48   ${LIBOMP_SRC_DIR}/i18n
49   ${LIBOMP_INC_DIR}
50   ${LIBOMP_SRC_DIR}/thirdparty/ittnotify
53 # Building with time profiling support requires LLVM directory includes.
54 if(LIBOMP_PROFILING_SUPPORT)
55   include_directories(
56     ${LLVM_MAIN_INCLUDE_DIR}
57     ${LLVM_INCLUDE_DIR}
58   )
59 endif()
61 # Getting correct source files to build library
62 set(LIBOMP_CXXFILES)
63 set(LIBOMP_ASMFILES)
64 set(LIBOMP_GNUASMFILES)
65 if(STUBS_LIBRARY)
66   set(LIBOMP_CXXFILES kmp_stub.cpp)
67 else()
68   # Get C++ files
69   set(LIBOMP_CXXFILES
70     kmp_alloc.cpp
71     kmp_atomic.cpp
72     kmp_csupport.cpp
73     kmp_debug.cpp
74     kmp_itt.cpp
75     kmp_environment.cpp
76     kmp_error.cpp
77     kmp_global.cpp
78     kmp_i18n.cpp
79     kmp_io.cpp
80     kmp_runtime.cpp
81     kmp_settings.cpp
82     kmp_str.cpp
83     kmp_tasking.cpp
84     kmp_threadprivate.cpp
85     kmp_utility.cpp
86     kmp_barrier.cpp
87     kmp_wait_release.cpp
88     kmp_affinity.cpp
89     kmp_dispatch.cpp
90     kmp_lock.cpp
91     kmp_sched.cpp
92     kmp_collapse.cpp
93   )
94   if(WIN32)
95     # Windows specific files
96     libomp_append(LIBOMP_CXXFILES z_Windows_NT_util.cpp)
97     libomp_append(LIBOMP_CXXFILES z_Windows_NT-586_util.cpp)
98     if(${LIBOMP_ARCH} STREQUAL "i386" OR ${LIBOMP_ARCH} STREQUAL "x86_64")
99       libomp_append(LIBOMP_ASMFILES z_Windows_NT-586_asm.asm) # Windows assembly file
100     elseif((${LIBOMP_ARCH} STREQUAL "aarch64" OR ${LIBOMP_ARCH} STREQUAL "arm") AND (NOT MSVC OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))
101       # z_Linux_asm.S works for AArch64 and ARM Windows too.
102       libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S)
103     else()
104       # AArch64 with MSVC gets implementations of the functions from
105       # ifdeffed sections in z_Windows_NT-586_util.cpp.
106     endif()
107   else()
108     # Unix specific files
109     libomp_append(LIBOMP_CXXFILES z_Linux_util.cpp)
110     libomp_append(LIBOMP_CXXFILES kmp_gsupport.cpp)
111     libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S) # Unix assembly file
112   endif()
113   libomp_append(LIBOMP_CXXFILES thirdparty/ittnotify/ittnotify_static.cpp LIBOMP_USE_ITT_NOTIFY)
114   libomp_append(LIBOMP_CXXFILES kmp_debugger.cpp LIBOMP_USE_DEBUGGER)
115   libomp_append(LIBOMP_CXXFILES kmp_stats.cpp LIBOMP_STATS)
116   libomp_append(LIBOMP_CXXFILES kmp_stats_timing.cpp LIBOMP_STATS)
117   libomp_append(LIBOMP_CXXFILES kmp_taskdeps.cpp)
118   libomp_append(LIBOMP_CXXFILES kmp_cancel.cpp)
119 endif()
120 # Files common to stubs and normal library
121 libomp_append(LIBOMP_CXXFILES kmp_ftn_cdecl.cpp)
122 libomp_append(LIBOMP_CXXFILES kmp_ftn_extra.cpp)
123 libomp_append(LIBOMP_CXXFILES kmp_version.cpp)
124 libomp_append(LIBOMP_CXXFILES ompt-general.cpp IF_TRUE LIBOMP_OMPT_SUPPORT)
125 libomp_append(LIBOMP_CXXFILES ompd-specific.cpp IF_TRUE LIBOMP_OMPD_SUPPORT)
127 set(LIBOMP_SOURCE_FILES ${LIBOMP_CXXFILES} ${LIBOMP_ASMFILES} ${LIBOMP_GNUASMFILES})
128 # For Windows, there is a resource file (.rc -> .res) that is also compiled
129 libomp_append(LIBOMP_SOURCE_FILES libomp.rc WIN32)
131 # Get compiler and assembler flags
132 libomp_get_cxxflags(LIBOMP_CONFIGURED_CXXFLAGS)
133 libomp_get_asmflags(LIBOMP_CONFIGURED_ASMFLAGS)
134 # Set the compiler flags for each type of source
135 set_source_files_properties(${LIBOMP_CXXFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CXXFLAGS}")
136 set_source_files_properties(${LIBOMP_ASMFILES} ${LIBOMP_GNUASMFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_ASMFLAGS}")
138 # Remove any cmake-automatic linking of the standard C++ library.
139 # We neither need (nor want) the standard C++ library dependency even though we compile c++ files.
140 if(NOT ${LIBOMP_USE_STDCPPLIB})
141   set(LIBOMP_LINKER_LANGUAGE C)
142   set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
143 else()
144   set(LIBOMP_LINKER_LANGUAGE CXX)
145 endif()
147 if(UNIX)
148   set(LIBOMP_DL_LIBS ${CMAKE_DL_LIBS})
149 endif()
151 # Add the OpenMP library
152 libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)
154 libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS)
155 # Build libomp library. Add LLVMSupport dependency if building in-tree with libomptarget profiling enabled.
156 if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING))
157   add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES})
158   # Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS
159   target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS})
160 else()
161   add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED
162     LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}
163     LINK_COMPONENTS Support
164     )
165   # libomp must be a C++ library such that it can link libLLVMSupport
166   set(LIBOMP_LINKER_LANGUAGE CXX)
167 endif()
168 if(${LIBOMP_USE_HWLOC})
169   target_include_directories(omp
170                              PUBLIC
171                              "$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
172                              "$<INSTALL_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
173   )
174 endif()
176 if(OPENMP_MSVC_NAME_SCHEME)
177   if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
178     set(LIBOMP_PDB_NAME ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH})
179     set(LIBOMP_LIB_FILE ${LIBOMP_PDB_NAME}${LIBOMP_LIBRARY_SUFFIX})
180   else()
181     # ${LIBOMP_LIB_NAME} is ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}.${LIBOMP_ARCH}
182     set(LIBOMP_PDB_NAME ${LIBOMP_LIB_NAME})
183   endif()
185   # in debug
186   # LIBOMP_LIB_FILE should be LIBOMP_LIB_FILE_DBG = ${LIBOMP_LIB_NAME_DBG}${LIBOMP_LIBRARY_SUFFIX}
187   #                                             = ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH}${LIBOMP_LIBRARY_SUFFIX}
188   # COMPILE_PDB_NAME/PDB_NAME should be LIBOMP_LIB_NAME_DBG = ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH}
189   set_target_properties(omp PROPERTIES
190     PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}"
191     PDB_NAME "${LIBOMP_PDB_NAME}"
192     COMPILE_PDB_NAME "${LIBOMP_PDB_NAME}"
193     LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"
194     LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
196 else()
197   set_target_properties(omp PROPERTIES
198     PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}"
199     LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"
200     LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
201   )
202 endif()
204 # Get the library's location within the build tree for the unit tester
205 if(NOT WIN32)
206   get_target_property(LIBOMP_LIBRARY_DIR omp LIBRARY_OUTPUT_DIRECTORY)
207 else()
208   get_target_property(LIBOMP_LIBRARY_DIR omp RUNTIME_OUTPUT_DIRECTORY)
209 endif()
210 if(NOT LIBOMP_LIBRARY_DIR)
211   set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
212   set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
213 else()
214   set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
215 endif()
216 set(LIBOMP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
218 # Add symbolic links to libomp
219 if(NOT WIN32)
220   add_custom_command(TARGET omp POST_BUILD
221     COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE}
222       libgomp${LIBOMP_LIBRARY_SUFFIX}
223     COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE}
224       libiomp5${LIBOMP_LIBRARY_SUFFIX}
225     WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}
226   )
227 endif()
228 set(LIBOMP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
230 # Create *.inc before compiling any sources
231 # objects depend on : .inc files
232 add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc)
233 add_dependencies(omp libomp-needed-headers)
235 # Windows specific build rules
236 if(WIN32)
237   configure_file(libomp.rc.var libomp.rc @ONLY)
238   # z_Windows_NT-586_asm.asm requires definitions to be sent via command line
239   # It only needs the architecture macro and OMPT_SUPPORT=0|1
240   libomp_append(LIBOMP_MASM_DEFINITIONS "-D_M_IA32" IF_TRUE IA32)
241   libomp_append(LIBOMP_MASM_DEFINITIONS "-D_M_AMD64" IF_TRUE INTEL64)
242   libomp_append(LIBOMP_MASM_DEFINITIONS "-DOMPT_SUPPORT" IF_TRUE_1_0 LIBOMP_OMPT_SUPPORT)
243   libomp_append(LIBOMP_MASM_DEFINITIONS "-DOMPD_SUPPORT" IF_TRUE_1_0 LIBOMP_OMPD_SUPPORT)
244   libomp_list_to_string("${LIBOMP_MASM_DEFINITIONS}" LIBOMP_MASM_DEFINITIONS)
245   set_property(SOURCE z_Windows_NT-586_asm.asm APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBOMP_MASM_DEFINITIONS}")
246   set_source_files_properties(thirdparty/ittnotify/ittnotify_static.cpp PROPERTIES COMPILE_DEFINITIONS "UNICODE")
248   # Create Windows import library
249   # On debug LIBOMP_IMP_LIB_FILE should be LIBOMP_IMP_LIB_FILE_DBG = ${LIBOMP_DEFAULT_LIB_NAME_DBG}${CMAKE_STATIC_LIBRARY_SUFFIX}
250   #                                                                     ${LIBOMP_DEFAULT_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX}
251   # and the ARCHIVE_OUTPUT_NAME of ompdbg should be ${LIBOMP_DEFAULT_LIB_NAME_DBG}${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
253   if(OPENMP_MSVC_NAME_SCHEME)
254     if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
255       set(LIBOMP_IMP_LIB_FILE ${LIBOMP_DEFAULT_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX})
256       set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_DEFAULT_LIB_NAME}d${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})
257     else()
258       set(LIBOMP_IMP_LIB_FILE ${LIBOMP_DEFAULT_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})
259       set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_DEFAULT_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})
260     endif()
261   else()
262     set(LIBOMP_IMP_LIB_FILE ${LIBOMP_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})
263     set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_LIB_FILE}${CMAKE_STATIC_LIBRARY_SUFFIX})
264   endif()
265   set_target_properties(omp PROPERTIES
266     VERSION ${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR} # uses /version flag
267     IMPORT_PREFIX "" IMPORT_SUFFIX "" # control generated import library name when building omp
268     ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME}
269   )
271   set(LIBOMP_IMP_LIB_TARGET omp)
272   set(LIBOMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.def)
273   add_custom_target(libomp-needed-def-file DEPENDS ${LIBOMP_GENERATED_DEF_FILE})
274   add_dependencies(omp libomp-needed-def-file)
276   # Create the main def file with ordinals to use for building the runtime dll to maintain backwards compatible exports order
277   libomp_get_gdflags(LIBOMP_GDFLAGS)
278   libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
279   add_custom_command(
280     OUTPUT  ${LIBOMP_GENERATED_DEF_FILE}
281     COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE}
282             -o ${LIBOMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
283     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
284   )
286   if(MSVC)
287     # For toolchains that generated the import library importing by ordinal, re-generate it to import by name
288     set(LIBOMP_IMP_LIB_TARGET ompimp)
289     # Create the auxiliary def file without ordinals to use for building the import library to import by name
290     set(LIBOMPIMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.imp.def)
291     add_custom_target(libompimp-needed-def-file DEPENDS ${LIBOMPIMP_GENERATED_DEF_FILE})
292     add_custom_command(
293       OUTPUT  ${LIBOMPIMP_GENERATED_DEF_FILE}
294       COMMAND ${PERL_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.pl ${LIBOMP_GDFLAGS} -D NAME=${LIBOMP_LIB_FILE} -D NOORDINALS
295           -o ${LIBOMPIMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
296       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.pl
297     )
298     # 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,
299     # 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)
300     add_library(${LIBOMP_IMP_LIB_TARGET} STATIC kmp_dummy.txt)
301     set_target_properties(${LIBOMP_IMP_LIB_TARGET} PROPERTIES
302         PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}" LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
303         STATIC_LIBRARY_OPTIONS "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE}")
304     add_dependencies(${LIBOMP_IMP_LIB_TARGET} libompimp-needed-def-file)
305   endif()
306 endif()
308 # Building the Fortran module files
309 # One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
310 if(${LIBOMP_FORTRAN_MODULES})
311   configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
312   configure_file(${LIBOMP_INC_DIR}/omp_lib.f90.var omp_lib.f90 @ONLY)
313   # Workaround for gfortran to build modules with the
314   # omp_sched_monotonic integer parameter
315   if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
316     set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
317   endif()
318   add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
319   libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
320   if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
321     set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.f90)
322   else()
323     message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
324   endif()
325   add_custom_command(
326     OUTPUT omp_lib.mod omp_lib_kinds.mod
327     COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
328             ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE}
329     DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
330       ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
331   )
332   set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${CMAKE_C_OUTPUT_EXTENSION})
333 endif()
335 # Move files to exports/ directory if requested
336 if(${LIBOMP_COPY_EXPORTS})
337   include(LibompExports)
338 endif()
340 # Micro test rules for after library has been built (cmake/LibompMicroTests.cmake)
341 include(LibompMicroTests)
342 add_custom_target(libomp-micro-tests)
343 if(NOT ${MIC} AND NOT CMAKE_CROSSCOMPILING)
344   add_dependencies(libomp-micro-tests libomp-test-touch)
345 endif()
346 if(NOT WIN32 AND NOT APPLE)
347   add_dependencies(libomp-micro-tests libomp-test-relo)
348 endif()
349 if(NOT WIN32 AND NOT APPLE)
350   add_dependencies(libomp-micro-tests libomp-test-execstack)
351 endif()
352 if(${MIC})
353   add_dependencies(libomp-micro-tests libomp-test-instr)
354 endif()
355 add_dependencies(libomp-micro-tests libomp-test-deps)
357 # `omp` needs to be exported if in-tree build.
358 set(export_to_llvmexports)
359 if (NOT OPENMP_STANDALONE_BUILD)
360   get_target_export_arg(omp LLVM export_to_llvmexports)
361   set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS omp)
362 endif()
364 # Install rules
365 # We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR}
366 # We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
367 if(WIN32)
368   install(TARGETS omp ${export_to_llvmexports} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
369   install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
370   # Create aliases (regular copies) of the library for backwards compatibility
371   set(LIBOMP_ALIASES "libiomp5md")
372   foreach(alias IN LISTS LIBOMP_ALIASES)
373     install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\"
374       \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${CMAKE_INSTALL_FULL_BINDIR}\")")
375     extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
376     install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\"
377       \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${outdir}\")")
378   endforeach()
379 else()
381   install(TARGETS omp ${export_to_llvmexports} ${LIBOMP_INSTALL_KIND} DESTINATION "${OPENMP_INSTALL_LIBDIR}")
383   if(${LIBOMP_INSTALL_ALIASES})
384     # Create aliases (symlinks) of the library for backwards compatibility
385     set(LIBOMP_ALIASES "libgomp;libiomp5")
386     foreach(alias IN LISTS LIBOMP_ALIASES)
387       extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
388       install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
389         \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY
390         \"\$ENV{DESTDIR}${outdir}\")")
391     endforeach()
392   endif()
393 endif()
394 install(
395   FILES
396   ${CMAKE_CURRENT_BINARY_DIR}/omp.h
397   ${CMAKE_CURRENT_BINARY_DIR}/ompx.h
398   DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
400 if(${LIBOMP_OMPT_SUPPORT})
401   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH})
402   # install under legacy name ompt.h
403   install(FILES ${CMAKE_CURRENT_BINARY_DIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)
404   set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
405 endif()
406 if(${LIBOMP_FORTRAN_MODULES})
407   install(FILES
408     ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
409     ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod
410     ${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod
411     DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
412   )
413 endif()