some CMake cleanups and additions (#2639)

This commit is contained in:
Oliver Stöneberg 2020-05-27 05:15:46 +02:00 committed by GitHub
parent 6a7eada417
commit 3a90341961
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 66 additions and 29 deletions

View File

@ -10,10 +10,10 @@ list(REMOVE_ITEM srcs ${mainfile})
add_library(cli_objs OBJECT ${hdrs} ${srcs})
add_executable(cppcheck ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:tinyxml_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if (HAVE_RULES)
find_library(PCRE_LIBRARY pcre)
target_link_libraries(cppcheck ${PCRE_LIBRARY})
find_path(PCRE_INCLUDE pcre.h)
target_include_directories(cppcheck PUBLIC ${PCRE_INCLUDE})
endif()
if (USE_Z3)
target_link_libraries(cppcheck ${Z3_LIBRARIES})
endif()
if (WIN32 AND NOT BORLAND)
target_link_libraries(cppcheck Shlwapi.lib)

View File

@ -1,15 +1,28 @@
if (UNIX)
if (MSVC)
# Visual Studio only sets _DEBUG
if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_definitions(-D_GLIBCXX_DEBUG)
add_definitions(-DDEBUG)
endif()
if (HAVE_RULES)
add_definitions(-DHAVE_RULES -DTIXML_USE_STL)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()
if (UNIX)
# TODO: check if this can be enabled again for Clang - also done in Makefile
if (CMAKE_BUILD_TYPE MATCHES "Debug" AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
add_definitions(-D_GLIBCXX_DEBUG)
endif()
add_definitions(-DFILESDIR="${FILESDIR}")
endif()
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
if (HAVE_RULES)
add_definitions(-DHAVE_RULES -DTIXML_USE_STL)
endif()
if (USE_Z3)
add_definitions(-DUSE_Z3)
endif()
if (ENABLE_CHECK_INTERNAL)
add_definitions(-DCHECK_INTERNAL)
endif()

View File

@ -1,16 +1,8 @@
if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_definitions(-DDEBUG)
elseif(CMAKE_BUILD_TYPE MATCHES "Release" OR CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
add_definitions(-DNDEBUG)
endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_definitions(-g -O0)
elseif(CMAKE_BUILD_TYPE MATCHES "Release" OR CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
add_definitions(-O2)
if(CMAKE_BUILD_TYPE MATCHES "Release")
# "Release" uses -O3 by default
add_compile_options(-O2)
endif()
if (WARNINGS_ARE_ERRORS)
add_compile_options(-Werror)
endif()

View File

@ -7,12 +7,27 @@ if (BUILD_GUI)
endif()
if (HAVE_RULES)
find_library(PCRE pcre)
if (NOT PCRE)
find_library(PCRE_LIBRARY pcre)
if (NOT PCRE_LIBRARY)
message(FATAL_ERROR "pcre dependency for RULES has not been found")
endif()
endif()
if (USE_Z3)
find_package(Z3 QUIET)
if (NOT Z3_FOUND)
find_library(Z3_LIBRARIES z3)
if (NOT Z3_LIBRARIES)
message(FATAL_ERROR "z3 dependency has not been found")
endif()
find_path(Z3_CXX_INCLUDE_DIRS z3++.h PATH_SUFFIXES "z3")
if (NOT Z3_CXX_INCLUDE_DIRS)
message(FATAL_ERROR "z3++.h has not been found")
endif()
endif()
include_directories(cppcheck SYSTEM ${Z3_CXX_INCLUDE_DIRS})
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC OFF)

View File

@ -34,10 +34,12 @@ endif()
option(BUILD_TESTS "Build tests" OFF)
option(ENABLE_CHECK_INTERNAL "Enable internal checks" OFF)
option(ENABLE_OSS_FUZZ "Enable the OSS-Fuzz related targets" ON)
option(BUILD_GUI "Build the qt application" OFF)
option(WITH_QCHART "When building GUI(need BUILD_GUI=ON), use Qt5 Charts" OFF)
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" OFF)
option(USE_Z3 "Usage of z3 library" OFF)
set(CMAKE_INCLUDE_DIRS_CONFIGCMAKE ${CMAKE_INSTALL_PREFIX}/include CACHE PATH "Output directory for headers")
set(CMAKE_LIB_DIRS_CONFIGCMAKE ${CMAKE_INSTALL_PREFIX}/lib CACHE PATH "Output directory for libraries")

View File

@ -7,6 +7,7 @@ message( STATUS "Build type = ${CMAKE_BUILD_TYPE}")
message( STATUS "CMAKE_INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}" )
message( STATUS "C++ flags (General) = ${CMAKE_CXX_FLAGS}")
message( STATUS "C++ flags (Release) = ${CMAKE_CXX_FLAGS_RELEASE}")
message( STATUS "C++ flags (RelWithDebInfo) = ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message( STATUS "C++ flags (Debug) = ${CMAKE_CXX_FLAGS_DEBUG}")
get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${DirDefs} )
@ -31,12 +32,21 @@ else()
endif(NOT DEFINED BUILD_SHARED_LIBS)
message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" )
message( STATUS "ENABLE_CHECK_INTERNAL = ${ENABLE_CHECK_INTERNAL}" )
message( STATUS "ENABLE_OSS_FUZZ = ${ENABLE_OSS_FUZZ}" )
message( STATUS )
message( STATUS "BUILD_GUI = ${BUILD_GUI}" )
message( STATUS "WITH_QCHART = ${WITH_QCHART}" )
message( STATUS )
message( STATUS "HAVE_RULES = ${HAVE_RULES}" )
if (HAVE_RULES)
message( STATUS "PCRE_LIBRARY = ${PCRE_LIBRARY}" )
endif()
message( STATUS )
message( STATUS "Change a value with: cmake -D<Variable>=<Value>" )
message( STATUS "USE_Z3 = ${USE_Z3}" )
if (USE_Z3)
message( STATUS "Z3_LIBRARIES = ${Z3_LIBRARIES}" )
message( STATUS "Z3_CXX_INCLUDE_DIRS = ${Z3_CXX_INCLUDE_DIRS}" )
endif()
message( STATUS )
if(${ANALYZE_ADDRESS})

View File

@ -3,7 +3,6 @@ SET(VERSION "2.0.99")
STRING(REGEX MATCHALL "[0-9]" VERSION_PARTS "${VERSION}")
LIST(GET VERSION_PARTS 0 VERSION_MAJOR)
LIST(GET VERSION_PARTS 1 VERSION_MINOR)
LIST(GET VERSION_PARTS 2 VERSION_PATCH)
SET(SOVERSION "${VERSION_MAJOR}.${VERSION_MINOR}")
# Postfix of so's:

View File

@ -14,7 +14,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()
# TODO: conflicts with ANALYZE_* options
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (ENABLE_OSS_FUZZ AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_library(tinyxml_objs_sanitized OBJECT EXCLUDE_FROM_ALL ${srcs} ${hdrs})
target_compile_options(tinyxml_objs_sanitized PRIVATE -fsanitize=address)
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")

View File

@ -22,7 +22,10 @@ if (BUILD_GUI)
add_executable(cppcheck-gui ${hdrs} ${srcs} ${uis_hdrs} ${resources} ${qms} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:tinyxml_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if (HAVE_RULES)
target_link_libraries(cppcheck-gui pcre)
target_link_libraries(cppcheck-gui ${PCRE_LIBRARY})
endif()
if (USE_Z3)
target_link_libraries(cppcheck-gui ${Z3_LIBRARIES})
endif()
target_link_libraries(cppcheck-gui Qt5::Core Qt5::Gui Qt5::Widgets Qt5::PrintSupport)
if(WITH_QCHART)

View File

@ -37,7 +37,7 @@ else()
endif()
add_library(lib_objs OBJECT ${srcs_lib} ${hdrs})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (ENABLE_OSS_FUZZ AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_library(lib_objs_sanitized OBJECT EXCLUDE_FROM_ALL ${srcs_lib} ${hdrs})
target_compile_options(lib_objs_sanitized PRIVATE -fsanitize=address)
endif()

View File

@ -1,4 +1,4 @@
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (ENABLE_OSS_FUZZ AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_executable(fuzz-client EXCLUDE_FROM_ALL
main.cpp
type2.cpp

View File

@ -21,7 +21,10 @@ if (BUILD_TESTS)
add_executable(testrunner ${hdrs} ${srcs} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:tinyxml_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if (HAVE_RULES)
target_link_libraries(testrunner pcre)
target_link_libraries(testrunner ${PCRE_LIBRARY})
endif()
if (USE_Z3)
target_link_libraries(testrunner ${Z3_LIBRARIES})
endif()
add_custom_target(copy_cfg ALL