Cmake object linkage. Fix #7128: (cppcheck 1.70 doesn't report any warnings)

This commit is contained in:
Frank Zingsheim 2015-11-26 20:25:09 +01:00
parent fe7d5cd242
commit 70c20515a9
8 changed files with 27 additions and 50 deletions

View File

@ -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)

View File

@ -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
$<TARGET_OBJECTS:cli_lib>
)
add_library(cli_objs OBJECT ${hdrs} ${srcs})
add_executable(cppcheck ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:tinyxml_objs>)
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)

View File

@ -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")

View File

@ -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)

View File

@ -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)

View File

@ -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_OBJECTS:lib_objs> $<TARGET_OBJECTS:tinyxml_objs>)
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)

View File

@ -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)

View File

@ -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}
$<TARGET_OBJECTS:cli_lib>
)
add_executable(testrunner ${hdrs} ${srcs} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:tinyxml_objs>)
if (HAVE_RULES)
target_link_libraries(testunner pcre)
endif()
add_custom_target(copy_cfg ALL
COMMENT "Copying cfg files")