Skip to content

Commit a72f0e8

Browse files
committed
CMake cleanup
1 parent 8f3d36a commit a72f0e8

12 files changed

Lines changed: 53 additions & 137 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ if(USE_BUNDLED_TINYXML2)
100100
add_subdirectory(externals/tinyxml2)
101101
endif()
102102
add_subdirectory(externals/simplecpp)
103+
add_subdirectory(externals/picojson)
103104
add_subdirectory(lib) # CppCheck Library
104105
add_subdirectory(frontend)
105106
add_subdirectory(cli) # Client application

cli/CMakeLists.txt

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,25 @@ if (BUILD_CLI)
55
file(GLOB mainfile "main.cpp")
66
list(REMOVE_ITEM srcs ${mainfile})
77

8-
add_library(cli_objs OBJECT ${hdrs} ${srcs})
9-
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/frontend/)
10-
if(USE_BUNDLED_TINYXML2)
11-
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
12-
else()
13-
target_include_directories(cli_objs SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
14-
endif()
15-
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
16-
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
8+
add_library(cli ${hdrs} ${srcs})
9+
target_include_directories(cli PUBLIC .)
10+
target_link_libraries(cli PRIVATE cppcheck-core frontend tinyxml2 simplecpp picojson)
1711
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
18-
target_precompile_headers(cli_objs PRIVATE precompiled.h)
19-
endif()
20-
if (BUILD_CORE_DLL)
21-
target_compile_definitions(cli_objs PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
12+
target_precompile_headers(cli PRIVATE precompiled.h)
2213
endif()
2314

2415
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 13)
2516
# false positive warning in Clang 13 - caused by FD_ZERO macro
2617
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
2718
endif()
2819

29-
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:frontend_objs>)
30-
if (NOT BUILD_CORE_DLL)
31-
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
32-
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)
33-
if(USE_BUNDLED_TINYXML2)
34-
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
35-
endif()
36-
endif()
20+
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile})
3721
if (WIN32)
3822
list(APPEND cppcheck_SOURCES version.rc)
3923
endif()
4024

