@@ -38,42 +38,124 @@ function (add_flangrt_library name)
3838 ${ARGN} )
3939
4040 if (ARG_INSTALL_WITH_TOOLCHAIN AND ARG_EXCLUDE_FROM_ALL)
41- message (SEND_ERROR "add_flangrt_library(${name} ...):
41+ message (SEND_ERROR "add_flangrt_library(${name} ...):
4242 INSTALL_WITH_TOOLCHAIN and EXCLUDE_FROM_ALL are in conflict. When
4343 installing an artifact it must have been built first in the 'all' target.
44- " )
44+ " )
45+ return ()
4546 endif ()
4647
47- # Also add header files to IDEs to list as part of the library
48- set_source_files_properties (${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON )
48+ #if (ARG_CMAKE_CONFIGURABLE AND (ARG_STATIC OR ARG_SHARED))
49+ # message(SEND_ERROR "add_flangrt_library(${name} ...):
50+ # CMAKE_CONFIGURABLE cannot be used together with STATIC or SHARED.
51+ # ")
52+ # return ()
53+ #endif ()
54+
55+ #if (NOT ARG_STATIC AND NOT ARG_SHARED AND NOT ARG_CMAKE_CONFIGURABLE AND NOT ARG_OBJECT)
56+ # message(SEND_ERROR "add_flangrt_library(${name} ...):
57+ # Must specifiy library type.
58+ # ")
59+ # return ()
60+ #endif ()
61+
62+ set (build_static OFF )
63+ set (build_shared OFF )
64+ if (ARG_STATIC AND FLANG_RT_ENABLE_STATIC)
65+ set (build_static ON )
66+ endif ()
67+ if (ARG_SHARED AND FLANG_RT_ENABLE_SHARED)
68+ set (build_shared ON )
69+ endif ()
70+ if (NOT ARG_STATIC AND NOT ARG_SHARED AND NOT ARG_OBJECT)
71+ if (BUILD_SHARED_LIBS )
72+ set (build_shared ON )
73+ else ()
74+ set (build_static ON )
75+ endif ()
76+ endif ()
4977
50- # Forward libtype to add_library
51- set (extra_args "" )
52- if (ARG_SHARED)
53- list (APPEND extra_args SHARED)
78+ # Name of targets must only depend on function arguments to be predictable for callers.
79+ if (ARG_STATIC AND ARG_SHARED)
80+ set (name_static "${name} .static" )
81+ set (name_shared "${name} .shared" )
82+ else ()
83+ set (name_static "${name} " )
84+ set (name_shared "${name} " )
5485 endif ()
55- if (ARG_STATIC)
56- list (APPEND extra_args STATIC )
86+ if (ARG_OBJECT AND NOT ARG_STATIC AND NOT ARG_SHARED)
87+ set (name_object "${name} " )
88+ else ()
89+ set (name_object "obj.${name} " )
5790 endif ()
58- if (ARG_OBJECT)
59- list (APPEND extra_args OBJECT)
91+
92+
93+ if (ARG_OBJECT AND NOT build_static AND NOT build_shared)
94+ set (build_only_objectlib ON )
95+ else ()
96+ set (build_only_objectlib OFF )
6097 endif ()
98+ if (build_only_objectlib OR (build_static AND build_shared))
99+ set (need_objectlib ON )
100+ else ()
101+ set (need_objectlib OFF )
102+ endif ()
103+
104+ if (NOT build_static AND NOT build_shared AND NOT need_objectlib)
105+ # Nothing to build
106+ return ()
107+ endif ()
108+
109+ # Also add header files to IDEs to list as part of the library
110+ set_source_files_properties (${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON )
111+
112+ set (extra_args "" )
61113 if (ARG_EXCLUDE_FROM_ALL)
62114 list (APPEND extra_args EXCLUDE_FROM_ALL )
63115 endif ()
64116
65- add_library (${name} ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS} )
66117
67- if (ARG_INSTALL_WITH_TOOLCHAIN)
68- set_target_properties (${name} PROPERTIES FOLDER "Flang-RT/Toolchain Libraries" )
69- elseif (ARG_OBJECT)
70- set_target_properties (${name} PROPERTIES FOLDER "Flang-RT/Object Libraries" )
118+ if (need_objectlib)
119+ add_library (${name_object} OBJECT ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS} )
120+ set_target_properties (${name_object} PROPERTIES FOLDER "Flang-RT/Object Libraries" )
121+
122+ # Replace arguments for the libraries we are going to create
123+ set (ARG_ADDITIONAL_HEADERS "" )
124+ set (ARG_UNPARSED_ARGUMENTS $<TARGET_OBJECTS:${objectlib_name} >)
125+ set (srctargets ${name_object} )
126+ set (liblist nostargets)
127+ set (alltargets ${name_object} )
71128 else ()
72- set_target_properties (${name} PROPERTIES FOLDER "Flang-RT/Libraries" )
129+ set (liblist srctargets)
130+ set (alltargets)
131+ endif ()
132+
133+ set (libtargets "" )
134+ if (build_static)
135+ add_library (${name_static} STATIC ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS} )
136+ list (APPEND alltargets ${name_static} )
137+ list (APPEND libtargets ${name_static} )
138+ list (APPEND ${liblist} ${name_static} )
73139 endif ()
140+ if (build_shared)
141+ add_library (${name_shared} SHARED ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS} )
142+ list (APPEND alltargets ${name_shared} )
143+ list (APPEND libtargets ${name_shared} )
144+ list (APPEND ${liblist} ${name_shared} )
145+ endif ()
146+
147+ foreach (name IN LISTS libtargets)
148+ if (ARG_INSTALL_WITH_TOOLCHAIN)
149+ set_target_properties (${name} PROPERTIES FOLDER "Flang-RT/Toolchain Libraries" )
150+ else ()
151+ set_target_properties (${name} PROPERTIES FOLDER "Flang-RT/Libraries" )
152+ endif ()
153+ endforeach ()
154+
155+ foreach (name IN LISTS alltargets)
156+ # Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
157+ target_compile_features (${name} PRIVATE cxx_std_17)
74158
75- # Minimum required C++ version for Flang-RT, even if CMAKE_CXX_STANDARD is defined to something else.
76- target_compile_features (${name} PRIVATE cxx_std_17)
77159
78160 # Use compiler-specific options to disable exceptions and RTTI.
79161 if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
@@ -163,4 +245,5 @@ function (add_flangrt_library name)
163245 if (NOT ARG_EXCLUDE_FROM_ALL)
164246 add_dependencies (flang-rt ${name} )
165247 endif ()
248+ endforeach ()
166249endfunction (add_flangrt_library)
0 commit comments