Skip to content

Commit cde06f7

Browse files
author
Serge Guelton
committed
[flang] Make flang build compatible with LLVM dylib
Harmonize usage of LLVM components througout Flang. Explicit LLVM Libs where used across several CMakeFIles, which led to incompatibilities with LLVM shlibs. Fortunately, the LLVM component system can be relied on to harmoniously handle both cases. Differential Revision: https://reviews.llvm.org/D87893
1 parent 82a7182 commit cde06f7

File tree

7 files changed

+41
-41
lines changed

7 files changed

+41
-41
lines changed

flang/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,8 @@ if(LINK_WITH_FIR)
229229
endif()
230230
# Always build tco tool
231231
set(LLVM_BUILD_TOOLS ON)
232-
message(STATUS "Linking driver with FIR and LLVM")
233-
llvm_map_components_to_libnames(LLVM_COMMON_LIBS support)
234-
message(STATUS "LLVM libraries: ${LLVM_COMMON_LIBS}")
232+
set(LLVM_COMMON_COMPONENTS Support)
233+
message(STATUS "Linking driver with FIR and LLVM, using LLVM components: ${LLVM_COMMON_COMPONENTS}")
235234
endif()
236235

237236
# Add Flang-centric modules to cmake path.

flang/cmake/modules/AddFlang.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ macro(add_flang_library name)
6161
llvm_add_library(${name} ${LIBTYPE} ${ARG_UNPARSED_ARGUMENTS} ${srcs})
6262

6363
if (TARGET ${name})
64-
target_link_libraries(${name} INTERFACE ${LLVM_COMMON_LIBS})
6564

6665
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "libflang")
6766
set(export_to_flangtargets)

flang/tools/flang-driver/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ link_directories(${LLVM_LIBRARY_DIR})
77
add_flang_tool(flang-new
88
driver.cpp
99
fc1_main.cpp
10+
11+
LINK_COMPONENTS
12+
13+
${LLVM_COMMON_COMPONENTS}
14+
Support
15+
Target
16+
Option
1017
)
1118

1219
# Link against LLVM and Clang libraries
1320
target_link_libraries(flang-new
1421
PRIVATE
15-
${LLVM_COMMON_LIBS}
1622
flangFrontend
1723
flangFrontendTool
1824
clangDriver
1925
clangBasic
2026
clangFrontend
21-
LLVMSupport
22-
LLVMTarget
23-
LLVMOption
2427
)
2528

2629
install(TARGETS flang-new DESTINATION bin)

flang/unittests/CMakeLists.txt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,30 @@ if (CXX_SUPPORTS_SUGGEST_OVERRIDE_FLAG)
1010
endif()
1111

1212
function(add_flang_nongtest_unittest test_name)
13-
add_executable(${test_name}.test ${test_name}.cpp)
13+
cmake_parse_arguments(ARG
14+
"SLOW_TEST"
15+
""
16+
""
17+
${ARGN})
1418

15-
target_link_libraries(${test_name}.test ${ARGN})
19+
if(ARG_SLOW_TEST)
20+
set(suffix .slow)
21+
else()
22+
set(suffix .test)
23+
endif()
1624

17-
add_dependencies(FlangUnitTests ${test_name}.test)
25+
add_executable(${test_name}${suffix} ${test_name}.cpp)
26+
27+
if (LLVM_LINK_LLVM_DYLIB AND NOT ARG_DISABLE_LLVM_LINK_LLVM_DYLIB)
28+
set(llvm_libs LLVM)
29+
else()
30+
llvm_map_components_to_libnames(llvm_libs Support)
31+
endif()
32+
target_link_libraries(${test_name}${suffix} ${llvm_libs} ${ARG_UNPARSED_ARGUMENTS})
33+
34+
if(NOT ARG_SLOW_TEST)
35+
add_dependencies(FlangUnitTests ${test_name}${suffix})
36+
endif()
1837
endfunction()
1938

2039
add_subdirectory(Optimizer)
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
22
add_flang_nongtest_unittest(quick-sanity-test
33
FortranDecimal
4-
LLVMSupport
54
)
65

