Add CMake files

This commit is contained in:
Luis Díaz Más 2015-02-13 19:00:14 +01:00 committed by Daniel Marjamäki
parent 6afe2e9fdc
commit 22424ba54a
16 changed files with 426 additions and 0 deletions

6
.gitignore vendored
View File

@ -70,3 +70,9 @@ htmlreport/MANIFEST
# kdevelop 4.x
*.kdev4
# Common cmake build directories
build*
# Temporal files
*.swp

19
CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
project(CppCheck)
cmake_minimum_required(VERSION 2.8)
include(cmake/versions.cmake REQUIRED)
include(cmake/options.cmake REQUIRED)
include(cmake/findDependencies.cmake REQUIRED)
include(cmake/compileroptions.cmake REQUIRED)
include(cmake/compilerDefinitions.cmake REQUIRED)
include(cmake/buildFiles.cmake REQUIRED)
file(GLOB cfgs "cfg/*.cfg")
add_subdirectory(externals/tinyxml)
add_subdirectory(lib) # CppCheck Library
add_subdirectory(cli) # Client application
add_subdirectory(test) # Tests
ADD_SUBDIRECTORY(gui) # Graphical application
include(cmake/printInfo.cmake REQUIRED)

23
cli/CMakeLists.txt Normal file
View File

@ -0,0 +1,23 @@
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml/)
include_directories(${PROJECT_SOURCE_DIR}/lib/)
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB mainfile "main.cpp")
list(REMOVE_ITEM srcs ${mainfile})
link_libraries(${PROJECT_NAME} tinyxml)
add_library(cli_lib OBJECT ${hdrs} ${srcs})
add_executable(cppcheck main.cpp
$<TARGET_OBJECTS:cli_lib>
)
install(TARGETS cppcheck
RUNTIME DESTINATION bin
COMPONENT applications)
install(FILES ${cfgs}
DESTINATION share/${PROJECT_NAME}/
COMPONENT headers)

2
cmake/buildFiles.cmake Normal file
View File

@ -0,0 +1,2 @@
CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake")

View File

@ -0,0 +1,16 @@
# -----------------------------------------------
# File that provides "make uninstall" target
# We use the file 'install_manifest.txt'
# -----------------------------------------------
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
execute_process(COMMAND rm $ENV{DESTDIR}${file})
endforeach(file)

View File

