diff --git a/llvm/test/tools/llvm-config/booleans.test b/llvm/test/tools/llvm-config/booleans.test new file mode 100644 index 000000000000..b28f293666f3 --- /dev/null +++ b/llvm/test/tools/llvm-config/booleans.test @@ -0,0 +1,28 @@ +# Check whether boolean options are consistently normalized to ON/OFF. +RUN: llvm-config --assertion-mode 2>&1 | FileCheck --check-prefix=CHECK-ONOFF %s +RUN: llvm-config --has-global-isel 2>&1 | FileCheck --check-prefix=CHECK-ONOFF %s +CHECK-ONOFF: {{ON|OFF}} +CHECK-ONOFF-NOT: error: +CHECK-ONOFF-NOT: warning + +# ...or to YES/NO. +RUN: llvm-config --has-rtti 2>&1 | FileCheck --check-prefix=CHECK-YESNO %s +CHECK-YESNO: {{YES|NO}} +CHECK-YESNO-NOT: error: +CHECK-YESNO-NOT: warning + +# Also check some other multi-choice options. +RUN: llvm-config --build-mode 2>&1 | FileCheck --check-prefix=CHECK-BUILD-MODE %s +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]}} +CHECK-BUILD-MODE-NOT: error: +CHECK-BUILD-MODE-NOT: warning + +RUN: llvm-config --build-system 2>&1 | FileCheck --check-prefix=CHECK-BUILD-SYSTEM %s +CHECK-BUILD-SYSTEM: cmake +CHECK-BUILD-SYSTEM-NOT: error: +CHECK-BUILD-SYSTEM-NOT: warning + +RUN: llvm-config --shared-mode 2>&1 | FileCheck --check-prefix=CHECK-SHARED-MODE %s +CHECK-SHARED-MODE: {{static|shared}} +CHECK-SHARED-MODE-NOT: error: +CHECK-SHARED-MODE-NOT: warning diff --git a/llvm/tools/llvm-config/BuildVariables.inc.in b/llvm/tools/llvm-config/BuildVariables.inc.in index 709ea35044c6..0740c3f9d9f5 100644 --- a/llvm/tools/llvm-config/BuildVariables.inc.in +++ b/llvm/tools/llvm-config/BuildVariables.inc.in @@ -27,10 +27,10 @@ #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" -#define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@" -#define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@" -#define LLVM_LINK_DYLIB "@LLVM_LINK_LLVM_DYLIB@" -#define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@" +#define LLVM_HAS_RTTI @LLVM_HAS_RTTI@ +#define LLVM_ENABLE_DYLIB @LLVM_BUILD_LLVM_DYLIB@ +#define LLVM_LINK_DYLIB @LLVM_LINK_LLVM_DYLIB@ +#define LLVM_ENABLE_SHARED @BUILD_SHARED_LIBS@ #define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@" #define LLVM_DYLIB_VERSION "@LLVM_DYLIB_VERSION@" -#define LLVM_HAS_GLOBAL_ISEL "@LLVM_HAS_GLOBAL_ISEL@" +#define LLVM_HAS_GLOBAL_ISEL @LLVM_HAS_GLOBAL_ISEL@ diff --git a/llvm/tools/llvm-config/CMakeLists.txt b/llvm/tools/llvm-config/CMakeLists.txt index 1f5db59beb50..5112648ea731 100644 --- a/llvm/tools/llvm-config/CMakeLists.txt +++ b/llvm/tools/llvm-config/CMakeLists.txt @@ -47,12 +47,13 @@ endif() set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}") set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE}) set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS}) -if(BUILD_SHARED_LIBS) - set(LLVM_ENABLE_SHARED ON) -else() - set(LLVM_ENABLE_SHARED OFF) -endif() string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}") +llvm_canonicalize_cmake_booleans( + LLVM_BUILD_LLVM_DYLIB + LLVM_LINK_LLVM_DYLIB + LLVM_HAS_RTTI + LLVM_HAS_GLOBAL_ISEL + BUILD_SHARED_LIBS) configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY) # Set build-time environment(s). diff --git a/llvm/tools/llvm-config/llvm-config.cpp b/llvm/tools/llvm-config/llvm-config.cpp index e8afcbaaf485..529824534334 100644 --- a/llvm/tools/llvm-config/llvm-config.cpp +++ b/llvm/tools/llvm-config/llvm-config.cpp @@ -212,7 +212,7 @@ Options:\n\ --assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\ --build-system Print the build system used to build LLVM (always cmake).\n\ --has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\ - --has-global-isel Print whether or not LLVM was built with global-isel support (YES or NO).\n\ + --has-global-isel Print whether or not LLVM was built with global-isel support (ON or OFF).\n\ --shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\ --link-shared Link the components as shared libraries.\n\ --link-static Link the component libraries statically.\n\ @@ -383,10 +383,10 @@ int main(int argc, char **argv) { StaticPrefix = SharedPrefix = "lib"; } - const bool BuiltDyLib = (std::strcmp(LLVM_ENABLE_DYLIB, "ON") == 0); + const bool BuiltDyLib = !!LLVM_ENABLE_DYLIB; /// CMake style shared libs, ie each component is in a shared library. - const bool BuiltSharedLibs = std::strcmp(LLVM_ENABLE_SHARED, "ON") == 0; + const bool BuiltSharedLibs = !!LLVM_ENABLE_SHARED; bool DyLibExists = false; const std::string DyLibName = @@ -395,7 +395,7 @@ int main(int argc, char **argv) { // If LLVM_LINK_DYLIB is ON, the single shared library will be returned // for "--libs", etc, if they exist. This behaviour can be overridden with // --link-static or --link-shared. - bool LinkDyLib = (std::strcmp(LLVM_LINK_DYLIB, "ON") == 0); + bool LinkDyLib = !!LLVM_LINK_DYLIB; if (BuiltDyLib) { std::string path((SharedDir + DirSep + DyLibName).str()); @@ -549,9 +549,9 @@ int main(int argc, char **argv) { } else if (Arg == "--build-system") { OS << LLVM_BUILD_SYSTEM << '\n'; } else if (Arg == "--has-rtti") { - OS << LLVM_HAS_RTTI << '\n'; + OS << (LLVM_HAS_RTTI ? "YES" : "NO") << '\n'; } else if (Arg == "--has-global-isel") { - OS << LLVM_HAS_GLOBAL_ISEL << '\n'; + OS << (LLVM_HAS_GLOBAL_ISEL ? "ON" : "OFF") << '\n'; } else if (Arg == "--shared-mode") { PrintSharedMode = true; } else if (Arg == "--obj-root") {