use target-specific configuration instead of global ones in CMake (#3534)

This commit is contained in:
Oliver Stöneberg 2021-10-30 09:08:07 +02:00 committed by GitHub
parent 1f5c3670bd
commit b4704ba065
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 35 deletions

View File

@ -1,15 +1,14 @@
include_directories(${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
endif()
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB mainfile "main.cpp")
list(REMOVE_ITEM srcs ${mainfile})
add_library(cli_objs OBJECT ${hdrs} ${srcs})
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
endif()
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:simplecpp_objs>)
if(USE_BUNDLED_TINYXML2)
@ -17,6 +16,11 @@ if(USE_BUNDLED_TINYXML2)
endif()
add_executable(cppcheck ${cppcheck_SOURCES})
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
endif()
target_include_directories(cppcheck PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (HAVE_RULES)
target_link_libraries(cppcheck ${PCRE_LIBRARY})
endif()

View File

@ -11,8 +11,6 @@ if (HAVE_RULES)
find_library(PCRE_LIBRARY pcre)
if (NOT PCRE_LIBRARY OR NOT PCRE_INCLUDE)
message(FATAL_ERROR "pcre dependency for RULES has not been found")
else()
include_directories(${PCRE_INCLUDE})
endif()
endif()
@ -28,11 +26,9 @@ if (USE_Z3)
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)
if (NOT USE_MATCHCOMPILER_OPT MATCHES "Off")
find_package(PythonInterp)

View File

@ -1,6 +1,5 @@
if (BUILD_GUI)
set(CMAKE_AUTOMOC ON)
if (CMAKE_BUILD_TYPE MATCHES "Release")
add_definitions(-DQT_NO_DEBUG)
add_definitions(-DQT_NO_DEBUG_OUTPUT)
@ -9,11 +8,6 @@ if (BUILD_GUI)
add_definitions(-DQT_DEBUG)
endif()
include_directories(${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
endif()
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
file(GLOB uis "*.ui")
@ -27,6 +21,11 @@ if (BUILD_GUI)
endif()
add_executable(cppcheck-gui ${cppcheck-gui_SOURCES})
set_target_properties(cppcheck-gui PROPERTIES AUTOMOC ON)
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(cppcheck-gui PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
endif()
if (HAVE_RULES)
target_link_libraries(cppcheck-gui ${PCRE_LIBRARY})
endif()
@ -57,6 +56,4 @@ if (BUILD_GUI)
install(FILES cppcheck-gui.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
install(FILES cppcheck-gui.png DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/64x64/apps)
set(CMAKE_AUTOMOC OFF)
endif()

View File

@ -1,10 +1,3 @@
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/picojson/)
if(USE_BUNDLED_TINYXML2)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
endif()
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
file(GLOB_RECURSE hdrs "*.h")
file(GLOB_RECURSE srcs "*.cpp")
@ -40,6 +33,19 @@ else()
endif()
add_library(lib_objs OBJECT ${srcs_lib} ${hdrs})
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
endif()
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/picojson/)
target_include_directories(lib_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (HAVE_RULES)
target_include_directories(lib_objs SYSTEM PRIVATE ${PCRE_INCLUDE})
endif()
if (USE_Z3)
target_include_directories(lib_objs SYSTEM PRIVATE ${Z3_CXX_INCLUDE_DIRS})
endif()
if (NOT CMAKE_DISABLE_PRECOMPILE_HEADERS)
target_precompile_headers(lib_objs PRIVATE precompiled.h)
endif()

View File

@ -1,10 +1,4 @@
if (BUILD_TESTS)
include_directories(${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
if(USE_BUNDLED_TINYXML2)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/externals/tinyxml2)
endif()
include_directories(${PROJECT_SOURCE_DIR}/externals/simplecpp/)
file(GLOB hdrs "*.h")
file(GLOB srcs "*.cpp")
list(APPEND testrunner_SOURCES ${hdrs} ${srcs} $<TARGET_OBJECTS:lib_objs> $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:simplecpp_objs>)
@ -13,6 +7,11 @@ if (BUILD_TESTS)
endif()
add_executable(testrunner ${testrunner_SOURCES})
target_include_directories(testrunner PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/cli/)
if(USE_BUNDLED_TINYXML2)
target_include_directories(testrunner PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2)
endif()
target_include_directories(testrunner PRIVATE ${PROJECT_SOURCE_DIR}/externals/simplecpp/)
if (HAVE_RULES)
target_link_libraries(testrunner ${PCRE_LIBRARY})
endif()

View File

@ -1,5 +1,4 @@
if (BUILD_GUI AND BUILD_TESTS)
set(CMAKE_AUTOMOC ON)
if (CMAKE_BUILD_TYPE MATCHES "Release")
add_definitions(-DQT_NO_DEBUG)
add_definitions(-DQT_NO_DEBUG_OUTPUT)
@ -20,7 +19,8 @@ if (BUILD_GUI AND BUILD_TESTS)
${uis_hdrs}
${PROJECT_SOURCE_DIR}/gui/codeeditorstyle.cpp
${PROJECT_SOURCE_DIR}/gui/codeeditor.cpp)
target_include_directories(triage PUBLIC ${PROJECT_SOURCE_DIR}/gui/)
set_target_properties(triage PROPERTIES AUTOMOC ON)
target_include_directories(triage PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/gui/)
target_link_libraries(triage Qt5::Core Qt5::Gui Qt5::Widgets)
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0")
@ -28,6 +28,4 @@ if (BUILD_GUI AND BUILD_TESTS)
target_compile_options(triage PRIVATE -Wno-extra-semi-stmt)
endif()
endif()
set(CMAKE_AUTOMOC OFF)
endif()