#645 Added cv::getBuildInformation function (with sample) to get OpenCV build configuration

This commit is contained in:
Andrey Kamaev 2012-04-06 15:43:20 +00:00
parent 89338a38af
commit 1c1c6b98f6
6 changed files with 67 additions and 13 deletions

View File

@ -667,9 +667,12 @@ endif()
status("") status("")
status(" C++:") status(" C++:")
status(" Built as dynamic libs?:" BUILD_SHARED_LIBS THEN YES ELSE NO) 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 (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
status(" C++ flags (Debug):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}) 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) if(WIN32)
status(" Linker flags (Release):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_RELEASE}) 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}) status(" Linker flags (Debug):" ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
@ -770,7 +773,7 @@ else()
status(" JPEG 2000:" "NO") status(" JPEG 2000:" "NO")
endif() 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:" HAVE_OPENNI THEN YES ELSE NO)
status(" OpenNI PrimeSensor Modules:" status(" OpenNI PrimeSensor Modules:"
HAVE_OPENNI_PRIME_SENSOR_MODULE THEN YES ELSE NO) HAVE_OPENNI_PRIME_SENSOR_MODULE THEN YES ELSE NO)
@ -814,7 +817,7 @@ elseif(APPLE)
status(" Video I/O: AVFoundation") status(" Video I/O: AVFoundation")
endif() endif()
elseif(WIN32) elseif(WIN32)
status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO) status(" Video I/O:" HAVE_VIDEOINPUT THEN DirectShow ELSE NO)
endif() endif()
# Other third-party libraries # Other third-party libraries

View File

@ -104,6 +104,16 @@ macro(CHECK_MODULE module_name define)
endmacro() 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. # Status report function.
# Automatically align right column and selects text based on condition. # Automatically align right column and selects text based on condition.
# Usage: # Usage:
@ -133,7 +143,7 @@ function(status text)
if(status_text_length LESS status_placeholder_length) if(status_text_length LESS status_placeholder_length)
string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text) string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text)
elseif(DEFINED status_then OR DEFINED status_else) elseif(DEFINED status_then OR DEFINED status_else)
message(STATUS "${text}") ocv_output_status("${text}")
set(status_text "${status_placeholder}") set(status_text "${status_placeholder}")
else() else()
set(status_text "${text}") set(status_text "${text}")
@ -142,17 +152,17 @@ function(status text)
if(DEFINED status_then OR DEFINED status_else) if(DEFINED status_then OR DEFINED status_else)
if(${status_cond}) if(${status_cond})
string(REPLACE ";" " " status_then "${status_then}") string(REPLACE ";" " " status_then "${status_then}")
message(STATUS "${status_text}" "${status_then}") ocv_output_status("${status_text} ${status_then}")
else() else()
string(REPLACE ";" " " status_else "${status_else}") string(REPLACE ";" " " status_else "${status_else}")
message(STATUS "${status_text}" "${status_else}") ocv_output_status("${status_text} ${status_else}")
endif() endif()
else() else()
string(REPLACE ";" " " status_cond "${status_cond}") string(REPLACE ";" " " status_cond "${status_cond}")
message(STATUS "${status_text}" "${status_cond}") ocv_output_status("${status_text} ${status_cond}")
endif() endif()
else() else()
message(STATUS "${text}") ocv_output_status("${text}")
endif() endif()
endfunction() endfunction()
@ -265,4 +275,4 @@ macro(ocv_to_full_paths VAR)
set(${VAR} ${__tmp}) set(${VAR} ${__tmp})
unset(__tmp) unset(__tmp)
endif() endif()
endmacro() endmacro()

View File

@ -16,7 +16,13 @@ else()
set(cuda_link_libs "") set(cuda_link_libs "")
endif() 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_create_module(${cuda_link_libs})
ocv_add_precompiled_headers(${the_module}) ocv_add_precompiled_headers(${the_module})
@ -24,6 +30,3 @@ ocv_add_precompiled_headers(${the_module})
ocv_add_accuracy_tests() ocv_add_accuracy_tests()
ocv_add_perf_tests() ocv_add_perf_tests()

View File

@ -218,6 +218,8 @@ CV_EXPORTS void setNumThreads(int nthreads);
CV_EXPORTS int getNumThreads(); CV_EXPORTS int getNumThreads();
CV_EXPORTS int getThreadNum(); CV_EXPORTS int getThreadNum();
CV_EXPORTS_W const std::string& getBuildInformation();
//! Returns the number of ticks. //! Returns the number of ticks.
/*! /*!

View File

@ -410,6 +410,14 @@ int getNumberOfCPUs(void)
#endif #endif
} }
const std::string& getBuildInformation()
{
static std::string build_info =
#include "version_string.inc"
;
return build_info;
}
string format( const char* fmt, ... ) string format( const char* fmt, ... )
{ {
char buf[1 << 16]; char buf[1 << 16];

View File

@ -0,0 +1,28 @@
#include "opencv2/core/core.hpp"
#include <iostream>
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<bool>("help"))
{
parser.printParams();
}
else if (parser.get<bool>("build"))
{
std::cout << cv::getBuildInformation() << std::endl;
}
else
{
std::cout << "OpenCV " << CV_VERSION << std::endl;
}
return 0;
}