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}"
15 macro(add_flang_subdirectory name)
16 add_llvm_subdirectory(FLANG TOOL ${name})
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
29 if (MSVC_IDE OR XCODE)
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)
44 endif(MSVC_IDE OR XCODE)
46 if (srcs OR ARG_ADDITIONAL_HEADERS)
50 ${ARG_ADDITIONAL_HEADERS}) # It may contain unparsed unknown args.
54 if(ARG_SHARED AND ARG_STATIC)
55 set(LIBTYPE SHARED STATIC)
59 # If BUILD_SHARED_LIBS and ARG_STATIC are both set, llvm_add_library prioritizes STATIC.
60 # This is required behavior for libFortranFloat128Math.
63 # Let llvm_add_library decide, taking BUILD_SHARED_LIBS into account.
66 llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
68 clang_target_link_libraries(${name} PRIVATE ${ARG_CLANG_LIBS})
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}
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}
88 set_property(GLOBAL APPEND PROPERTY FLANG_LIBS ${name})
90 set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
92 # Add empty "phony" target
93 add_custom_target(${name})
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)
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}"
119 if(NOT LLVM_ENABLE_IDE)
120 add_llvm_install_targets(install-${name}
124 set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
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)