From 6e148cc1058d79e9ed9f56a78fed6de6471c8815 Mon Sep 17 00:00:00 2001 From: renbin Date: Thu, 28 Nov 2024 13:20:56 +0800 Subject: [PATCH] chore: format cmakelists.txt As title. Log: Format CMakeLists.txt --- CMakeLists.txt | 12 ++-- src/deb-installer/CMakeLists.txt | 100 +++++++++++++++---------------- tests/CMakeLists.txt | 85 +++++++++++++------------- 3 files changed, 100 insertions(+), 97 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7861abe..4423cedd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,11 @@ cmake_minimum_required(VERSION 3.13) -if (NOT DEFINED VERSION) +if(NOT DEFINED VERSION) set(VERSION 5.3.9) -endif () +endif() -#安全测试的开关 +# 安全测试的开关 set(CMAKE_SAFETYTEST OFF) project(deepin_deb_installer) @@ -18,10 +18,12 @@ find_package(Qt5LinguistTools REQUIRED) set(POLICY_FILE com.deepin.pkexec.aptInstallDepend.policy) add_subdirectory(src/AptInstallDepend) add_subdirectory(src/deb-installer) -if (CMAKE_BUILD_TYPE STREQUAL "Debug") + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_subdirectory(tests) endif() + add_subdirectory(src/deepin-deb-installer-dev) add_subdirectory(translations) -#add_subdirectory(tests/FuzzyTest) +# add_subdirectory(tests/FuzzyTest) diff --git a/src/deb-installer/CMakeLists.txt b/src/deb-installer/CMakeLists.txt index 33e64a82..375d3bdf 100644 --- a/src/deb-installer/CMakeLists.txt +++ b/src/deb-installer/CMakeLists.txt @@ -3,16 +3,17 @@ # SPDX-License-Identifier: CC0-1.0 cmake_minimum_required(VERSION 3.7) -if (NOT DEFINED VERSION) + +if(NOT DEFINED VERSION) message(WARNING "Not defined version ,about dialog version set 5.3.9") set(VERSION 5.3.9) -endif () +endif() -#检查qapt版本 +# 检查qapt版本 execute_process(COMMAND dpkg -s libqapt-dev - COMMAND grep Version - TIMEOUT 5 - OUTPUT_VARIABLE QAPT_VERSION_STR) + COMMAND grep Version + TIMEOUT 5 + OUTPUT_VARIABLE QAPT_VERSION_STR) string(REPLACE "Version: " "" QAPT_VERSION_STR ${QAPT_VERSION_STR}) message(STATUS "BUILD QAPT VERSION ${QAPT_VERSION_STR}") @@ -33,7 +34,7 @@ else() endif() endif() -#common resource names +# common resource names set(APP_RES_DIR "${CMAKE_SOURCE_DIR}/assets") set(APP_BIN_NAME "deepin-deb-installer") set(APP_TRANS_SCRIPT "${APP_RES_DIR}/translate_generation.sh") @@ -56,63 +57,62 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-strong -D_FORTITY_SOURCE=1 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -D_FORTITY_SOURCE=1 -z noexecstack -pie -fPIC -z lazy") if(CMAKE_COVERAGE_ARG STREQUAL "CMAKE_COVERAGE_ARG_ON") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage") endif() -#安全测试加固编译参数 +# 安全测试加固编译参数 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -z relro -z now -z noexecstack -pie") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z relro -z now -z noexecstack -pie") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") -if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64") +if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mieee") -endif () - -#compile flags -if (CMAKE_BUILD_TYPE MATCHES Debug) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra") - - # Enable Qt builtin debug mode - add_definitions("-DQT_MESSAGELOGCONTEXT") - - # 添加宏定义只在debug模式下输出性能打点日志 - add_definitions("-DDEBUG") - - if(CMAKE_SAFETYTEST) - #安全测试选项 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=undefined,address -O2") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined,address -O2") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -g -fsanitize=undefined,address -O2") - set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -g -fsanitize=undefined,address -O2") - set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -g -fsanitize=undefined,address -O2") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=undefined,address -O2") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined,address -O2") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fsanitize=undefined,address -O2") - set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -g -fsanitize=undefined,address -O2") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g -fsanitize=undefined,address -O2") - endif() +endif() -else() - # -Wl, -O2 Enable linker optimizations - # -Wl, --gc-sections Remove unused code resulting from -fdsta-sections and - # -ffunction-sections - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2 -Wl,-O1 -Wl,--gc-sections") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -O2 -Wl,-O1 -Wl,--gc-sections") +# compile flags +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra") + + # Enable Qt builtin debug mode + add_definitions("-DQT_MESSAGELOGCONTEXT") + + # 添加宏定义只在debug模式下输出性能打点日志 + add_definitions("-DDEBUG") + + if(CMAKE_SAFETYTEST) + # 安全测试选项 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=undefined,address -O2") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=undefined,address -O2") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -g -fsanitize=undefined,address -O2") + set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -g -fsanitize=undefined,address -O2") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -g -fsanitize=undefined,address -O2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=undefined,address -O2") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=undefined,address -O2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -fsanitize=undefined,address -O2") + set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -g -fsanitize=undefined,address -O2") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -g -fsanitize=undefined,address -O2") + endif() +else() + # -Wl, -O2 Enable linker optimizations + # -Wl, --gc-sections Remove unused code resulting from -fdsta-sections and + # -ffunction-sections + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O2 -Wl,-O1 -Wl,--gc-sections") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -O2 -Wl,-O1 -Wl,--gc-sections") endif() -#Generate the qm file +# Generate the qm file execute_process(COMMAND bash ${APP_TRANS_SCRIPT} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/") + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/") configure_file(${APP_RES_DIR}/environments.h.in environments.h @ONLY) add_definitions(-DUSE_POLKIT -DENABLE_INACTIVE_DISPLAY) -# Find the library +# Find the library find_package(PkgConfig REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5Gui REQUIRED) @@ -139,11 +139,13 @@ set(LINK_LIBS macro(SUBDIRLIST result curdir) file(GLOB children RELATIVE ${curdir} ${curdir}/*) set(dirlist "") + foreach(child ${children}) if(IS_DIRECTORY ${curdir}/${child}) LIST(APPEND dirlist ${child}) endif() endforeach() + set(${result} ${dirlist}) endmacro() @@ -151,7 +153,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) SUBDIRLIST(all_src ${CMAKE_CURRENT_SOURCE_DIR}) -#Include all app own subdirectorys +# Include all app own subdirectorys foreach(subdir ${all_src}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}${subdir}) endforeach() @@ -160,7 +162,7 @@ include_directories(${CMAKE_CURRENT_LIST_DIR}/utils) file(GLOB_RECURSE APP_SRCS ${CMAKE_CURRENT_LIST_DIR}/*.h ${CMAKE_CURRENT_LIST_DIR}/*.cpp - ) +) include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) @@ -191,5 +193,3 @@ install(FILES ${APP_CONFIG} DESTINATION share/deepin-deb-installer) install(FILES ${APP_DESKTOP} DESTINATION share/applications) install(FILES ${APP_MIME} DESTINATION share/mime/packages) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/dbus/com.deepin.DebInstaller.service DESTINATION share/dbus-1/services/) - - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5e44d3e3..ae1d96bc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,14 +3,16 @@ # SPDX-License-Identifier: CC0-1.0 cmake_minimum_required(VERSION 3.7) -if (NOT DEFINED VERSION) + +if(NOT DEFINED VERSION) message(WARNING "Not defined version ,about dialog version set 5.3.9") set(VERSION 5.3.9) -endif () +endif() find_package(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIRS}) -#common resource names + +# common resource names set(APP_RES_DIR "${CMAKE_SOURCE_DIR}/assets") set(APP_BIN_NAME_TEST "deepin-deb-installer-test") set(APP_TRANS_SCRIPT "${APP_RES_DIR}/translate_generation.sh") @@ -19,7 +21,6 @@ set(APP_QRC "${APP_RES_DIR}/resources.qrc") project(${APP_BIN_NAME_TEST}) - ADD_COMPILE_OPTIONS(-fno-access-control) set(CMAKE_VERBOSE_MAKEFILE ON) @@ -31,15 +32,15 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--as-need -fPIE") set(CMAKE_EXE_LINKER_FLAGS "-pie") -#安全测试加固编译参数 +# 安全测试加固编译参数 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -z relro -z now -z noexecstack -pie") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z relro -z now -z noexecstack -pie") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-all") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector-all") -if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64") +if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "sw_64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mieee") -endif () +endif() set(CMAKE_SAFETYTEST "${CMAKE_SAFETYTEST_ARG}") @@ -50,39 +51,39 @@ endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${CMAKE_SAFETYTEST}") if(CMAKE_SAFETYTEST STREQUAL "CMAKE_SAFETYTEST_ARG_ON") - #安全测试选项 - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=undefined,address -O2") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=undefined,address -O2") + # 安全测试选项 + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=undefined,address -O2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=undefined,address -O2") endif() -#compile flags -if (CMAKE_BUILD_TYPE MATCHES Debug) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra") +# compile flags +if(CMAKE_BUILD_TYPE MATCHES Debug) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra") - # Enable Qt builtin debug mode - add_definitions("-DQT_MESSAGELOGCONTEXT") + # Enable Qt builtin debug mode + add_definitions("-DQT_MESSAGELOGCONTEXT") else() - # -Wl, -O2 Enable linker optimizations - # -Wl, --gc-sections Remove unused code resulting from -fdsta-sections and - # -ffunction-sections - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2 -Wl,-O1 -Wl,--gc-sections") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -Wl,-O1 -Wl,--gc-sections") + # -Wl, -O2 Enable linker optimizations + # -Wl, --gc-sections Remove unused code resulting from -fdsta-sections and + # -ffunction-sections + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O2 -Wl,-O1 -Wl,--gc-sections") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -Wl,-O1 -Wl,--gc-sections") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fprofile-arcs -ftest-coverage") -#Generate the qm file +# Generate the qm file execute_process(COMMAND bash ${APP_TRANS_SCRIPT} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/") + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/") configure_file(${APP_RES_DIR}/environments.h.in environments.h @ONLY) add_definitions(-DUSE_POLKIT -DENABLE_INACTIVE_DISPLAY) -# Find the library +# Find the library find_package(PkgConfig REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5Gui REQUIRED) @@ -96,7 +97,6 @@ find_package(Qt5DBus REQUIRED) find_package(Qt5Test REQUIRED) find_package(PolkitQt5-1 REQUIRED) - set(LINK_LIBS Qt5::Core Qt5::Widgets @@ -112,11 +112,13 @@ set(LINK_LIBS macro(SUBDIRLIST result curdir) file(GLOB children RELATIVE ${curdir} ${curdir}/*) set(dirlist "") + foreach(child ${children}) if(IS_DIRECTORY ${curdir}/${child}) LIST(APPEND dirlist ${child}) endif() endforeach() + set(${result} ${dirlist}) endmacro() @@ -124,7 +126,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src/deb-installer) SUBDIRLIST(all_src ${CMAKE_CURRENT_SOURCE_DIR}/../src/deb-installer/) -#Include all app own subdirectorys +# Include all app own subdirectorys foreach(subdir ${all_src}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}${subdir}) endforeach() @@ -140,27 +142,26 @@ file(GLOB_RECURSE APP_SRCS ${CMAKE_CURRENT_LIST_DIR}/../src/deb-installer/uab/*.cpp ${CMAKE_CURRENT_LIST_DIR}/../src/deb-installer/compatible/*.cpp ${CMAKE_CURRENT_LIST_DIR}/../src/deb-installer/immutable/*.cpp - ) +) FILE(GLOB allTestSource - src/*.cpp - src/manager/*.cpp - src/model/*.cpp - src/utils/*.cpp - src/view/pages/*.cpp - src/view/widgets/*.cpp - src/uab/*.cpp + src/*.cpp + src/manager/*.cpp + src/model/*.cpp + src/utils/*.cpp + src/view/pages/*.cpp + src/view/widgets/*.cpp + src/uab/*.cpp ) include_directories(src) -include_directories( ${CMAKE_CURRENT_LIST_DIR}/../src/deb-installer/) +include_directories(${CMAKE_CURRENT_LIST_DIR}/../src/deb-installer/) include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) # Tell CMake to create the executable -add_executable(${APP_BIN_NAME_TEST} ${APP_SRCS} ${APP_QRC} ${TEST_ACCESSIBLE_HEADERS_FILES} ${allTestSource} ) +add_executable(${APP_BIN_NAME_TEST} ${APP_SRCS} ${APP_QRC} ${TEST_ACCESSIBLE_HEADERS_FILES} ${allTestSource}) target_include_directories(${APP_BIN_NAME_TEST} PUBLIC ${DtkWidget_INCLUDE_DIRS} ${OBJECT_BINARY_DIR}) - target_link_libraries(${APP_BIN_NAME_TEST} Qt5::Core Qt5::Widgets @@ -178,8 +179,8 @@ target_link_libraries(${APP_BIN_NAME_TEST} pthread ) -#add_custom_target(test -# COMMAND echo " =================== TEST BEGIN ==================== " -# COMMAND ${CMAKE_BINARY_DIR}/tests/${APP_BIN_NAME_TEST} -# COMMAND echo " =================== TEST END ==================== " -#) +# add_custom_target(test +# COMMAND echo " =================== TEST BEGIN ==================== " +# COMMAND ${CMAKE_BINARY_DIR}/tests/${APP_BIN_NAME_TEST} +# COMMAND echo " =================== TEST END ==================== " +# )