trinity-devel@lists.pearsoncomputing.net

Message: previous - next
Month: February 2014

CMake - get list of ALL variables available to build (take the upper hand)

From: "David C. Rankin" <drankinatty@...>
Date: Mon, 24 Feb 2014 14:57:26 -0600
All,

  I have always been frustrated by not knowing what variables were available to
cmake so that I could intelligently adjust include_directories or
target_link_libraries without pulling my hair out. I have stumbled on two very
different and very useful ways of showing all cmake variables available to your
build. They literally pull back the cmake veil of secrecy... Both are simple:

(1) simply include the following code snippet in any CMakeLists.txt to dump all
variables (both in-use & available) to stdout during the build (then just save
the list to a text file):

# dump all variable names
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
    message(STATUS "${_variableName}=${${_variableName}}")
endforeach()

(2) simply call cmake with 'cmake -LAH' and it will do something similar, but
not quite as complete.

  The outputs are this:

(1) (from an old kde3 install)

-- Could NOT find Threads (missing:  Threads_FOUND)
-- Found KDE3 include dir: /opt/kde3/include
-- Found KDE3 library dir: /opt/kde3/lib64
-- Found KDE3 dcopidl preprocessor: /opt/kde3/bin/dcopidl
-- Found KDE3 dcopidl2cpp preprocessor: /opt/kde3/bin/dcopidl2cpp
-- Found KDE3 kconfig_compiler preprocessor: /opt/kde3/bin/kconfig_compiler
-- CMAKE_AR=/usr/bin/ar
-- CMAKE_BASE_NAME=g++
<snip>
-- KDE3PREFIX=/opt/kde3
-- KDE3_BUILD_TESTS=OFF
-- KDE3_DCOPIDL2CPP_EXECUTABLE=/opt/kde3/bin/dcopidl2cpp
-- KDE3_DCOPIDL_EXECUTABLE=/opt/kde3/bin/dcopidl
--
KDE3_DEFINITIONS=-DQT_CLEAN_NAMESPACE;-D_GNU_SOURCE;-D_XOPEN_SOURCE=500;-D_BSD_SOURCE
-- KDE3_FOUND=TRUE
-- KDE3_INCLUDE_DIR=/opt/kde3/include
-- KDE3_INCLUDE_DIRS=/usr/lib/qt3/include;/opt/kde3/include
-- KDE3_KCFGC_EXECUTABLE=/opt/kde3/bin/kconfig_compiler
-- KDE3_KDECORE_LIBRARY=/opt/kde3/lib64/libkdecore.so
-- KDE3_LIBTOOL_DIR=/lib64/kde3
-- KDE3_LIB_DIR=/opt/kde3/lib64
-- KDE3_MODULE_DIR=/usr/share/cmake/Modules
-- KDECONFIG_EXECUTABLE=/opt/kde3/bin/kde-config
-- PROJECT_BINARY_DIR=/home/david/dev/kde3/tutorial/p1bld
-- PROJECT_NAME=p1
-- PROJECT_SOURCE_DIR=/home/david/dev/kde3/tutorial/p1
-- QGLOBAL_H=#define QT_VERSION_STR   "3.3.8c"
-- QT3_FOUND=TRUE
-- QTVERSION_MOC=
-- QTVERSION_UIC=
--
QT_AND_KDECORE_LIBS=/usr/lib/qt3/lib64/libqassistantclient.a;/usr/lib/qt3/lib64/libqt-mt.so;/usr/lib64/libX11.so;/usr/lib64/libXext.so;dl;/opt/kde3/lib64/libkdecore.so
-- QT_DEFINITIONS=-DQT_SHARED;-DQT_NO_DEBUG;-DQT_THREAD_SUPPORT;-D_REENTRANT
-- QT_FOUND=TRUE
-- QT_INCLUDE_DIR=/usr/lib/qt3/include
--
QT_LIBRARIES=/usr/lib/qt3/lib64/libqassistantclient.a;/usr/lib/qt3/lib64/libqt-mt.so;/usr/lib64/libX11.so;/usr/lib64/libXext.so;dl
-- QT_MOC_EXE=/usr/lib/qt3/bin/moc
-- QT_MOC_EXECUTABLE=/usr/lib/qt3/bin/moc
-- QT_MT_REQUIRED=TRUE
-- QT_QASSISTANTCLIENT_LIBRARY=/usr/lib/qt3/lib64/libqassistantclient.a
-- QT_QTMAIN_LIBRARY=
-- QT_QT_LIBRARY=/usr/lib/qt3/lib64/libqt-mt.so
-- QT_UIC_EXE=/usr/lib/qt3/bin/uic
-- QT_UIC_EXECUTABLE=/usr/lib/qt3/bin/uic
-- QT_VERSION_STRING=3.3.8c
-- QT_WRAP_CPP=FALSE
-- QT_WRAP_UI=FALSE

(2) # cmake -LAH

// Path to a program.
CMAKE_AR:FILEPATH=/usr/bin/ar

// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS
used) Debug Release RelWithDebInfo MinSizeRel.
CMAKE_BUILD_TYPE:STRING=

// Enable/Disable color output during build.
CMAKE_COLOR_MAKEFILE:BOOL=ON

// CXX compiler.
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++

// Flags used by the compiler during all build types.
CMAKE_CXX_FLAGS:STRING=

// Flags used by the compiler during debug builds.
CMAKE_CXX_FLAGS_DEBUG:STRING=-g

// Flags used by the compiler during release minsize builds.
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG

// Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs
will produce slightly less optimized but smaller files).
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG

// Flags used by the compiler during Release with Debug Info builds.
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g

// Flags used by the linker.
CMAKE_EXE_LINKER_FLAGS:STRING=

// Flags used by the linker during debug builds.
CMAKE_EXE_LINKER_FLAGS_DEBUG:STRING=

// Flags used by the linker during release minsize builds.
CMAKE_EXE_LINKER_FLAGS_MINSIZEREL:STRING=

// Flags used by the linker during release builds.
CMAKE_EXE_LINKER_FLAGS_RELEASE:STRING=

// Flags used by the linker during Release with Debug Info builds.
CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO:STRING=

// Enable/Disable output of compile commands during generation.
CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=OFF

// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local

// Path to a program.
CMAKE_LINKER:FILEPATH=/usr/bin/ld

<snip>


-- 
David C. Rankin, J.D.,P.E.