@ -0,0 +1,9 @@
if (UNIX)
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
add_definitions(-D_GLIBCXX_DEBUG)
endif()
if (HAVE_RULES)
add_definitions(-DHAVE_RULES -DTIXML_USE_STL)
endif()
add_definitions(-DCFGDIR="${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
endif()

121
cmake/compileroptions.cmake Normal file
View File

@ -0,0 +1,121 @@
set(EXTRA_C_FLAGS "")
set(EXTRA_C_FLAGS_RELEASE "-DNDEBUG")
set(EXTRA_C_FLAGS_DEBUG "-DDEBUG -O0")
if (USE_CLANG)
set (CMAKE_C_COMPILER_ID "Clang")
set (CMAKE_CXX_COMPILER_ID "Clang")
set (CMAKE_C_COMPILER "/usr/bin/clang")
set (CMAKE_CXX_COMPILER "/usr/bin/clang++")
set (CMAKE_C_FLAGS "-std=c99")
set (CMAKE_C_FLAGS_DEBUG "-g")
set (CMAKE_C_FLAGS_RELEASE "-O2")
set (CMAKE_CXX_FLAGS "")
set (CMAKE_CXX_FLAGS_DEBUG "-g")
set (CMAKE_CXX_FLAGS_RELEASE "-O2")
endif()
if (USE_ANALYZE)
set (CMAKE_C_COMPILER_ID "ccc-analyzer")
set (CMAKE_CXX_COMPILER_ID "c++-analyzer")
set (CMAKE_C_COMPILER "/usr/share/clang/scan-build/ccc-analyzer")
set (CMAKE_CXX_COMPILER "/usr/share/clang/scan-build/c++-analyzer")
set (CMAKE_C_FLAGS "-Wall -std=c99")
set (CMAKE_C_FLAGS_DEBUG "-g")
set (CMAKE_C_FLAGS_RELEASE "-O2")
set (CMAKE_CXX_FLAGS "-Wall")
set (CMAKE_CXX_FLAGS_DEBUG "-g")
set (CMAKE_CXX_FLAGS_RELEASE "-O2")
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
message(FATAL_ERROR "${PROJECT_NAME} c++11 support requires g++ 4.7 or greater.")
endif ()
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wabi")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wcast-qual") # Cast for removing type qualifiers
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wconversion") # Implicit conversions that may alter a value
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wfloat-equal") # Floating values used in equality comparisons
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Winline") # If a inline declared function couldn't be inlined
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wmissing-declarations") # If a global function is defined without a previous declaration
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wmissing-format-attribute") #
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Woverloaded-virtual") # when a function declaration hides virtual functions from a base class
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wpacked") #
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wredundant-decls") # if anything is declared more than once in the same scope
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wshadow") # whenever a local variable or type declaration shadows another one
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wsign-promo") #
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-missing-field-initializers")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-missing-braces")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-sign-compare")
if(WARNINGS_ANSI_ISO)
# set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror=return-type") #
# set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wstrict-aliasing=3")
else()
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-narrowing")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-delete-non-virtual-dtor")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-unnamed-type-template-args")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if(NOT EXISTS ${CMAKE_CXX_COMPILER})
MESSAGE( FATAL_ERROR "Clang++ not found. " )
endif()
if(ENABLE_COVERAGE OR ENABLE_COVERAGE_XML)
MESSAGE(FATAL_ERROR "Not use clang for generate code coverage. Use gcc. ")
endif()
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "c++-analyzer")
if(NOT EXISTS ${CMAKE_CXX_COMPILER})
MESSAGE( FATAL_ERROR "c++-analyzer not found. " )
endif()
if(ENABLE_COVERAGE)
MESSAGE(FATAL_ERROR "Not use c++-analyzer for generate code coverage. Use gcc. ")
endif()
endif()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "c++-analyzer" )
if(WARNINGS_ANSI_ISO)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wextra -pedantic")
# set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wlogical-op")
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wno-long-long") # Don't warn about long long usage.
endif()
if(WARNINGS_ARE_ERRORS)
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Werror")
endif()
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall -std=c++0x")
endif()
include(cmake/dynamic_analyzer_options.cmake REQUIRED)
# Add user supplied extra options (optimization, etc...)
# ==========================================================
set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS}" CACHE INTERNAL "Extra compiler options")
set(EXTRA_C_FLAGS_RELEASE "${EXTRA_C_FLAGS_RELEASE}" CACHE INTERNAL "Extra compiler options for Release build")
set(EXTRA_C_FLAGS_DEBUG "${EXTRA_C_FLAGS_DEBUG}" CACHE INTERNAL "Extra compiler options for Debug build")
#combine all "extra" options
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_C_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${EXTRA_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${EXTRA_C_FLAGS_DEBUG}")

View File

@ -0,0 +1,31 @@
IF (USE_CLANG)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fdiagnostics-show-category=name")
ENDIF()
IF(ANALYZE_MEMORY)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fsanitize=memory")
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fsanitize-memory-track-origins=2")
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fno-omit-frame-pointer")
# NOTE: tail call elimination -fno-optimize-sibling-calls
ELSEIF(ANALYZE_ADDRESS)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fsanitize=address")
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fno-omit-frame-pointer")
ELSEIF(ANALYZE_THREAD)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fsanitize=thread")
ENDIF()
IF(ANALYZE_UNDEFINED)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fsanitize=undefined-trap")
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fsanitize-undefined-trap-on-error")
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fno-sanitize-recover")
ENDIF()
IF(ANALYZE_DATAFLOW)
SET(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -fsanitize=dataflow")
ENDIF()

View File

@ -0,0 +1,10 @@
find_package(Qt4 4.6.1 COMPONENTS QtCore QtGui)
if (HAVE_RULES)
find_library(PCRE pcre)
if (NOT PCRE)
message(FATAL_ERROR "pcre dependency for RULES has not been found")
endif()
endif()
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC OFF)

38
cmake/options.cmake Normal file
View File

@ -0,0 +1,38 @@
#------------------------------------------------------
# Build type
#------------------------------------------------------
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Configs" FORCE)
if(DEFINED CMAKE_BUILD_TYPE)
SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
# ----------------------------------------------------------------------------
# PROJECT CONFIGURATION
# ----------------------------------------------------------------------------
option(USE_CLANG "Use Clang compiler" OFF)
option(USE_ANALYZE "Use Clang compiler with analyze mode" OFF)
option(ANALYZE_MEMORY "Clang dynamic analyzer: detector of uninitialized reads." OFF)
option(ANALYZE_ADDRESS "Clang dynamic analyzer: fast memory error detector. " OFF)
option(ANALYZE_THREAD "Clang dynamic analyzer: tool that detects data races. " OFF)
option(ANALYZE_UNDEFINED "Clang dynamic analyzer: undefined behavior checker. " OFF)
option(ANALYZE_DATAFLOW "Clang dynamic analyzer: general dynamic dataflow analysis." OFF)
option(WARNINGS_ARE_ERRORS "Treat warnings as errors" OFF)
option(WARNINGS_ANSI_ISO "Issue all the mandatory diagnostics Listed in C standard" ON)
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_TESTS "Build tests" OFF)
option(BUILD_GUI "Build the qt application" OFF)
option(BUILD_UTILS_TESTS "Build applications tests using the different modules" OFF)
option(HAVE_RULES "Usage of rules (needs PCRE library and headers)" 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")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

47
cmake/printInfo.cmake Normal file
View File

@ -0,0 +1,47 @@
message( STATUS "------------------ General configuration for ${PROJECT_NAME} ${VERSION} -----------------")
message( STATUS )
message( STATUS "CMake Generator = ${CMAKE_GENERATOR}")
message( STATUS "Compiler = ${CMAKE_CXX_COMPILER_ID}")
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 (Debug) = ${CMAKE_CXX_FLAGS_DEBUG}")
get_directory_property( DirDefs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS )
foreach( d ${DirDefs} )
message( STATUS "Found Define: " ${d} )
endforeach()
message( STATUS )
message( STATUS "---------------------------------------------------------" )
message( STATUS "USE_CLANG = ${USE_CLANG}" )
message( STATUS "USE_ANALYZE = ${USE_ANALYZE}" )
message( STATUS "ANALYZE_MEMORY = ${ANALYZE_MEMORY}" )
message( STATUS "ANALYZE_ADDRESS = ${ANALYZE_ADDRESS}" )
message( STATUS "ANALYZE_THREAD = ${ANALYZE_THREAD}" )
message( STATUS "ANALYZE_UNDEFINED = ${ANALYZE_UNDEFINED}" )
message( STATUS "ANALYZE_DATAFLOW = ${ANALYZE_DATAFLOW}" )
message( STATUS "WARNINGS_ANSI_ISO = ${WARNINGS_ANSI_ISO}" )
message( STATUS "WARNINGS_ARE_ERRORS = ${WARNINGS_ARE_ERRORS}" )
message( STATUS )
message( STATUS "BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}" )
message( STATUS "BUILD_TESTS = ${BUILD_TESTS}" )
message( STATUS "BUILD_GUI = ${BUILD_GUI}" )
message( STATUS )
message( STATUS "HAVE_RULES = ${HAVE_RULES}" )
message( STATUS )
message( STATUS "Change a value with: cmake -D<Variable>=<Value>" )
message( STATUS )
if(${USE_ANALYZE})
message( STATUS "------------------- Run static analyzer ----------------------" )
message( STATUS "##############################")
message( STATUS "RUN: scan-build make" )
message( STATUS "##############################")
message( STATUS )
endif()
if(${ANALYZE_ADDRESS})
message("##########################################################")
message(STATUS "For better visualitation change enviroment variable: ASAN_SYMBOLIZER_PATH=/path/to/llvm-symbolizer")
message(STATUS "Detect memory leaks, change enviroment variable: ASAN_OPTIONS=\"detect_leaks=1\"")
message("##########################################################")
endif()

11
cmake/versions.cmake Normal file
View File

@ -0,0 +1,11 @@
# Version for libraries CPP
SET(VERSION "1.6.8")
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:
SET(DLLVERSION "")
SET(DEBUG_POSTFIX "")

13
externals/tinyxml/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,13 @@
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
add_library(tinyxml ${srcs} ${hdrs})
install(TARGETS tinyxml
RUNTIME DESTINATION bin COMPONENT libraries
LIBRARY DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT libraries
ARCHIVE DESTINATION lib COMPONENT libraries)
install(FILES ${hdrs}
DESTINATION include/${PROJECT_NAME}/
COMPONENT headers)

34
gui/CMakeLists.txt Normal file
View File

@ -0,0 +1,34 @@
if (BUILD_GUI)
set(CMAKE_AUTOMOC ON)
include(${QT_USE_FILE})
if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
add_definitions(-DQT_NO_DEBUG)
add_definitions(-DQT_NO_DEBUG_OUTPUT)
add_definitions(-DQT_NO_WARNING_OUTPUT)
else()
add_definitions(-DQT_DEBUG)
endif()
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml/)
include_directories(${PROJECT_SOURCE_DIR}/lib/)
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB uis "*.ui")
file(GLOB tss "*.ts")
QT4_WRAP_UI(uis_hdrs ${uis})
QT4_ADD_RESOURCES(resources "gui.qrc")
QT4_ADD_TRANSLATION(qms ${tss})
link_libraries(${PROJECT_NAME} tinyxml ${QT_LIBRARIES})
add_executable(cppcheck-gui ${hdrs} ${srcs} ${uis_hdrs} ${resources} ${qms})
install(TARGETS cppcheck-gui RUNTIME DESTINATION bin COMPONENT applications)
install(FILES ${qms} DESTINATION bin COMPONENT applications)
set(CMAKE_AUTOMOC OFF)
endif()

