llvm.org GIT mirror llvm / 71b8698
[llvm-config] Canonicalize CMake booleans to 0/1 Following the similar change to lit configuration, ensure that all CMake booleans are canonicalized to 0/1 when being passed to llvm-config. This fixes the incorrect interpretation of values when user passes another value than the ON/OFF, and simplifies the code by removing unnecessary string matching. Furthermore, the code for --has-rtti and --has-global-isel has been modified to print consistent values indepdently of the boolean used by passed by the user to CMake. Sadly, the code already implicitly used different values for the two (YES/NO for --has-rtti, ON/OFF for --has-global-isel). Include tests for all booleans and multi-value options in llvm-config. Differential Revision: https://reviews.llvm.org/D28366 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291593 91177308-0d34-0410-b5e6-96231b3b80d8 Michal Gorny 2 years ago
4 changed file(s) with 45 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
0 # Check whether boolean options are consistently normalized to ON/OFF.
1 RUN: llvm-config --assertion-mode 2>&1 | FileCheck --check-prefix=CHECK-ONOFF %s
2 RUN: llvm-config --has-global-isel 2>&1 | FileCheck --check-prefix=CHECK-ONOFF %s
3 CHECK-ONOFF: {{ON|OFF}}
4 CHECK-ONOFF-NOT: error:
5 CHECK-ONOFF-NOT: warning
6
7 # ...or to YES/NO.
8 RUN: llvm-config --has-rtti 2>&1 | FileCheck --check-prefix=CHECK-YESNO %s
9 CHECK-YESNO: {{YES|NO}}
10 CHECK-YESNO-NOT: error:
11 CHECK-YESNO-NOT: warning
12
13 # Also check some other multi-choice options.
14 RUN: llvm-config --build-mode 2>&1 | FileCheck --check-prefix=CHECK-BUILD-MODE %s
15 CHECK-BUILD-MODE: {{[Dd][Ee][Bb][Uu][Gg]|[Rr][Ee][Ll][Ee][Aa][Ss][Ee]|[Rr][Ee][Ll][Ww][Ii][Tt][Hh][Dd][Ee][Bb][Ii][Nn][Ff][Oo]|[Mm][Ii][Nn][Ss][Ii][Zz][Ee][Rr][Ee][Ll]}}
16 CHECK-BUILD-MODE-NOT: error:
17 CHECK-BUILD-MODE-NOT: warning
18
19 RUN: llvm-config --build-system 2>&1 | FileCheck --check-prefix=CHECK-BUILD-SYSTEM %s
20 CHECK-BUILD-SYSTEM: cmake
21 CHECK-BUILD-SYSTEM-NOT: error:
22 CHECK-BUILD-SYSTEM-NOT: warning
23
24 RUN: llvm-config --shared-mode 2>&1 | FileCheck --check-prefix=CHECK-SHARED-MODE %s
25 CHECK-SHARED-MODE: {{static|shared}}
26 CHECK-SHARED-MODE-NOT: error:
27 CHECK-SHARED-MODE-NOT: warning
2626 #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
2727 #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
2828 #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
29 #define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@"
30 #define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@"
31 #define LLVM_LINK_DYLIB "@LLVM_LINK_LLVM_DYLIB@"
32 #define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@"
29 #define LLVM_HAS_RTTI @LLVM_HAS_RTTI@
30 #define LLVM_ENABLE_DYLIB @LLVM_BUILD_LLVM_DYLIB@
31 #define LLVM_LINK_DYLIB @LLVM_LINK_LLVM_DYLIB@
32 #define LLVM_ENABLE_SHARED @BUILD_SHARED_LIBS@
3333 #define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@"
3434 #define LLVM_DYLIB_VERSION "@LLVM_DYLIB_VERSION@"
35 #define LLVM_HAS_GLOBAL_ISEL "@LLVM_HAS_GLOBAL_ISEL@"
35 #define LLVM_HAS_GLOBAL_ISEL @LLVM_HAS_GLOBAL_ISEL@
4646 set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
4747 set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
4848 set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
49 if(BUILD_SHARED_LIBS)
50 set(LLVM_ENABLE_SHARED ON)
51 else()
52 set(LLVM_ENABLE_SHARED OFF)
53 endif()
5449 string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
50 llvm_canonicalize_cmake_booleans(
51 LLVM_BUILD_LLVM_DYLIB
52 LLVM_LINK_LLVM_DYLIB
53 LLVM_HAS_RTTI
54 LLVM_HAS_GLOBAL_ISEL
55 BUILD_SHARED_LIBS)
5556 configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
5657
5758 # Set build-time environment(s).
211211 --assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
212212 --build-system Print the build system used to build LLVM (always cmake).\n\
213213 --has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\
214 --has-global-isel Print whether or not LLVM was built with global-isel support (YES or NO).\n\
214 --has-global-isel Print whether or not LLVM was built with global-isel support (ON or OFF).\n\
215215 --shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\
216216 --link-shared Link the components as shared libraries.\n\
217217 --link-static Link the component libraries statically.\n\
382382 StaticPrefix = SharedPrefix = "lib";
383383 }
384384
385 const bool BuiltDyLib = (std::strcmp(LLVM_ENABLE_DYLIB, "ON") == 0);
385 const bool BuiltDyLib = !!LLVM_ENABLE_DYLIB;
386386
387387 /// CMake style shared libs, ie each component is in a shared library.
388 const bool BuiltSharedLibs = std::strcmp(LLVM_ENABLE_SHARED, "ON") == 0;
388 const bool BuiltSharedLibs = !!LLVM_ENABLE_SHARED;
389389
390390 bool DyLibExists = false;
391391 const std::string DyLibName =
394394 // If LLVM_LINK_DYLIB is ON, the single shared library will be returned
395395 // for "--libs", etc, if they exist. This behaviour can be overridden with
396396 // --link-static or --link-shared.
397 bool LinkDyLib = (std::strcmp(LLVM_LINK_DYLIB, "ON") == 0);
397 bool LinkDyLib = !!LLVM_LINK_DYLIB;
398398
399399 if (BuiltDyLib) {
400400 std::string path((SharedDir + DirSep + DyLibName).str());
548548 } else if (Arg == "--build-system") {
549549 OS << LLVM_BUILD_SYSTEM << '\n';
550550 } else if (Arg == "--has-rtti") {
551 OS << LLVM_HAS_RTTI << '\n';
551 OS << (LLVM_HAS_RTTI ? "YES" : "NO") << '\n';
552552 } else if (Arg == "--has-global-isel") {
553 OS << LLVM_HAS_GLOBAL_ISEL << '\n';
553 OS << (LLVM_HAS_GLOBAL_ISEL ? "ON" : "OFF") << '\n';
554554 } else if (Arg == "--shared-mode") {
555555 PrintSharedMode = true;
556556 } else if (Arg == "--obj-root") {