Add find_package(tinyxml2) to CMake builds (#2691)
So far, the cmake files of Cppcheck needed to be patched in order to use installed tinyxml2 instead of the bundled version of tinyxml2. - Introduce the CMake option USE_BUNDLED_TINYXML2 with a default value of ON. This preserves the behavior as in the past and uses the bundled version under externals/tinyxml2 by default. - Usage of the installed tinyxml2 version of a system can be enabled now using -DUSE_BUNDLED_TINYXML2=OFF as a cmake parameter. - Some Linux distros do not install tinyxml2*.cmake files, which are required to find tinyxml2 using find_package(). Try first using find_package(tinyxml2 QUIET) and if this fails, try again using find_library(tinyxml2_LIBRARY tinyxml2)
This commit is contained in:
parent
4a8a78a925
commit
8ac55a8534
|
@ -33,7 +33,10 @@ if (BUILD_TESTS)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(USE_BUNDLED_TINYXML2)
|
||||||
|
message(STATUS "Using bundled version of tinyxml2")
|
||||||
add_subdirectory(externals/tinyxml2)
|
add_subdirectory(externals/tinyxml2)
|
||||||
|
endif()
|
||||||
add_subdirectory(externals/simplecpp)
|
add_subdirectory(externals/simplecpp)
|
||||||
add_subdirectory(lib) # CppCheck Library
|
add_subdirectory(lib) # CppCheck Library
|
||||||
add_subdirectory(cli) # Client application
|
add_subdirectory(cli) # Client application
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/lib/)
|
include_directories(${PROJECT_SOURCE_DIR}/lib/)
|
||||||
|
if(USE_BUNDLED_TINYXML2)
|
||||||
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
|
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
|
||||||
|
endif()
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
|
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
|
||||||
|
|
||||||
file(GLOB hdrs "*.h")
|
file(GLOB hdrs "*.h")
|
||||||
|
@ -8,7 +10,13 @@ file(GLOB mainfile "main.cpp")
|
||||||
list(REMOVE_ITEM srcs ${mainfile})
|
list(REMOVE_ITEM srcs ${mainfile})
|
||||||
|
|
||||||
add_library(cli_objs OBJECT ${hdrs} ${srcs})
|
add_library(cli_objs OBJECT ${hdrs} ${srcs})
|
||||||
add_executable(cppcheck ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:tinyxml2_objs> $<TARGET_OBJECTS:simplecpp_objs>)
|
|
||||||
|
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
|
||||||
|
if(USE_BUNDLED_TINYXML2)
|
||||||
|
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_executable(cppcheck ${cppcheck_SOURCES})
|
||||||
if (HAVE_RULES)
|
if (HAVE_RULES)
|
||||||
target_link_libraries(cppcheck ${PCRE_LIBRARY})
|
target_link_libraries(cppcheck ${PCRE_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
|
@ -18,6 +26,9 @@ endif()
|
||||||
if (WIN32 AND NOT BORLAND)
|
if (WIN32 AND NOT BORLAND)
|
||||||
target_link_libraries(cppcheck Shlwapi.lib)
|
target_link_libraries(cppcheck Shlwapi.lib)
|
||||||
endif()
|
endif()
|
||||||
|
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
|
||||||
|
target_link_libraries(cppcheck tinyxml2)
|
||||||
|
endif()
|
||||||
|
|
||||||
install(TARGETS cppcheck
|
install(TARGETS cppcheck
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
|
||||||
|
|
|
@ -38,3 +38,16 @@ if (NOT USE_MATCHCOMPILER_OPT MATCHES "Off")
|
||||||
set(USE_MATCHCOMPILER_OPT "Off")
|
set(USE_MATCHCOMPILER_OPT "Off")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (NOT USE_BUNDLED_TINYXML2)
|
||||||
|
find_package(tinyxml2 QUIET)
|
||||||
|
if (NOT tinyxml2_FOUND)
|
||||||
|
find_library(tinyxml2_LIBRARY tinyxml2)
|
||||||
|
if (NOT tinyxml2_LIBRARY)
|
||||||
|
message(FATAL_ERROR "tinyxml2 has not been found")
|
||||||
|
else()
|
||||||
|
message(STATUS "tinyxml2_LIBRARY: ${tinyxml2_LIBRARY}")
|
||||||
|
set(tinyxml2_FOUND 1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
|
@ -41,6 +41,7 @@ option(WITH_QCHART "When building GUI(need BUILD_GUI=ON), use Qt5 Chart
|
||||||
|
|
||||||
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
|
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
|
||||||
option(USE_Z3 "Usage of z3 library" OFF)
|
option(USE_Z3 "Usage of z3 library" OFF)
|
||||||
|
option(USE_BUNDLED_TINYXML2 "Usage of bundled tinyxml2 library" ON)
|
||||||
|
|
||||||
# precompiled headers do not emit compiler warnings so we cannot use them right now
|
# precompiled headers do not emit compiler warnings so we cannot use them right now
|
||||||
#if (CMAKE_VERSION VERSION_EQUAL "3.16" OR CMAKE_VERSION VERSION_GREATER "3.16")
|
#if (CMAKE_VERSION VERSION_EQUAL "3.16" OR CMAKE_VERSION VERSION_GREATER "3.16")
|
||||||
|
|
|
@ -52,6 +52,7 @@ if (USE_Z3)
|
||||||
message( STATUS "Z3_LIBRARIES = ${Z3_LIBRARIES}" )
|
message( STATUS "Z3_LIBRARIES = ${Z3_LIBRARIES}" )
|
||||||
message( STATUS "Z3_CXX_INCLUDE_DIRS = ${Z3_CXX_INCLUDE_DIRS}" )
|
message( STATUS "Z3_CXX_INCLUDE_DIRS = ${Z3_CXX_INCLUDE_DIRS}" )
|
||||||
endif()
|
endif()
|
||||||
|
message( STATUS "USE_BUNDLED_TINYXML2 = ${USE_BUNDLED_TINYXML2}" )
|
||||||
message( STATUS )
|
message( STATUS )
|
||||||
|
|
||||||
if(${ANALYZE_ADDRESS})
|
if(${ANALYZE_ADDRESS})
|
||||||
|
|
|
@ -10,7 +10,9 @@ if (BUILD_GUI)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/lib/)
|
include_directories(${PROJECT_SOURCE_DIR}/lib/)
|
||||||
|
if(USE_BUNDLED_TINYXML2)
|
||||||
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
|
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
|
||||||
|
endif()
|
||||||
|
|
||||||
file(GLOB hdrs "*.h")
|
file(GLOB hdrs "*.h")
|
||||||
file(GLOB srcs "*.cpp")
|
file(GLOB srcs "*.cpp")
|
||||||
|
@ -19,14 +21,21 @@ if (BUILD_GUI)
|
||||||
QT5_WRAP_UI(uis_hdrs ${uis})
|
QT5_WRAP_UI(uis_hdrs ${uis})
|
||||||
QT5_ADD_RESOURCES(resources "gui.qrc")
|
QT5_ADD_RESOURCES(resources "gui.qrc")
|
||||||
QT5_ADD_TRANSLATION(qms ${tss})
|
QT5_ADD_TRANSLATION(qms ${tss})
|
||||||
|
list(APPEND cppcheck-gui_SOURCES ${hdrs} ${srcs} ${uis_hdrs} ${resources} ${qms} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
|
||||||
|
if(USE_BUNDLED_TINYXML2)
|
||||||
|
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(cppcheck-gui ${hdrs} ${srcs} ${uis_hdrs} ${resources} ${qms} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:tinyxml2_objs> $<TARGET_OBJECTS:simplecpp_objs>)
|
add_executable(cppcheck-gui ${cppcheck-gui_SOURCES})
|
||||||
if (HAVE_RULES)
|
if (HAVE_RULES)
|
||||||
target_link_libraries(cppcheck-gui ${PCRE_LIBRARY})
|
target_link_libraries(cppcheck-gui ${PCRE_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
if (USE_Z3)
|
if (USE_Z3)
|
||||||
target_link_libraries(cppcheck-gui ${Z3_LIBRARIES})
|
target_link_libraries(cppcheck-gui ${Z3_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
|
||||||
|
target_link_libraries(cppcheck-gui tinyxml2)
|
||||||
|
endif()
|
||||||
target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport Qt5::Help)
|
target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport Qt5::Help)
|
||||||
if(WITH_QCHART)
|
if(WITH_QCHART)
|
||||||
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART )
|
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART )
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
if (BUILD_TESTS)
|
if (BUILD_TESTS)
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
|
include_directories(${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
|
||||||
|
if(USE_BUNDLED_TINYXML2)
|
||||||
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2)
|
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2)
|
||||||
|
endif()
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
|
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
|
||||||
|
|
||||||
file(GLOB hdrs "*.h")
|
file(GLOB hdrs "*.h")
|
||||||
file(GLOB srcs "*.cpp")
|
file(GLOB srcs "*.cpp")
|
||||||
|
list(APPEND testrunner_SOURCES ${hdrs} ${srcs} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:simplecpp_objs>)
|
||||||
|
if(USE_BUNDLED_TINYXML2)
|
||||||
|
list(APPEND testrunner_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
|
||||||
|
endif()
|
||||||
|
|
||||||
add_executable(testrunner ${hdrs} ${srcs} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:tinyxml2_objs> $<TARGET_OBJECTS:simplecpp_objs>)
|
add_executable(testrunner ${testrunner_SOURCES})
|
||||||
if (HAVE_RULES)
|
if (HAVE_RULES)
|
||||||
target_link_libraries(testrunner ${PCRE_LIBRARY})
|
target_link_libraries(testrunner ${PCRE_LIBRARY})
|
||||||
endif()
|
endif()
|
||||||
|
@ -16,6 +22,9 @@ if (BUILD_TESTS)
|
||||||
if (WIN32 AND NOT BORLAND)
|
if (WIN32 AND NOT BORLAND)
|
||||||
target_link_libraries(testrunner Shlwapi.lib)
|
target_link_libraries(testrunner Shlwapi.lib)
|
||||||
endif()
|
endif()
|
||||||
|
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
|
||||||
|
target_link_libraries(testrunner tinyxml2)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
|
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
|
||||||
target_precompile_headers(testrunner PRIVATE precompiled.h)
|
target_precompile_headers(testrunner PRIVATE precompiled.h)
|
||||||
|
|
Loading…
Reference in New Issue