[memprof] Upgrade a unit test to MemProf Version 3 (#117063)
[llvm-project.git] / openmp / runtime / src / CMakeLists.txt
blob698e185d9c4dde6ebc52965bed7537fb4e05b57d
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 # The generated headers will be placed in clang's resource directory if present.
14 if(OPENMP_STANDALONE_BUILD OR NOT LLVM_RUNTIMES_BUILD)
15   set(LIBOMP_HEADERS_INTDIR ${CMAKE_CURRENT_BINARY_DIR})
16 else()
17   set(LIBOMP_HEADERS_INTDIR ${LLVM_BINARY_DIR}/${LIBOMP_HEADERS_INSTALL_PATH})
18 endif()
20 # Configure omp.h, kmp_config.h and omp-tools.h if necessary
21 configure_file(${LIBOMP_INC_DIR}/omp.h.var ${LIBOMP_HEADERS_INTDIR}/omp.h @ONLY)
22 configure_file(${LIBOMP_INC_DIR}/ompx.h.var ${LIBOMP_HEADERS_INTDIR}/ompx.h @ONLY)
23 configure_file(kmp_config.h.cmake kmp_config.h @ONLY)
24 if(${LIBOMP_OMPT_SUPPORT})
25   configure_file(${LIBOMP_INC_DIR}/omp-tools.h.var ${LIBOMP_HEADERS_INTDIR}/omp-tools.h @ONLY)
26 endif()
28 # Generate message catalog files: kmp_i18n_id.inc and kmp_i18n_default.inc
29 set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS "")
30 if("${CMAKE_SYSTEM_NAME}" STREQUAL "Emscripten")
31   # Required as Python doesn't inherit CMake's environment setup and uses the host system as the target system by default
32   set(LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} --target-system-override=${CMAKE_SYSTEM_NAME})
33 endif()
35 add_custom_command(
36   OUTPUT  kmp_i18n_id.inc
37   COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
38           --enum=kmp_i18n_id.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt
39   DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
41 add_custom_command(
42   OUTPUT  kmp_i18n_default.inc
43   COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/message-converter.py
44           --default=kmp_i18n_default.inc ${LIBOMP_MESSAGE_CONVERTER_EXTRA_ARGS} ${LIBOMP_SRC_DIR}/i18n/en_US.txt
45   DEPENDS ${LIBOMP_SRC_DIR}/i18n/en_US.txt ${LIBOMP_TOOLS_DIR}/message-converter.py
48 # Set the -D definitions for all sources
49 # UNICODE and _UNICODE are set in LLVM's CMake system.  They affect the
50 # ittnotify code and should only be set when compiling ittnotify_static.cpp
51 # on Windows (done below).
52 # TODO: Fix the UNICODE usage in ittnotify code for Windows.
53 remove_definitions(-DUNICODE -D_UNICODE)
54 libomp_get_definitions_flags(LIBOMP_CONFIGURED_DEFINITIONS_FLAGS)
55 add_definitions(${LIBOMP_CONFIGURED_DEFINITIONS_FLAGS})
57 # Set the -I includes for all sources
58 include_directories(
59   ${CMAKE_CURRENT_BINARY_DIR}
60   ${LIBOMP_SRC_DIR}
61   ${LIBOMP_SRC_DIR}/i18n
62   ${LIBOMP_INC_DIR}
63   ${LIBOMP_SRC_DIR}/thirdparty/ittnotify
66 # Building with time profiling support requires LLVM directory includes.
67 if(LIBOMP_PROFILING_SUPPORT)
68   include_directories(
69     ${LLVM_MAIN_INCLUDE_DIR}
70     ${LLVM_INCLUDE_DIR}
71   )
72 endif()
74 # Getting correct source files to build library
75 set(LIBOMP_CXXFILES)
76 set(LIBOMP_ASMFILES)
77 set(LIBOMP_GNUASMFILES)
78 if(STUBS_LIBRARY)
79   set(LIBOMP_CXXFILES kmp_stub.cpp)
80 else()
81   # Get C++ files
82   set(LIBOMP_CXXFILES
83     kmp_alloc.cpp
84     kmp_atomic.cpp
85     kmp_csupport.cpp
86     kmp_debug.cpp
87     kmp_itt.cpp
88     kmp_environment.cpp
89     kmp_error.cpp
90     kmp_global.cpp
91     kmp_i18n.cpp
92     kmp_io.cpp
93     kmp_runtime.cpp
94     kmp_settings.cpp
95     kmp_str.cpp
96     kmp_tasking.cpp
97     kmp_threadprivate.cpp
98     kmp_utility.cpp
99     kmp_barrier.cpp
100     kmp_wait_release.cpp
101     kmp_affinity.cpp
102     kmp_dispatch.cpp
103     kmp_lock.cpp
104     kmp_sched.cpp
105     kmp_collapse.cpp
106   )
107   if(WIN32)
108     # Windows specific files
109     libomp_append(LIBOMP_CXXFILES z_Windows_NT_util.cpp)
110     libomp_append(LIBOMP_CXXFILES z_Windows_NT-586_util.cpp)
111     if(${LIBOMP_ARCH} STREQUAL "i386" OR ${LIBOMP_ARCH} STREQUAL "x86_64")
112       libomp_append(LIBOMP_ASMFILES z_Windows_NT-586_asm.asm) # Windows assembly file
113     elseif((${LIBOMP_ARCH} STREQUAL "aarch64" OR ${LIBOMP_ARCH} STREQUAL "arm") AND (NOT MSVC OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))
114       # z_Linux_asm.S works for AArch64 and ARM Windows too.
115       libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S)
116     else()
117       # AArch64 with MSVC gets implementations of the functions from
118       # ifdeffed sections in z_Windows_NT-586_util.cpp.
119     endif()
120   else()
121     # Unix specific files
122     libomp_append(LIBOMP_CXXFILES z_Linux_util.cpp)
123     libomp_append(LIBOMP_CXXFILES kmp_gsupport.cpp)
124     if(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
125       libomp_append(LIBOMP_GNUASMFILES z_AIX_asm.S) # AIX assembly file
126     else()
127       libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S) # Unix assembly file
128     endif()
129   endif()
130   libomp_append(LIBOMP_CXXFILES thirdparty/ittnotify/ittnotify_static.cpp LIBOMP_USE_ITT_NOTIFY)
131   libomp_append(LIBOMP_CXXFILES kmp_debugger.cpp LIBOMP_USE_DEBUGGER)
132   libomp_append(LIBOMP_CXXFILES kmp_stats.cpp LIBOMP_STATS)
133   libomp_append(LIBOMP_CXXFILES kmp_stats_timing.cpp LIBOMP_STATS)
134   libomp_append(LIBOMP_CXXFILES kmp_taskdeps.cpp)
135   libomp_append(LIBOMP_CXXFILES kmp_cancel.cpp)
136 endif()
137 # Files common to stubs and normal library
138 libomp_append(LIBOMP_CXXFILES kmp_ftn_cdecl.cpp)
139 libomp_append(LIBOMP_CXXFILES kmp_ftn_extra.cpp)
140 libomp_append(LIBOMP_CXXFILES kmp_version.cpp)
141 libomp_append(LIBOMP_CXXFILES ompt-general.cpp IF_TRUE LIBOMP_OMPT_SUPPORT)
142 libomp_append(LIBOMP_CXXFILES ompd-specific.cpp IF_TRUE LIBOMP_OMPD_SUPPORT)
144 set(LIBOMP_SOURCE_FILES ${LIBOMP_CXXFILES} ${LIBOMP_ASMFILES} ${LIBOMP_GNUASMFILES})
145 # For Windows, there is a resource file (.rc -> .res) that is also compiled
146 libomp_append(LIBOMP_SOURCE_FILES libomp.rc WIN32)
148 # Get compiler and assembler flags
149 libomp_get_cxxflags(LIBOMP_CONFIGURED_CXXFLAGS)
150 libomp_get_asmflags(LIBOMP_CONFIGURED_ASMFLAGS)
151 # Set the compiler flags for each type of source
152 set_source_files_properties(${LIBOMP_CXXFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_CXXFLAGS}")
153 set_source_files_properties(${LIBOMP_ASMFILES} ${LIBOMP_GNUASMFILES} PROPERTIES COMPILE_FLAGS "${LIBOMP_CONFIGURED_ASMFLAGS}")
155 # Remove any cmake-automatic linking of the standard C++ library.
156 # We neither need (nor want) the standard C++ library dependency even though we compile c++ files.
157 if(NOT ${LIBOMP_USE_STDCPPLIB})
158   set(LIBOMP_LINKER_LANGUAGE C)
159   set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES)
160 else()
161   set(LIBOMP_LINKER_LANGUAGE CXX)
162 endif()
164 if(UNIX)
165   set(LIBOMP_DL_LIBS ${CMAKE_DL_LIBS})
166 endif()
168 # Disable libstdc++ assertions, even in an LLVM_ENABLE_ASSERTIONS build, to
169 # avoid an unwanted dependency on libstdc++.so.
170 if(NOT WIN32)
171   add_definitions(-U_GLIBCXX_ASSERTIONS)
172 endif()
174 # Add the OpenMP library
175 libomp_get_ldflags(LIBOMP_CONFIGURED_LDFLAGS)
177 libomp_get_libflags(LIBOMP_CONFIGURED_LIBFLAGS)
178 # Build libomp library. Add LLVMSupport dependency if building in-tree with libomptarget profiling enabled.
179 if(OPENMP_STANDALONE_BUILD OR (NOT OPENMP_ENABLE_LIBOMP_PROFILING))
180   add_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES})
181   set_property(TARGET omp PROPERTY FOLDER "OpenMP/Libraries")
182   # Linking command will include libraries in LIBOMP_CONFIGURED_LIBFLAGS
183   target_link_libraries(omp ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS})
184 else()
185   add_llvm_library(omp ${LIBOMP_LIBRARY_KIND} ${LIBOMP_SOURCE_FILES} PARTIAL_SOURCES_INTENDED
186     LINK_LIBS ${LIBOMP_CONFIGURED_LIBFLAGS} ${LIBOMP_DL_LIBS}
187     LINK_COMPONENTS Support
188     BUILDTREE_ONLY
189     )
190   # libomp must be a C++ library such that it can link libLLVMSupport
191   set(LIBOMP_LINKER_LANGUAGE CXX)
192 endif()
193 if(${LIBOMP_USE_HWLOC})
194   target_include_directories(omp
195                              PUBLIC
196                              "$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
197                              "$<INSTALL_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
198   )
199 endif()
201 if(OPENMP_MSVC_NAME_SCHEME)
202   if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
203     set(LIBOMP_PDB_NAME ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH})
204     set(LIBOMP_LIB_FILE ${LIBOMP_PDB_NAME}${LIBOMP_LIBRARY_SUFFIX})
205   else()
206     # ${LIBOMP_LIB_NAME} is ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}.${LIBOMP_ARCH}
207     set(LIBOMP_PDB_NAME ${LIBOMP_LIB_NAME})
208   endif()
210   # in debug
211   # LIBOMP_LIB_FILE should be LIBOMP_LIB_FILE_DBG = ${LIBOMP_LIB_NAME_DBG}${LIBOMP_LIBRARY_SUFFIX}
212   #                                             = ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH}${LIBOMP_LIBRARY_SUFFIX}
213   # COMPILE_PDB_NAME/PDB_NAME should be LIBOMP_LIB_NAME_DBG = ${LIBOMP_DEFAULT_LIB_NAME}${MSVC_TOOLS_VERSION}d.${LIBOMP_ARCH}
214   set_target_properties(omp PROPERTIES
215     PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}"
216     PDB_NAME "${LIBOMP_PDB_NAME}"
217     COMPILE_PDB_NAME "${LIBOMP_PDB_NAME}"
218     LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"
219     LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
221 elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX")
222   set(LIBOMP_SHARED_OUTPUT_NAME "omp" CACHE STRING "Output name for the shared libomp runtime library.")
223   set_target_properties(omp PROPERTIES
224     OUTPUT_NAME "${LIBOMP_SHARED_OUTPUT_NAME}"
225     LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"
226     LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
227     VERSION "1.0"
228     SOVERSION "1"
229   )
230 else()
231   set_target_properties(omp PROPERTIES
232     PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_LIB_FILE}"
233     LINK_FLAGS "${LIBOMP_CONFIGURED_LDFLAGS}"
234     LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
235   )
236 endif()
238 # Get the library's location within the build tree for the unit tester
239 if(NOT WIN32)
240   get_target_property(LIBOMP_LIBRARY_DIR omp LIBRARY_OUTPUT_DIRECTORY)
241 else()
242   get_target_property(LIBOMP_LIBRARY_DIR omp RUNTIME_OUTPUT_DIRECTORY)
243 endif()
244 if(NOT LIBOMP_LIBRARY_DIR)
245   set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
246   set(LIBOMP_LIBRARY_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
247 else()
248   set(LIBOMP_LIBRARY_DIR ${LIBOMP_LIBRARY_DIR} PARENT_SCOPE)
249 endif()
250 set(LIBOMP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR})
251 set(LIBOMP_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
253 # Add symbolic links to libomp
254 if(NOT WIN32)
255   add_custom_command(TARGET omp POST_BUILD
256     COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE}
257       libgomp${LIBOMP_LIBRARY_SUFFIX}
258     COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE}
259       libiomp5${LIBOMP_LIBRARY_SUFFIX}
260     WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}
261   )
262   if(LIBOMP_ENABLE_SHARED)
263     if(APPLE)
264       set(VERSIONED_LIBGOMP_NAME libgomp.1${LIBOMP_LIBRARY_SUFFIX})
265     else()
266       set(VERSIONED_LIBGOMP_NAME libgomp${LIBOMP_LIBRARY_SUFFIX}.1)
267     endif()
268     add_custom_command(TARGET omp POST_BUILD
269       COMMAND ${CMAKE_COMMAND} -E create_symlink ${LIBOMP_LIB_FILE} ${VERSIONED_LIBGOMP_NAME}
270       WORKING_DIRECTORY ${LIBOMP_LIBRARY_DIR}
271     )
272   endif()
273 endif()
275 # Definitions for testing, for reuse when testing libomptarget-nvptx.
276 set(LIBOMPTARGET_OPENMP_HEADER_FOLDER "${LIBOMP_INCLUDE_DIR}" CACHE STRING
277   "Path to folder containing omp.h")
278 set(LIBOMPTARGET_OPENMP_HOST_RTL_FOLDER "${LIBOMP_LIBRARY_DIR}" CACHE STRING
279   "Path to folder containing libomp.so, and libLLVMSupport.so with profiling enabled")
281 # Create *.inc before compiling any sources
282 # objects depend on : .inc files
283 add_custom_target(libomp-needed-headers DEPENDS kmp_i18n_id.inc kmp_i18n_default.inc)
284 set_target_properties(libomp-needed-headers PROPERTIES FOLDER "OpenMP/Sourcegenning")
285 add_dependencies(omp libomp-needed-headers)
287 # Windows specific build rules
288 if(WIN32)
289   configure_file(libomp.rc.var libomp.rc @ONLY)
290   # z_Windows_NT-586_asm.asm requires definitions to be sent via command line
291   # It only needs the architecture macro and OMPT_SUPPORT=0|1
292   libomp_append(LIBOMP_MASM_DEFINITIONS "-D_M_IA32" IF_TRUE IA32)
293   libomp_append(LIBOMP_MASM_DEFINITIONS "-D_M_AMD64" IF_TRUE INTEL64)
294   libomp_append(LIBOMP_MASM_DEFINITIONS "-DOMPT_SUPPORT" IF_TRUE_1_0 LIBOMP_OMPT_SUPPORT)
295   libomp_append(LIBOMP_MASM_DEFINITIONS "-DOMPD_SUPPORT" IF_TRUE_1_0 LIBOMP_OMPD_SUPPORT)
296   libomp_list_to_string("${LIBOMP_MASM_DEFINITIONS}" LIBOMP_MASM_DEFINITIONS)
297   set_property(SOURCE z_Windows_NT-586_asm.asm APPEND_STRING PROPERTY COMPILE_FLAGS " ${LIBOMP_MASM_DEFINITIONS}")
298   set_source_files_properties(thirdparty/ittnotify/ittnotify_static.cpp PROPERTIES COMPILE_DEFINITIONS "UNICODE")
300   # Create Windows import library
301   # On debug LIBOMP_IMP_LIB_FILE should be LIBOMP_IMP_LIB_FILE_DBG = ${LIBOMP_DEFAULT_LIB_NAME_DBG}${CMAKE_STATIC_LIBRARY_SUFFIX}
302   #                                                                     ${LIBOMP_DEFAULT_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX}
303   # and the ARCHIVE_OUTPUT_NAME of ompdbg should be ${LIBOMP_DEFAULT_LIB_NAME_DBG}${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
305   if(OPENMP_MSVC_NAME_SCHEME)
306     if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
307       set(LIBOMP_IMP_LIB_FILE ${LIBOMP_DEFAULT_LIB_NAME}d${CMAKE_STATIC_LIBRARY_SUFFIX})
308       set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_DEFAULT_LIB_NAME}d${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})
309     else()
310       set(LIBOMP_IMP_LIB_FILE ${LIBOMP_DEFAULT_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})
311       set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_DEFAULT_LIB_NAME}${LIBOMP_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX})
312     endif()
313   else()
314     set(LIBOMP_IMP_LIB_FILE ${LIBOMP_LIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX})
315     set(LIBOMP_GENERATED_IMP_LIB_FILENAME ${LIBOMP_LIB_FILE}${CMAKE_STATIC_LIBRARY_SUFFIX})
316   endif()
317   set_target_properties(omp PROPERTIES
318     VERSION ${LIBOMP_VERSION_MAJOR}.${LIBOMP_VERSION_MINOR} # uses /version flag
319     IMPORT_PREFIX "" IMPORT_SUFFIX "" # control generated import library name when building omp
320     ARCHIVE_OUTPUT_NAME ${LIBOMP_GENERATED_IMP_LIB_FILENAME}
321   )
323   set(LIBOMP_IMP_LIB_TARGET omp)
324   set(LIBOMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.def)
325   add_custom_target(libomp-needed-def-file DEPENDS ${LIBOMP_GENERATED_DEF_FILE})
326   set_target_properties(libomp-needed-def-file PROPERTIES FOLDER "OpenMP/Sourcegenning")
327   add_dependencies(omp libomp-needed-def-file)
329   # Create the main def file with ordinals to use for building the runtime dll to maintain backwards compatible exports order
330   libomp_get_gdflags(LIBOMP_GDFLAGS)
331   libomp_string_to_list("${LIBOMP_GDFLAGS}" LIBOMP_GDFLAGS)
333   add_custom_command(
334     OUTPUT  ${LIBOMP_GENERATED_DEF_FILE}
335     COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.py ${LIBOMP_GDFLAGS} --name ${LIBOMP_LIB_FILE}
336             -o ${LIBOMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
337     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.py
338   )
340   if(MSVC)
341     # For toolchains that generated the import library importing by ordinal, re-generate it to import by name
342     set(LIBOMP_IMP_LIB_TARGET ompimp)
343     # Create the auxiliary def file without ordinals to use for building the import library to import by name
344     set(LIBOMPIMP_GENERATED_DEF_FILE ${LIBOMP_LIB_NAME}.imp.def)
345     add_custom_target(libompimp-needed-def-file DEPENDS ${LIBOMPIMP_GENERATED_DEF_FILE})
346     set_target_properties(libompimp-needed-def-file PROPERTIES FOLDER "OpenMP/Resources")
347     add_custom_command(
348       OUTPUT  ${LIBOMPIMP_GENERATED_DEF_FILE}
349       COMMAND ${Python3_EXECUTABLE} ${LIBOMP_TOOLS_DIR}/generate-def.py ${LIBOMP_GDFLAGS}
350               --name ${LIBOMP_LIB_FILE} --no-ordinals
351               -o ${LIBOMPIMP_GENERATED_DEF_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/dllexports
352       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dllexports ${LIBOMP_TOOLS_DIR}/generate-def.py
353     )
354     # 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,
355     # 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)
356     add_library(${LIBOMP_IMP_LIB_TARGET} STATIC kmp_dummy.txt)
357     set_target_properties(${LIBOMP_IMP_LIB_TARGET} PROPERTIES FOLDER "OpenMP/Libraries")
358     set_target_properties(${LIBOMP_IMP_LIB_TARGET} PROPERTIES
359         PREFIX "" SUFFIX "" OUTPUT_NAME "${LIBOMP_IMP_LIB_FILE}" LINKER_LANGUAGE ${LIBOMP_LINKER_LANGUAGE}
360         STATIC_LIBRARY_OPTIONS "${CMAKE_LINK_DEF_FILE_FLAG}${CMAKE_CURRENT_BINARY_DIR}/${LIBOMPIMP_GENERATED_DEF_FILE}")
361     add_dependencies(${LIBOMP_IMP_LIB_TARGET} libompimp-needed-def-file)
362     add_dependencies(omp ${LIBOMP_IMP_LIB_TARGET})
363   endif()
364 endif()
366 # Building the Fortran module files
367 # One compilation step creates both omp_lib.mod and omp_lib_kinds.mod
368 configure_file(${LIBOMP_INC_DIR}/omp_lib.h.var omp_lib.h @ONLY)
369 configure_file(${LIBOMP_INC_DIR}/omp_lib.F90.var omp_lib.F90 @ONLY)
371 set(BUILD_FORTRAN_MODULES False)
372 if (NOT ${LIBOMP_FORTRAN_MODULES_COMPILER} STREQUAL "")
373   # If libomp is built as an LLVM runtime and the flang compiler is available,
374   # compile the Fortran module files.
375   message(STATUS "configuring openmp to build Fortran module files using ${LIBOMP_FORTRAN_MODULES_COMPILER}")
376   set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
377   add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
378   add_custom_command(
379     OUTPUT omp_lib.mod omp_lib_kinds.mod
380     COMMAND ${LIBOMP_FORTRAN_MODULES_COMPILER} -cpp -fsyntax-only ${LIBOMP_FORTRAN_SOURCE_FILE}
381     DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
382       ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
383   )
384   set(BUILD_FORTRAN_MODULES True)
385 elseif(${LIBOMP_FORTRAN_MODULES})
386   # The following requests explicit building of the Fortran module files
387   # Workaround for gfortran to build modules with the
388   # omp_sched_monotonic integer parameter
389   if (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
390     set(ADDITIONAL_Fortran_FLAGS "-fno-range-check")
391   endif()
392   add_custom_target(libomp-mod ALL DEPENDS omp_lib.mod omp_lib_kinds.mod)
393   set_target_properties(libomp-mod PROPERTIES FOLDER "OpenMP/Misc")
394   libomp_get_fflags(LIBOMP_CONFIGURED_FFLAGS)
395   if(CMAKE_Fortran_COMPILER_SUPPORTS_F90)
396     set(LIBOMP_FORTRAN_SOURCE_FILE omp_lib.F90)
397   else()
398     message(FATAL_ERROR "Fortran module build requires Fortran 90 compiler")
399   endif()
400   add_custom_command(
401     OUTPUT omp_lib.mod omp_lib_kinds.mod
402     COMMAND ${CMAKE_Fortran_COMPILER} -c ${ADDITIONAL_Fortran_FLAGS}
403             ${LIBOMP_CONFIGURED_FFLAGS} ${LIBOMP_FORTRAN_SOURCE_FILE}
404     DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${LIBOMP_FORTRAN_SOURCE_FILE}
405       ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
406   )
407   set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES omp_lib${CMAKE_C_OUTPUT_EXTENSION})
408   set(BUILD_FORTRAN_MODULES True)
409 endif()
411 # Move files to exports/ directory if requested
412 if(${LIBOMP_COPY_EXPORTS})
413   include(LibompExports)
414 endif()
416 # Micro test rules for after library has been built (cmake/LibompMicroTests.cmake)
417 include(LibompMicroTests)
418 add_custom_target(libomp-micro-tests)
419 set_target_properties(libomp-micro-tests PROPERTIES FOLDER "OpenMP/Tests")
420 if(NOT ${MIC} AND NOT CMAKE_CROSSCOMPILING)
421   add_dependencies(libomp-micro-tests libomp-test-touch)
422 endif()
423 if(NOT WIN32 AND NOT APPLE)
424   add_dependencies(libomp-micro-tests libomp-test-relo)
425 endif()
426 if(NOT WIN32 AND NOT APPLE)
427   add_dependencies(libomp-micro-tests libomp-test-execstack)
428 endif()
429 add_dependencies(libomp-micro-tests libomp-test-deps)
431 # `omp` needs to be exported if in-tree build.
432 set(export_to_llvmexports)
433 if (NOT OPENMP_STANDALONE_BUILD)
434   get_target_export_arg(omp LLVM export_to_llvmexports)
435   set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS omp)
436 endif()
438 # Install rules
439 # We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR}
440 # We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
441 if(WIN32)
442   install(TARGETS omp ${export_to_llvmexports} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
443   install(TARGETS ${LIBOMP_IMP_LIB_TARGET} ARCHIVE DESTINATION "${OPENMP_INSTALL_LIBDIR}")
444   # Create aliases (regular copies) of the library for backwards compatibility
445   set(LIBOMP_ALIASES "libiomp5md")
446   foreach(alias IN LISTS LIBOMP_ALIASES)
447     install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\"
448       \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${CMAKE_INSTALL_FULL_BINDIR}\")")
449     extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
450     install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\"
451       \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${outdir}\")")
452   endforeach()
453 else()
455   install(TARGETS omp ${export_to_llvmexports} ${LIBOMP_INSTALL_KIND} DESTINATION "${OPENMP_INSTALL_LIBDIR}")
457   if(${LIBOMP_INSTALL_ALIASES})
458     # Create aliases (symlinks) of the library for backwards compatibility
459     extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
460     set(LIBOMP_ALIASES "libgomp;libiomp5")
461     foreach(alias IN LISTS LIBOMP_ALIASES)
462       install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
463         \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY
464         \"\$ENV{DESTDIR}${outdir}\")")
465     endforeach()
466     if(LIBOMP_ENABLE_SHARED)
467       install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
468         \"${VERSIONED_LIBGOMP_NAME}\" WORKING_DIRECTORY
469         \"\$ENV{DESTDIR}${outdir}\")")
470     endif()
471   endif()
472 endif()
473 install(
474   FILES
475   ${LIBOMP_HEADERS_INTDIR}/omp.h
476   ${LIBOMP_HEADERS_INTDIR}/ompx.h
477   DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
479 if(${LIBOMP_OMPT_SUPPORT})
480   install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH})
481   # install under legacy name ompt.h
482   install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)
483   set(LIBOMP_OMP_TOOLS_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
484 endif()
485 if(${BUILD_FORTRAN_MODULES})
486   set (destination ${LIBOMP_HEADERS_INSTALL_PATH})
487   if (NOT ${LIBOMP_MODULES_INSTALL_PATH} STREQUAL "")
488     set (destination ${LIBOMP_MODULES_INSTALL_PATH})
489   endif()
490   install(FILES
491     ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.h
492     ${CMAKE_CURRENT_BINARY_DIR}/omp_lib.mod
493     ${CMAKE_CURRENT_BINARY_DIR}/omp_lib_kinds.mod
494     DESTINATION ${destination}
495   )
496 endif()