From 1c1c6b98f637ff5f4f1e8591b95304a43739ef7d Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Fri, 6 Apr 2012 15:43:20 +0000 Subject: [PATCH] #645 Added cv::getBuildInformation function (with sample) to get OpenCV build configuration --- CMakeLists.txt | 9 ++++++--- cmake/OpenCVUtils.cmake | 22 ++++++++++++++++------ modules/core/CMakeLists.txt | 11 +++++++---- modules/core/include/opencv2/core/core.hpp | 2 ++ modules/core/src/system.cpp | 8 ++++++++ samples/cpp/opencv_version.cpp | 28 ++++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 samples/cpp/opencv_version.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d4d1db0..864c1bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -667,9 +667,12 @@ endif() status("") status(" C++:") status(" Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO) -status(" C++ Compiler:" CMAKE_COMPILER THEN "${CMAKE_COMPILER}" ELSE "${CMAKE_CXX_COMPILER}") +status(" C++ Compiler:" ${CMAKE_CXX_COMPILER}) status(" C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}) status(" C++ flags (Debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}) +status(" C Compiler:" ${CMAKE_C_COMPILER}) +status(" C flags (Release):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}) +status(" C flags (Debug):" ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}) if(WIN32) status(" Linker flags (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE}) status(" Linker flags (Debug):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG}) @@ -770,7 +773,7 @@ else() status(" JPEG 2000:" "NO") endif() -status(" OpenEXR:" WITH_OPENEXR AND OPENEXR_FOUND THEN YES ELSE NO) +status(" OpenEXR:" WITH_OPENEXR AND OPENEXR_FOUND THEN ${OPENEXR_LIBRARIES} ELSE NO) status(" OpenNI:" HAVE_OPENNI THEN YES ELSE NO) status(" OpenNI PrimeSensor Modules:" HAVE_OPENNI_PRIME_SENSOR_MODULE THEN YES ELSE NO) @@ -814,7 +817,7 @@ elseif(APPLE) status(" Video I/O: AVFoundation") endif() elseif(WIN32) - status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO) + status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO) endif() # Other third-party libraries diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index ab6bb05..7b67487 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -104,6 +104,16 @@ macro(CHECK_MODULE module_name define) endmacro() +set(OPENCV_BUILD_INFO_FILE "${OpenCV_BINARY_DIR}/version_string.tmp") +file(REMOVE "${OPENCV_BUILD_INFO_FILE}") +function(ocv_output_status msg) + message(STATUS "${msg}") + if(msg MATCHES "\"") + string(REPLACE "\"" "\\\"" msg "${msg}") + endif() + file(APPEND "${OPENCV_BUILD_INFO_FILE}" "\"${msg}\\n\"\n") +endfunction() + # Status report function. # Automatically align right column and selects text based on condition. # Usage: @@ -133,7 +143,7 @@ function(status text) if(status_text_length LESS status_placeholder_length) string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text) elseif(DEFINED status_then OR DEFINED status_else) - message(STATUS "${text}") + ocv_output_status("${text}") set(status_text "${status_placeholder}") else() set(status_text "${text}") @@ -142,17 +152,17 @@ function(status text) if(DEFINED status_then OR DEFINED status_else) if(${status_cond}) string(REPLACE ";" " " status_then "${status_then}") - message(STATUS "${status_text}" "${status_then}") + ocv_output_status("${status_text} ${status_then}") else() string(REPLACE ";" " " status_else "${status_else}") - message(STATUS "${status_text}" "${status_else}") + ocv_output_status("${status_text} ${status_else}") endif() else() string(REPLACE ";" " " status_cond "${status_cond}") - message(STATUS "${status_text}" "${status_cond}") + ocv_output_status("${status_text} ${status_cond}") endif() else() - message(STATUS "${text}") + ocv_output_status("${text}") endif() endfunction() @@ -265,4 +275,4 @@ macro(ocv_to_full_paths VAR) set(${VAR} ${__tmp}) unset(__tmp) endif() -endmacro() \ No newline at end of file +endmacro() diff --git a/modules/core/CMakeLists.txt b/modules/core/CMakeLists.txt index 87d2044..3f321b6 100644 --- a/modules/core/CMakeLists.txt +++ b/modules/core/CMakeLists.txt @@ -16,7 +16,13 @@ else() set(cuda_link_libs "") endif() -ocv_glob_module_sources(SOURCES ${lib_cuda} ${cuda_objs}) +set(OPENCV_VERSION_FILE "${opencv_core_BINARY_DIR}/version_string.inc") +add_custom_command(OUTPUT "${OPENCV_VERSION_FILE}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENCV_BUILD_INFO_FILE}" "${OPENCV_VERSION_FILE}" + MAIN_DEPENDENCY "${OPENCV_BUILD_INFO_FILE}" + COMMENT "") + +ocv_glob_module_sources(SOURCES ${lib_cuda} ${cuda_objs} "${OPENCV_VERSION_FILE}") ocv_create_module(${cuda_link_libs}) ocv_add_precompiled_headers(${the_module}) @@ -24,6 +30,3 @@ ocv_add_precompiled_headers(${the_module}) ocv_add_accuracy_tests() ocv_add_perf_tests() - - - diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 555c2b3..525d8de 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -218,6 +218,8 @@ CV_EXPORTS void setNumThreads(int nthreads); CV_EXPORTS int getNumThreads(); CV_EXPORTS int getThreadNum(); +CV_EXPORTS_W const std::string& getBuildInformation(); + //! Returns the number of ticks. /*! diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index e0c1eb9..3d337cf 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -410,6 +410,14 @@ int getNumberOfCPUs(void) #endif } +const std::string& getBuildInformation() +{ + static std::string build_info = +#include "version_string.inc" + ; + return build_info; +} + string format( const char* fmt, ... ) { char buf[1 << 16]; diff --git a/samples/cpp/opencv_version.cpp b/samples/cpp/opencv_version.cpp new file mode 100644 index 0000000..5eb4bcc --- /dev/null +++ b/samples/cpp/opencv_version.cpp @@ -0,0 +1,28 @@ +#include "opencv2/core/core.hpp" +#include + +const char* keys = +{ + "{ b |build |false | print complete build info }" + "{ h |help |false | print this help }" +}; + +int main(int argc, const char* argv[]) +{ + cv::CommandLineParser parser(argc, argv, keys); + + if (parser.get("help")) + { + parser.printParams(); + } + else if (parser.get("build")) + { + std::cout << cv::getBuildInformation() << std::endl; + } + else + { + std::cout << "OpenCV " << CV_VERSION << std::endl; + } + + return 0; +} \ No newline at end of file -- 2.7.4