19
lib/CMakeLists.txt Normal file
View File

@ -0,0 +1,19 @@
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml/)
file(GLOB_RECURSE hdrs "*.h")
file(GLOB_RECURSE srcs "*.cpp")
add_library(${PROJECT_NAME} ${srcs} ${hdrs})
if (HAVE_RULES)
target_link_libraries(${PROJECT_NAME} pcre)
endif()
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin COMPONENT libraries
LIBRARY DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT libraries
ARCHIVE DESTINATION lib COMPONENT libraries)
install(FILES ${hdrs}
DESTINATION include/${PROJECT_NAME}/
COMPONENT headers)

27
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,27 @@
if (BUILD_TESTS)
include_directories(
${PROJECT_SOURCE_DIR}/lib/
${PROJECT_SOURCE_DIR}/cli/
${PROJECT_SOURCE_DIR}/externals/tinyxml
)
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
link_libraries(${PROJECT_NAME} tinyxml)
add_executable(testrunner ${hdrs} ${srcs}
$<TARGET_OBJECTS:cli_lib>
)
add_custom_target(copy_cfg ALL
COMMENT "Copying cfg files")
add_custom_command(
TARGET copy_cfg
COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/cfg"
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cfg")
add_dependencies(testrunner copy_cfg)
endif()