7-
# This test is not run by default as it takes a long time to execute
8-
add_executable(thorough-test
9-
thorough-test.cpp
10-
)
11-
12-
target_link_libraries(thorough-test
6+
# This test is not run by default as it takes a long time to execute.
7+
add_flang_nongtest_unittest(thorough-test
8+
SLOW_TEST
139
FortranDecimal
14-
LLVMSupport
1510
)

flang/unittests/Evaluate/CMakeLists.txt

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ add_library(FortranEvaluateTesting
33
testing.cpp
44
fp-testing.cpp
55
)
6-
7-
target_link_libraries(FortranEvaluateTesting
8-
LLVMSupport
9-
)
6+
if (LLVM_LINK_LLVM_DYLIB)
7+
set(llvm_libs LLVM)
8+
else()
9+
llvm_map_components_to_libnames(llvm_libs Support)
10+
endif()
11+
target_link_libraries(FortranEvaluateTesting
12+
${llvm_libs})
1013

1114
add_flang_nongtest_unittest(leading-zero-bit-count
1215
FortranEvaluateTesting
13-
LLVMSupport
1416
)
1517

1618
add_flang_nongtest_unittest(bit-population-count
1719
FortranEvaluateTesting
18-
LLVMSupport
1920
)
2021

2122
add_flang_nongtest_unittest(uint128
2223
FortranEvaluateTesting
23-
LLVMSupport
2424
)
2525

2626
add_flang_nongtest_unittest(expression
@@ -29,14 +29,12 @@ add_flang_nongtest_unittest(expression
2929
FortranEvaluate
3030
FortranSemantics
3131
FortranParser
32-
LLVMSupport
3332
)
3433

3534
add_flang_nongtest_unittest(integer
3635
FortranEvaluateTesting
3736
FortranEvaluate
3837
FortranSemantics
39-
LLVMSupport
4038
)
4139

4240
add_flang_nongtest_unittest(intrinsics
@@ -47,14 +45,12 @@ add_flang_nongtest_unittest(intrinsics
4745
FortranSemantics
4846
FortranParser
4947
FortranRuntime
50-
LLVMSupport
5148
)
5249

5350
add_flang_nongtest_unittest(logical
5451
FortranEvaluateTesting
5552
FortranEvaluate
5653
FortranSemantics
57-
LLVMSupport
5854
)
5955

6056
# GCC -fno-exceptions breaks the fenv.h interfaces needed to capture
@@ -68,7 +64,6 @@ add_flang_nongtest_unittest(real
6864
FortranEvaluate
6965
FortranDecimal
7066
FortranSemantics
71-
LLVMSupport
7267
)
7368
llvm_update_compile_flags(real.test)
7469

@@ -77,21 +72,18 @@ add_flang_nongtest_unittest(reshape
7772
FortranSemantics
7873
FortranEvaluate
7974
FortranRuntime
80-
LLVMSupport
8175
)
8276

8377
add_flang_nongtest_unittest(ISO-Fortran-binding
8478
FortranEvaluateTesting
8579
FortranEvaluate
8680
FortranSemantics
8781
FortranRuntime
88-
LLVMSupport
8982
)
9083

9184
add_flang_nongtest_unittest(folding
9285
FortranCommon
9386
FortranEvaluateTesting
9487
FortranEvaluate
9588
FortranSemantics
96-
LLVMSupport
9789
)

flang/unittests/Runtime/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,16 @@ llvm_update_compile_flags(RuntimeTesting)
1010

1111
target_link_libraries(RuntimeTesting
1212
FortranRuntime
13-
LLVMSupport
1413
)
1514

1615
add_flang_nongtest_unittest(format
1716
RuntimeTesting
1817
FortranRuntime
19-
LLVMSupport
2018
)
2119

2220
add_flang_nongtest_unittest(hello
2321
RuntimeTesting
2422
FortranRuntime
25-
LLVMSupport
2623
)
2724

2825
# This test is not run by default as it requires input.
@@ -32,23 +29,19 @@ add_executable(external-hello-world
3229

3330
target_link_libraries(external-hello-world
3431
FortranRuntime
35-
LLVMSupport
3632
)
3733

3834
add_flang_nongtest_unittest(external-io
3935
RuntimeTesting
4036
FortranRuntime
41-
LLVMSupport
4237
)
4338

4439
add_flang_nongtest_unittest(list-input
4540
RuntimeTesting
4641
FortranRuntime
47-
LLVMSupport
4842
)
4943

5044
add_flang_nongtest_unittest(character
5145
RuntimeTesting
5246
FortranRuntime
53-
LLVMSupport
5447
)

0 commit comments

Comments
 (0)