Skip to content

Commit

Permalink
app
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoth committed Aug 21, 2023
1 parent 327192e commit 187de9d
Show file tree
Hide file tree
Showing 34 changed files with 418 additions and 3,186 deletions.
17 changes: 0 additions & 17 deletions .gitattributes

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
build*/
/[Bb]uild*/

.vscode/
.vs/
.DS_store

html/
latex/

*.lnk
CMakeLists.txt.user
133 changes: 38 additions & 95 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,43 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

# 添加版本号
set(PROJECT_VERSION_MAJOR 0) # 主版本号
set(PROJECT_VERSION_MINOR 1) # 子版本号
set(PROJECT_VERSION_MINOR 0) # 子版本号
set(PROJECT_VERSION_PATCH 1) # 阶段版本号
string(TIMESTAMP PROJECT_VERSION_TIME %y%m%d) # 日期版本号
set(PROJECT_VERSION_ALPHABET "alpha") # 希腊字母版本号
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TIME})
set(PROJECT_VERSION_TWEAK 0) # build
set(PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}.${PROJECT_VERSION_TWEAK})
set(PROJECT_DESCRIPTION "hello cmake")
set(PROJECT_HOMEPAGE_URL "https://zmoth.top")

# 工程名称
project(dlldemo VERSION ${PROJECT_VERSION})
message(STATUS "${PROJECT_NAME} v${PROJECT_VERSION}")

# 判断是否作为第三方库
get_directory_property(_has_parent PARENT_DIRECTORY)
if(_has_parent)
set(is_root_project OFF)
else()
set(is_root_project ON)
endif()
project(
showlogo
VERSION ${PROJECT_VERSION}
DESCRIPTION ${PROJECT_DESCRIPTION}
HOMEPAGE_URL ${PROJECT_HOMEPAGE_URL}
LANGUAGES CXX
)

set(PROJECT_DEVELOPER_DEFAULTS
"${is_root_project}"
CACHE BOOL "Turns on default settings for development")
message(STATUS "[${PROJECT_NAME}] Project ${PROJECT_NAME} v${PROJECT_VERSION}")

option(BUILD_TESTING "Build tests" "${PROJECT_DEVELOPER_DEFAULTS}")
option(BUILD_EXAMPLES "Build Examples" "${PROJECT_DEVELOPER_DEFAULTS}")
option(BUILD_DOCS "Build Documentation" "${PROJECT_DEVELOPER_DEFAULTS}")
# 选项
option(BUILD_DEBUG_POSTFIX_D "Append d suffix to debug libraries" ON)

# 加入一个配置头文件,用于处理 CMake 对源码的设置
configure_file("${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_BINARY_DIR}/config.h")

# 设置输出路径
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # 静态库的文件夹位置
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) # 动态库的文件夹位置
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # 可执行软件的文件夹位置
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set(CMAKE_DISABLE_SOURCE_CHANGES ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/Debug)
# Compiler set
message(STATUS "[${PROJECT_NAME}] C++ compiler ID is: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "[${PROJECT_NAME}] cmake system is: ${CMAKE_SYSTEM_NAME}")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib/Release)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib/Release)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/Release)
# qt
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

# 后缀
if(BUILD_DEBUG_POSTFIX_D)
# 这个就是定义各个版本对应的后缀,例如d,debug版本后缀,当然你想定义为其他,自己修改这块就可以了。
set(CMAKE_DEBUG_POSTFIX "d")
Expand All @@ -53,71 +46,21 @@ if(BUILD_DEBUG_POSTFIX_D)
set(CMAKE_MINSIZEREL_POSTFIX "s")
endif()

include_directories(${PROJECT_BINARY_DIR}) # config.h
include(GNUInstallDirs)

# add_subdirectory(3rdparty) # 添加第三方库
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "[${PROJECT_NAME}] Project will be installed to ${CMAKE_INSTALL_PREFIX}")
message(STATUS "[${PROJECT_NAME}] Project is top? ${PROJECT_IS_TOP_LEVEL}")

# qt
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) # 识别是Qt6还是Qt5
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
message(STATUS "QT_VERSION: ${QT_VERSION}; QT_DIR: ${QT_DIR}")

if(${QT_VERSION} VERSION_LESS 5.15.2)
message(FATAL_ERROR "Requires qt version >= 5.15.2, Your current version is ${QT_VERSION}")
endif()

file(GLOB_RECURSE SRCS src/*.cpp src/*.cxx src/*.cc)
file(GLOB_RECURSE INCS src/*.hpp src/*.h)
file(GLOB_RECURSE RES src/*.qrc src/*.rc src/*.ui)

set(PROJECT_SOURCES ${SRCS} ${INCS} ${RES})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) # data

# 制作动态库
add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES})
# add_subdirectory(3rdparty) # 第三方库
add_subdirectory(src) # 主程序

# 支持动态库和静态库同时存在
set_target_properties(${PROJECT_NAME} PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# 设置头文件路径
target_include_directories(
${PROJECT_NAME}
PUBLIC $<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/demo/internal>)
# install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
# install(DIRECTORY examples DESTINATION .)
# install(FILES ${CMAKE_SOURCE_DIR}/LICENSE.txt DESTINATION .)

# 编译选项
target_compile_definitions(
${PROJECT_NAME}
PUBLIC PROJECT_DLL_SHARED
PRIVATE PROJECT_DLL_EXPORTS
# QT_NO_DEBUG_OUTPUT
QT_NO_KEYWORDS)

target_compile_options(
${PROJECT_NAME}
PRIVATE $<$<CXX_COMPILER_ID:MSVC>:/W4 /wd4127 /EHsc /utf-8> $<$<C_COMPILER_ID:MSVC>:/utf-8>
$<$<CXX_COMPILER_ID:GNU>:-Wall -Wextra> $<$<CXX_COMPILER_ID:AppleClang>:-Wall -Wextra -Werror>)

if(NOT "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
# Clang-Cl on MSVC identifies as "Clang" but behaves more like MSVC:
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CXX_COMPILER_ID:Clang>:-Wall -Wextra>)
endif()

install(
TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION CMAKE_RUNTIME_OUTPUT_DIRECTORY
LIBRARY DESTINATION CMAKE_LIBRARY_OUTPUT_DIRECTORY
ARCHIVE DESTINATION CMAKE_ARCHIVE_OUTPUT_DIRECTORY
BUNDLE DESTINATION CMAKE_RUNTIME_OUTPUT_DIRECTORY)

if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# Pack
include(${CMAKE_SOURCE_DIR}/cmake/CPack.cmake)
Loading

0 comments on commit 187de9d

Please sign in to comment.