1macro(set_flang_windows_version_resource_properties name)
2  if (DEFINED windows_resource_file)
3    set_windows_version_resource_properties(${name} ${windows_resource_file}
4      VERSION_MAJOR ${FLANG_VERSION_MAJOR}
5      VERSION_MINOR ${FLANG_VERSION_MINOR}
6      VERSION_PATCHLEVEL ${FLANG_VERSION_PATCHLEVEL}
7      VERSION_STRING "${FLANG_VERSION} (${BACKEND_PACKAGE_STRING})"
8      PRODUCT_NAME "flang")
9  endif()
10endmacro()
11
12macro(add_flang_subdirectory name)
13  add_llvm_subdirectory(FLANG TOOL ${name})
14endmacro()
15
16macro(add_flang_library name)
17  cmake_parse_arguments(ARG
18    "SHARED"
19    ""
20    "ADDITIONAL_HEADERS"
21    ${ARGN})
22  set(srcs)
23  if (MSVC_IDE OR XCODE)
24    # Add public headers
25    file(RELATIVE_PATH lib_path
26      ${FLANG_SOURCE_DIR}/lib/
27      ${CMAKE_CURRENT_SOURCE_DIR})
28    if(NOT lib_path MATCHES "^[.][.]")
29      file( GLOB_RECURSE headers
30        ${FLANG_SOURCE_DIR}/include/flang/${lib_path}/*.h
31        ${FLANG_SOURCE_DIR}/include/flang/${lib_path}/*.def)
32      set_source_files_properties(${headers} PROPERTIES HEADER_FILE_ONLY ON)
33
34      if (headers)
35        set(srcs ${headers})
36      endif()
37    endif()
38  endif(MSVC_IDE OR XCODE)
39
40  if (srcs OR ARG_ADDITIONAL_HEADERS)
41    set(srcs
42      ADDITIONAL_HEADERS
43      ${srcs}
44      ${ARG_ADDITIONAL_HEADERS}) # It may contain unparsed unknown args.
45
46  endif()
47
48  if (ARG_SHARED)
49    set(LIBTYPE SHARED)
50  else()
51    # llvm_add_library ignores BUILD_SHARED_LIBS if STATIC is explicitly set,
52    # so we need to handle it here.
53    if (BUILD_SHARED_LIBS)
54      set(LIBTYPE SHARED OBJECT)
55    else()
56      set(LIBTYPE STATIC OBJECT)
57    endif()
58    set_property(GLOBAL APPEND PROPERTY FLANG_STATIC_LIBS ${name})
59  endif()
60
61  llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
62
63  if (TARGET ${name})
64
65    if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libflang")
66      set(export_to_flangtargets)
67      if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
68          "flang-libraries" IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
69          NOT LLVM_DISTRIBUTION_COMPONENTS)
70        set(export_to_flangtargets EXPORT FlangTargets)
71        set_property(GLOBAL PROPERTY FLANG_HAS_EXPORTS True)
72      endif()
73
74      install(TARGETS ${name}
75        COMPONENT ${name}
76        ${export_to_flangtargets}
77        LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
78        ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
79        RUNTIME DESTINATION bin)
80
81      if (NOT LLVM_ENABLE_IDE)
82        add_llvm_install_targets(install-${name}
83                                 DEPENDS ${name}
84                                 COMPONENT ${name})
85      endif()
86
87      set_property(GLOBAL APPEND PROPERTY FLANG_LIBS ${name})
88    endif()
89    set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
90  else()
91    # Add empty "phony" target
92    add_custom_target(${name})
93  endif()
94
95  set_target_properties(${name} PROPERTIES FOLDER "Flang libraries")
96  set_flang_windows_version_resource_properties(${name})
97endmacro(add_flang_library)
98
99macro(add_flang_executable name)
100  add_llvm_executable(${name} ${ARGN})
101  set_target_properties(${name} PROPERTIES FOLDER "Flang executables")
102  set_flang_windows_version_resource_properties(${name})
103endmacro(add_flang_executable)
104
105macro(add_flang_tool name)
106  if (NOT FLANG_BUILD_TOOLS)
107    set(EXCLUDE_FROM_ALL ON)
108  endif()
109
110  add_flang_executable(${name} ${ARGN})
111
112  if (FLANG_BUILD_TOOLS)
113    set(export_to_flangtargets)
114    if (${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR
115        NOT LLVM_DISTRIBUTION_COMPONENTS)
116      set(export_to_flangtargets EXPORT FlangTargets)
117      set_property(GLOBAL PROPERTY FLANG_HAS_EXPORTS True)
118    endif()
119
120    install(TARGETS ${name}
121      ${export_to_flangtargets}
122      RUNTIME DESTINATION bin
123      COMPONENT ${name})
124
125    if(NOT LLVM_ENABLE_IDE)
126      add_llvm_install_targets(install-${name}
127                               DEPENDS ${name}
128                               COMPONENT ${name})
129    endif()
130    set_property(GLOBAL APPEND PROPERTY FLANG_EXPORTS ${name})
131  endif()
132endmacro()
133
134macro(add_flang_symlink name dest)
135  add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE)
136  # Always generate install targets
137  llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE)
138endmacro()
139
140