From 70c20515a967db5f3ecb75896317793cd47b62c1 Mon Sep 17 00:00:00 2001 From: Frank Zingsheim Date: Thu, 26 Nov 2015 20:25:09 +0100 Subject: [PATCH] Cmake object linkage. Fix #7128: (cppcheck 1.70 doesn't report any warnings) --- CMakeLists.txt | 2 ++ cli/CMakeLists.txt | 18 ++++++++---------- cmake/compileroptions.cmake | 2 +- cmake/options.cmake | 2 -- externals/tinyxml/CMakeLists.txt | 9 +-------- gui/CMakeLists.txt | 14 ++++++++------ lib/CMakeLists.txt | 14 +------------- test/CMakeLists.txt | 16 ++++++---------- 8 files changed, 27 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e957df5e5..56b3e05fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ project(CppCheck) cmake_minimum_required(VERSION 2.8) +include(GNUInstallDirs) + include(cmake/versions.cmake REQUIRED) include(cmake/options.cmake REQUIRED) include(cmake/findDependencies.cmake REQUIRED) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 59e139a94..a7fc54fcc 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -1,23 +1,21 @@ -include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml/) include_directories(${PROJECT_SOURCE_DIR}/lib/) +include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml/) 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 - $ -) +add_library(cli_objs OBJECT ${hdrs} ${srcs}) +add_executable(cppcheck ${hdrs} ${mainfile} $ $ $) +if (HAVE_RULES) + target_link_libraries(cppcheck pcre) +endif() install(TARGETS cppcheck - RUNTIME DESTINATION bin + RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications) install(FILES ${cfgs} - DESTINATION share/${PROJECT_NAME}/ + DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/${PROJECT_NAME}/ COMPONENT headers) diff --git a/cmake/compileroptions.cmake b/cmake/compileroptions.cmake index e65c183c0..97cfa3456 100644 --- a/cmake/compileroptions.cmake +++ b/cmake/compileroptions.cmake @@ -35,7 +35,7 @@ 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.") + message(FATAL_ERROR "${PROJECT_NAME} c++11 support requires g++ 4.7 or greater, but it is ${GCC_VERSION}") endif () set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wabi") diff --git a/cmake/options.cmake b/cmake/options.cmake index 400b01c08..333a73175 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -35,10 +35,8 @@ else() set(USE_MATCHCOMPILER_OPT ${USE_MATCHCOMPILER}) endif() -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) diff --git a/externals/tinyxml/CMakeLists.txt b/externals/tinyxml/CMakeLists.txt index a629d6d3e..7f05d80ac 100644 --- a/externals/tinyxml/CMakeLists.txt +++ b/externals/tinyxml/CMakeLists.txt @@ -1,13 +1,6 @@ file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") -add_library(tinyxml ${srcs} ${hdrs}) +add_library(tinyxml_objs OBJECT ${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) diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 7bfd31ec1..2d07d7ace 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -10,9 +10,8 @@ if (BUILD_GUI) add_definitions(-DQT_DEBUG) endif() - - include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml/) include_directories(${PROJECT_SOURCE_DIR}/lib/) + include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml/) file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") @@ -22,12 +21,15 @@ if (BUILD_GUI) 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} $ $) + target_link_libraries(cppcheck-gui ${QT_LIBRARIES}) + if (HAVE_RULES) + target_link_libraries(cppcheck-gui pcre) + endif() - 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) + install(TARGETS cppcheck-gui RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications) + install(FILES ${qms} DESTINATION ${CMAKE_INSTALL_FULL_BINDIR} COMPONENT applications) set(CMAKE_AUTOMOC OFF) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b6275b22a..3d5949baa 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -34,17 +34,5 @@ else() set(srcs_lib ${srcs}) endif() -add_library(${PROJECT_NAME} ${srcs_lib} ${hdrs}) +add_library(lib_objs OBJECT ${srcs_lib} ${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) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 59b508b53..0d7380273 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,19 +1,15 @@ if (BUILD_TESTS) - include_directories( - ${PROJECT_SOURCE_DIR}/lib/ - ${PROJECT_SOURCE_DIR}/cli/ - ${PROJECT_SOURCE_DIR}/externals/tinyxml - ) + include_directories(${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/) + include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml) file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") - link_libraries(${PROJECT_NAME} tinyxml) - - add_executable(testrunner ${hdrs} ${srcs} - $ - ) + add_executable(testrunner ${hdrs} ${srcs} $ $ $) + if (HAVE_RULES) + target_link_libraries(testunner pcre) + endif() add_custom_target(copy_cfg ALL COMMENT "Copying cfg files")