4125
add_executable(cppcheck ${cppcheck_SOURCES})
42-
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
43-
if(USE_BUNDLED_TINYXML2)
44-
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
45-
else()
46-
target_include_directories(cppcheck SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
47-
endif()
48-
target_externals_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
26+
target_link_libraries(cppcheck PRIVATE cppcheck-core cli tinyxml2 simplecpp)
4927
if (HAVE_RULES)
5028
target_link_libraries(cppcheck ${PCRE_LIBRARY})
5129
endif()
@@ -56,13 +34,7 @@ if (BUILD_CLI)
5634
target_link_libraries(cppcheck shlwapi)
5735
endif()
5836
endif()
59-
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
60-
target_link_libraries(cppcheck ${tinyxml2_LIBRARIES})
61-
endif()
6237
target_link_libraries(cppcheck ${CMAKE_THREAD_LIBS_INIT})
63-
if (BUILD_CORE_DLL)
64-
target_link_libraries(cppcheck cppcheck-core)
65-
endif()
6638

6739
add_dependencies(cppcheck copy_cfg)
6840
add_dependencies(cppcheck copy_addons)

cmake/compileroptions.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ function(target_externals_include_directories TARGET)
2424
endif()
2525
endfunction()
2626

27+
function(target_dll_compile_definitions TARGET EXPORT IMPORT)
28+
if (BUILD_SHARED_LIBS AND MSVC)
29+
target_compile_definitions(simplecpp_objs PRIVATE ${EXPORT})
30+
target_compile_definitions(simplecpp_objs INTERFACE ${IMPORT})
31+
endif()
32+
endfunction()
33+
2734
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
2835
add_compile_options(-Weverything)
2936
endif()

cmake/findDependencies.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ else()
6767
endif()
6868

6969
if(NOT USE_BUNDLED_TINYXML2)
70+
add_library(tinyxml2 INTERFACE)
7071
find_package(tinyxml2 QUIET)
7172
if(TARGET tinyxml2::tinyxml2)
72-
set(tinyxml2_LIBRARIES "tinyxml2::tinyxml2")
73-
set(tinyxml2_INCLUDE_DIRS $<TARGET_PROPERTY:tinyxml2::tinyxml2,INTERFACE_INCLUDE_DIRECTORIES>)
73+
target_link_libraries(tinyxml2 INTERFACE tinyxml2::tinyxml2)
7474
else()
7575
find_library(tinyxml2_LIBRARIES tinyxml2)
7676
find_path(tinyxml2_INCLUDE_DIRS tinyxml2.h)
@@ -79,6 +79,8 @@ if(NOT USE_BUNDLED_TINYXML2)
7979
else()
8080
set(tinyxml2_FOUND 1)
8181
endif()
82+
target_link_libraries(tinyxml2 INTERFACE ${tinyxml2_LIBRARIES})
83+
target_include_directories(tinyxml2 INTERFACE ${tinyxml2_INCLUDE_DIRS})
8284
endif()
8385
endif()
8486

externals/simplecpp/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
file(GLOB hdrs "*.h")
22
file(GLOB srcs "*.cpp")
33

4-
add_library(simplecpp_objs OBJECT ${srcs} ${hdrs})
5-
if (BUILD_CORE_DLL)
6-
target_compile_definitions(simplecpp_objs PRIVATE SIMPLECPP_EXPORT)
7-
endif()
4+
add_library(simplecpp ${srcs} ${hdrs})
5+
target_dll_compile_definitions(simplecpp SIMPLECPP_EXPORT SIMPLECPP_IMPORT)
86

97
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10-
target_compile_options_safe(simplecpp_objs -Wno-zero-as-null-pointer-constant)
8+
target_compile_options_safe(simplecpp -Wno-zero-as-null-pointer-constant)
119
endif()
10+
11+
target_include_directories(simplecpp PUBLIC .)

externals/tinyxml2/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
file(GLOB hdrs "*.h")
22
file(GLOB srcs "*.cpp")
33

4-
add_library(tinyxml2_objs OBJECT ${srcs} ${hdrs})
5-
if (BUILD_CORE_DLL)
6-
target_compile_definitions(tinyxml2_objs PRIVATE TINYXML2_EXPORT)
7-
endif()
4+
add_library(tinyxml2 ${srcs} ${hdrs})
5+
target_dll_compile_definitions(tinyxml2 TINYXML2_EXPORT TINYXML2_IMPORT)
86

97
# TODO: needs to be fixed upstream
108
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
11-
target_compile_options(tinyxml2_objs PRIVATE -Wno-suggest-attribute=format)
12-
target_compile_options(tinyxml2_objs PRIVATE -Wno-useless-cast)
9+
target_compile_options(tinyxml2 PRIVATE -Wno-suggest-attribute=format)
10+
target_compile_options(tinyxml2 PRIVATE -Wno-useless-cast)
1311
endif()
1412
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
15-
target_compile_options_safe(tinyxml2_objs -Wno-implicit-fallthrough)
16-
target_compile_options_safe(tinyxml2_objs -Wno-suggest-destructor-override)
17-
target_compile_options_safe(tinyxml2_objs -Wno-zero-as-null-pointer-constant)
18-
target_compile_options_safe(tinyxml2_objs -Wno-format-nonliteral)
19-
target_compile_options_safe(tinyxml2_objs -Wno-inconsistent-missing-destructor-override)
13+
target_compile_options_safe(tinyxml2 -Wno-implicit-fallthrough)
14+
target_compile_options_safe(tinyxml2 -Wno-suggest-destructor-override)
15+
target_compile_options_safe(tinyxml2 -Wno-zero-as-null-pointer-constant)
16+
target_compile_options_safe(tinyxml2 -Wno-format-nonliteral)
17+
target_compile_options_safe(tinyxml2 -Wno-inconsistent-missing-destructor-override)
2018
endif()
2119
if(CYGWIN)
2220
target_compile_definitions(-D_LARGEFILE_SOURCE) # required for fseeko() and ftello()
2321
endif()
2422

23+
target_include_directories(tinyxml2 PUBLIC .)
24+

frontend/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
file(GLOB hdrs "*.h")
22
file(GLOB srcs "*.cpp")
33

4-
add_library(frontend_objs OBJECT ${hdrs} ${srcs})
5-
target_include_directories(frontend_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib)
4+
add_library(frontend OBJECT ${hdrs} ${srcs})
5+
target_include_directories(frontend PUBLIC .)
6+
target_link_libraries(frontend PRIVATE cppcheck-core)

gui/CMakeLists.txt

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,26 @@ CheckOptions:
2020
list(APPEND cppcheck-gui-deps ${hdrs} ${uis_hdrs} ${resources} ${qms})
2121
add_custom_target(gui-build-deps SOURCES ${cppcheck-gui-deps})
2222

23-
list(APPEND cppcheck-gui_SOURCES ${srcs} $<TARGET_OBJECTS:frontend_objs>)
24-
if (NOT BUILD_CORE_DLL)
25-
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
26-
if(USE_BUNDLED_TINYXML2)
27-
list(APPEND cppcheck-gui_SOURCES $<TARGET_OBJECTS:tinyxml2_objs>)
28-
endif()
29-
endif()
23+
list(APPEND cppcheck-gui_SOURCES ${srcs})
3024
if (WIN32)
3125
list(APPEND cppcheck-gui_SOURCES cppcheck-gui.rc)
3226
endif()
3327

3428
add_executable(cppcheck-gui ${cppcheck-gui-deps} ${cppcheck-gui_SOURCES})
29+
target_link_libraries(frontend_objs cppcheck-core simplecpp tinyxml2 picojson)
30+
3531
set_target_properties(cppcheck-gui PROPERTIES AUTOMOC ON)
3632
set_target_properties(cppcheck-gui PROPERTIES WIN32_EXECUTABLE ON)
37-
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/frontend/)
38-
if(USE_BUNDLED_TINYXML2)
39-
target_externals_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
40-
else()
41-
target_include_directories(cppcheck-gui SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
42-
endif()
43-
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
4433
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
4534
target_precompile_headers(cppcheck-gui PRIVATE precompiled.h)
4635
endif()
4736
if (HAVE_RULES)
4837
target_link_libraries(cppcheck-gui ${PCRE_LIBRARY})
4938
endif()
50-
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
51-
target_link_libraries(cppcheck-gui ${tinyxml2_LIBRARIES})
52-
endif()
5339
target_link_libraries(cppcheck-gui ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_PRINTSUPPORT_LIB} ${QT_HELP_LIB} ${QT_NETWORK_LIB})
5440
if(WITH_QCHART)
5541
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
5642
endif()
57-
if (BUILD_CORE_DLL)
58-
target_compile_definitions(cppcheck-gui PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
59-
target_link_libraries(cppcheck-gui cppcheck-core)
60-
endif()
6143
if(MSVC)
6244
# compilation will fail as e.g. QList::realloc would be replaced by MSVC's macro definition
6345
target_compile_definitions(cppcheck-gui PRIVATE $<$<CONFIG:Debug>:DISABLE_CRTDBG_MAP_ALLOC>)

gui/test/xmlreportv2/CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
qt_wrap_cpp(test-xmlreportv2_SRC testxmlreportv2.h)
22
add_custom_target(build-xmlreportv2-deps SOURCES ${test-xmlreportv2_SRC})
33
add_dependencies(gui-build-deps build-xmlreportv2-deps)
4-
if (NOT BUILD_CORE_DLL)
5-
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:cppcheck-core> $<TARGET_OBJECTS:simplecpp_objs>)
6-
if(USE_BUNDLED_TINYXML2)
7-
list(APPEND test-xmlreportv2_SRC $<TARGET_OBJECTS:tinyxml2_objs>)
8-
endif()
9-
endif()
104
add_executable(test-xmlreportv2
115
${test-xmlreportv2_SRC}
126
testxmlreportv2.cpp
@@ -17,17 +11,13 @@ add_executable(test-xmlreportv2
1711
)
1812
target_include_directories(test-xmlreportv2 PRIVATE ${CMAKE_SOURCE_DIR}/gui ${CMAKE_SOURCE_DIR}/lib)
1913
target_compile_definitions(test-xmlreportv2 PRIVATE SRCDIR="${CMAKE_CURRENT_SOURCE_DIR}")
20-
target_link_libraries(test-xmlreportv2 ${QT_CORE_LIB} ${QT_TEST_LIB})
14+
target_link_libraries(test-xmlreportv2 ${QT_CORE_LIB} ${QT_TEST_LIB} cppcheck-core)
2115
if (HAVE_RULES)
2216
target_link_libraries(test-xmlreportv2 ${PCRE_LIBRARY})
2317
endif()
2418
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
2519
target_link_libraries(test-xmlreportv2 ${tinyxml2_LIBRARIES})
2620
endif()
27-
if (BUILD_CORE_DLL)
28-
target_compile_definitions(test-xmlreportv2 PRIVATE CPPCHECKLIB_IMPORT TINYXML2_IMPORT)
29-
target_link_libraries(test-xmlreportv2 cppcheck-core)
30-
endif()
3121
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
3222
if(QT_VERSION VERSION_LESS "6.0.0")
3323
# Q_UNUSED() in generated code - see https://bugreports.qt.io/browse/QTBUG-82978

lib/CMakeLists.txt

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,20 @@ else()
3737
set(srcs_lib ${srcs})
3838
endif()
3939

40-
if (BUILD_CORE_DLL)
41-
add_library(cppcheck-core SHARED ${srcs_lib} ${hdrs} $<TARGET_OBJECTS:tinyxml2_objs> $<TARGET_OBJECTS:simplecpp_objs> version.rc)
42-
target_compile_definitions(cppcheck-core PRIVATE CPPCHECKLIB_EXPORT TINYXML2_EXPORT SIMPLECPP_EXPORT)
43-
else()
44-
add_library(cppcheck-core OBJECT ${srcs_lib} ${hdrs})
45-
endif()
46-
target_externals_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/)
47-
if(USE_BUNDLED_TINYXML2)
48-
target_externals_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
49-
else()
50-
target_include_directories(cppcheck-core SYSTEM PRIVATE ${tinyxml2_INCLUDE_DIRS})
40+
add_library(cppcheck-core ${srcs_lib} ${hdrs})
41+
target_dll_compile_definitions(simplecpp_objs CPPCHECKLIB_EXPORT CPPCHECKLIB_IMPORT)
42+
if (BUILD_SHARED_LIBS AND MSVC)
43+
target_sources(cppcheck-core PRIVATE version.rc)
5144
endif()
52-
target_externals_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
53-
target_externals_include_directories(cppcheck-core PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
45+
46+
target_include_directories(cppcheck-core PUBLIC .)
47+
target_link_libraries(cppcheck-core PRIVATE tinyxml2 simplecpp picojson)
48+
5449
if (HAVE_RULES)
5550
target_include_directories(cppcheck-core SYSTEM PRIVATE ${PCRE_INCLUDE})
5651
endif()
5752
if (Boost_FOUND)
58-
target_include_directories(cppcheck-core SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
53+
target_include_directories(cppcheck-core SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
5954
endif()
6055

6156
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)

0 commit comments

Comments
 (0)