Skip to content

Commit

Permalink
perf: Minimum support c++ standard 11
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoth committed Oct 23, 2023
1 parent 9afed48 commit 7058e5c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
43 changes: 23 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
cmake_minimum_required(VERSION 3.15)

# 添加版本号
# 添加版本号信息
set(PROJECT_VERSION_MAJOR 0) # 主版本号
set(PROJECT_VERSION_MINOR 1) # 子版本号
set(PROJECT_VERSION_PATCH 0) # 阶段版本号
set(PROJECT_VERSION_TWEAK 0) # build
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK})
set(PROJECT_VERSION_PATCH 0) # 补丁版本号
set(PROJECT_VERSION_TWEAK 0) # 修订号,预发布版本

# 设置版本号
if(${PROJECT_VERSION_TWEAK} EQUAL 0)
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
else()
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK})
endif()

set(PROJECT_DESCRIPTION "Qt Json Schema Form.")
set(PROJECT_HOMEPAGE_URL "https://zmoth.top")

Expand All @@ -18,23 +25,14 @@ project(
LANGUAGES CXX
)

message(STATUS "[${PROJECT_NAME}] Project ${PROJECT_NAME} v${PROJECT_VERSION}")

message(STATUS "[${PROJECT_NAME}] C++ compiler ID is: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "[${PROJECT_NAME}] cmake system is: ${CMAKE_SYSTEM_NAME}")
message(STATUS "[${PROJECT_NAME}] install默认安装位置: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "[${PROJECT_NAME}] 此CMakeLists.txt是否是顶层 ${PROJECT_IS_TOP_LEVEL}")
set(CMAKE_CXX_STANDARD 11)

# 选项
option(BUILD_EXAMPLES "是否编译例程" ${PROJECT_IS_TOP_LEVEL})
option(BUILD_DEBUG_POSTFIX_D "是否需要添加后缀以区分是debug还是release" ${PROJECT_IS_TOP_LEVEL})

# 如果此项目作为其他项目的第三方库,以下的配置不生效
if(PROJECT_IS_TOP_LEVEL)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)

# 设置输出路径
include(GNUInstallDirs)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}) # 静态库的文件夹位置
Expand All @@ -51,6 +49,12 @@ if(PROJECT_IS_TOP_LEVEL)
endif()
endif()

message(STATUS "[${PROJECT_NAME}] Project ${PROJECT_NAME} v${PROJECT_VERSION}")
message(STATUS "[${PROJECT_NAME}] C++ compiler ID is: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "[${PROJECT_NAME}] cmake system is: ${CMAKE_SYSTEM_NAME}")
message(STATUS "[${PROJECT_NAME}] install默认安装位置: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "[${PROJECT_NAME}] 此CMakeLists.txt是否是顶层 ${PROJECT_IS_TOP_LEVEL}")

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

Expand Down Expand Up @@ -114,11 +118,10 @@ set_target_properties(
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}
)

target_compile_options(
${PROJECT_NAME}
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/utf-8>
PRIVATE $<$<C_COMPILER_ID:MSVC>:/utf-8>
)
# 设置编译器选项
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
target_compile_options(${PROJECT_NAME} PRIVATE /utf-8)
endif()

install(
TARGETS ${PROJECT_NAME}
Expand Down
4 changes: 2 additions & 2 deletions src/QJsonSchemaWidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void QJsonSchemaObject::setOneOf(const QJsonObject &schema)
auto order = schema.find("ui:order")->toArray();
for (auto valueRef : order) {
QString name = valueRef.toString();
if (widgetsMap.contains(name)) {
if (widgetsMap.count(name)) {
layout->addRow(widgetsMap[name].first, widgetsMap[name].second);
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ void QJsonSchemaObject::setValue(const QJsonObject &json)
}

for (const auto &key : json.keys()) {
if (widgetsMap.contains(key)) {
if (widgetsMap.count(key)) {
QJsonSchemaWidgetsFactory::setValue(widgetsMap[key].second, json[key]);
}
}
Expand Down

0 comments on commit 7058e5c

Please sign in to comment.