Index: llvm/trunk/test/tools/llvm-config/booleans.test =================================================================== --- llvm/trunk/test/tools/llvm-config/booleans.test +++ llvm/trunk/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 Index: llvm/trunk/tools/llvm-config/BuildVariables.inc.in =================================================================== --- llvm/trunk/tools/llvm-config/BuildVariables.inc.in +++ llvm/trunk/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@ Index: llvm/trunk/tools/llvm-config/CMakeLists.txt =================================================================== --- llvm/trunk/tools/llvm-config/CMakeLists.txt +++ llvm/trunk/tools/llvm-config/CMakeLists.txt @@ -47,12 +47,13 @@ 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). Index: llvm/trunk/tools/llvm-config/llvm-config.cpp =================================================================== --- llvm/trunk/tools/llvm-config/llvm-config.cpp +++ llvm/trunk/tools/llvm-config/llvm-config.cpp @@ -212,7 +212,7 @@ --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 @@ 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 @@ // 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 @@ } 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") {