[SDAG] Generalize FSINCOS type legalization (NFC) (#116848)
[llvm-project.git] / flang / cmake / modules / AddFlang.cmake
blob9ed1a3050b7e8636cccc514d4b00a4895205dfbe
1 include(GNUInstallDirs)
2 include(LLVMDistributionSupport)
4 macro(set_flang_windows_version_resource_properties name)
5   if (DEFINED windows_resource_file)
6     set_windows_version_resource_properties(${name} ${windows_resource_file}
7       VERSION_MAJOR ${FLANG_VERSION_MAJOR}
8       VERSION_MINOR ${FLANG_VERSION_MINOR}
9       VERSION_PATCHLEVEL ${FLANG_VERSION_PATCHLEVEL}
10       VERSION_STRING "${FLANG_VERSION}"
11       PRODUCT_NAME "flang")
12   endif()
13 endmacro()
15 macro(add_flang_subdirectory name)
16   add_llvm_subdirectory(FLANG TOOL ${name})
17 endmacro()
19 function(add_flang_library name)
20   set(options SHARED STATIC INSTALL_WITH_TOOLCHAIN)
21   set(multiValueArgs ADDITIONAL_HEADERS CLANG_LIBS)
22   cmake_parse_arguments(ARG
23     "${options}"
24     ""
25     "${multiValueArgs}"
26     ${ARGN})
28   set(srcs)
29   if (MSVC_IDE OR XCODE)
30     # Add public headers
31     file(RELATIVE_PATH lib_path
32       ${FLANG_SOURCE_DIR}/lib/
33       ${CMAKE_CURRENT_SOURCE_DIR})
34     if(NOT lib_path MATCHES "^[.][.]")
35       file( GLOB_RECURSE headers
36         ${FLANG_SOURCE_DIR}/include/flang/${lib_path}/*.h
37         ${FLANG_SOURCE_DIR}/include/flang/${lib_path}/*.def)
38       set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON)
40       if (headers)
41         set(srcs ${headers})
42       endif()
43     endif()
44   endif(MSVC_IDE OR XCODE)
46   if (srcs OR ARG_ADDITIONAL_HEADERS)
47     set(srcs
48       ADDITIONAL_HEADERS
49       ${srcs}
50       ${ARG_ADDITIONAL_HEADERS}) # It may contain unparsed unknown args.
51       
52   endif()
54   if(ARG_SHARED AND ARG_STATIC)
55     set(LIBTYPE SHARED STATIC)
56   elseif(ARG_SHARED)
57     set(LIBTYPE SHARED)
58   elseif(ARG_STATIC)
59     # If BUILD_SHARED_LIBS and ARG_STATIC are both set, llvm_add_library prioritizes STATIC.
60     # This is required behavior for libFortranFloat128Math.
61     set(LIBTYPE STATIC)
62   else()
63     # Let llvm_add_library decide, taking BUILD_SHARED_LIBS into account.
64     set(LIBTYPE)
65   endif()
66   llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
68   clang_target_link_libraries(${name} PRIVATE ${ARG_CLANG_LIBS})
70   if (TARGET ${name})
72     if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libflang"
73         OR ARG_INSTALL_WITH_TOOLCHAIN)
74       get_target_export_arg(${name} Flang export_to_flangtargets UMBRELLA flang-libraries)
75       install(TARGETS ${name}
76         COMPONENT ${name}
77         ${export_to_flangtargets}
78         LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
79         ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
80         RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
82       if (NOT LLVM_ENABLE_IDE)
83         add_llvm_install_targets(install-${name}
84                                  DEPENDS ${name}
85                                  COMPONENT ${name})
86       endif()
88       set_property(GLOBAL APPEND PROPERTY FLANG_LIBS ${name})
89     endif()
90     set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
91   else()
92     # Add empty "phony" target
93     add_custom_target(${name})
94   endif()
96   set_target_properties(${name} PROPERTIES FOLDER "Flang/Libraries")
97   set_flang_windows_version_resource_properties(${name})
98 endfunction(add_flang_library)
100 macro(add_flang_executable name)
101   add_llvm_executable(${name} ${ARGN})
102   set_flang_windows_version_resource_properties(${name})
103 endmacro(add_flang_executable)
105 macro(add_flang_tool name)
106   if (NOT FLANG_BUILD_TOOLS)
107     set(EXCLUDE_FROM_ALL ON)
108   endif()
110   add_flang_executable(${name} ${ARGN})
112   if (FLANG_BUILD_TOOLS)
113     get_target_export_arg(${name} Flang export_to_flangtargets)
114     install(TARGETS ${name}
115       ${export_to_flangtargets}
116       RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
117       COMPONENT ${name})
119     if(NOT LLVM_ENABLE_IDE)
120       add_llvm_install_targets(install-${name}
121                                DEPENDS ${name}
122                                COMPONENT ${name})
123     endif()
124     set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
125   endif()
126 endmacro()
128 macro(add_flang_symlink name dest)
129   llvm_add_tool_symlink(FLANG ${name} ${dest} ALWAYS_GENERATE)
130   # Always generate install targets
131   llvm_install_symlink(FLANG ${name} ${dest} ALWAYS_GENERATE)
132 endmacro()