Skip to content

Commit

Permalink
refactor: 调整项目的目录格式
Browse files Browse the repository at this point in the history
  • Loading branch information
s12mmm3 committed Oct 26, 2024
1 parent 47d1e10 commit f1fd91c
Show file tree
Hide file tree
Showing 88 changed files with 141 additions and 162 deletions.
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "QCloudMusicApi/openssl-cmake"]
path = QCloudMusicApi/openssl-cmake
[submodule "src/QCloudMusicApi/openssl-cmake"]
path = src/QCloudMusicApi/openssl-cmake
url = https://github.com/janbar/openssl-cmake.git
[submodule "Test/libqrencode"]
path = Test/libqrencode
[submodule "src/Test/libqrencode"]
path = src/Test/libqrencode
url = https://github.com/fukuchi/libqrencode.git
4 changes: 0 additions & 4 deletions ApiServer/logger.cpp

This file was deleted.

49 changes: 13 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,25 @@
cmake_minimum_required(VERSION 3.14)

project(QCloudMusicApiProject VERSION 1.0)
project(QCloudMusicApi VERSION 1.0)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows/Macos")

option(MUSICAPI_TEST "Build Test" ON)
option(MUSICAPI_SERVER "Build ApiServer" ON)
option(MUSICAPI_SETOUTPUTPATH "Set default output path" ON)

if(ANDROID OR IOS)
set(MUSICAPI_SETOUTPUTPATH OFF)
endif()
# 生成动态库
option(BUILD_SHARED_LIBS "Build shared libraries" ON)

if(MUSICAPI_SETOUTPUTPATH)
# set default output path
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${CMAKE_INSTALL_LIBDIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_PDB_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${CMAKE_INSTALL_BINDIR})
set(CMAKE_HEADER_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/include)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE} ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_PDB_OUTPUT_DIRECTORY_${CMAKE_BUILD_TYPE} ${CMAKE_PDB_OUTPUT_DIRECTORY})


# 设置安装前缀为二进制目录
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
endif()

add_subdirectory(QCloudMusicApi)
if(MUSICAPI_TEST)
add_subdirectory(Test)
endif()

find_package(QT NAMES Qt6 Qt5)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS HttpServer)
if(Qt${QT_VERSION_MAJOR}HttpServer_FOUND)
# Qt6.4后才支持QHttpServer库
if(MUSICAPI_SERVER)
add_subdirectory(ApiServer)
endif()
endif()
link_directories(${CMAKE_BINARY_DIR}/lib)

add_subdirectory(src)
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT Test)
55 changes: 0 additions & 55 deletions QCloudMusicApi/CMakeLists.txt

This file was deleted.

4 changes: 0 additions & 4 deletions Test/logger.cpp

This file was deleted.

42 changes: 17 additions & 25 deletions ApiServer/CMakeLists.txt → src/ApiServer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
cmake_minimum_required(VERSION 3.14)

project(ApiServer LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(TARGET_NAME ApiServer)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core HttpServer Network Concurrent)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core HttpServer Network Concurrent)
Expand All @@ -19,40 +10,41 @@ set(PROJECT_SOURCES
${SOURCES}
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(${PROJECT_NAME}
qt_add_executable(${TARGET_NAME}
MANUAL_FINALIZATION
${PROJECT_SOURCES}
)
# Define target properties for Android with Qt 6 as:
# set_property(TARGET ${PROJECT_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# set_property(TARGET ${TARGET_NAME} APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
# ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
if(ANDROID)
add_library(${PROJECT_NAME} SHARED
add_library(${TARGET_NAME} SHARED
${PROJECT_SOURCES}
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
else()
add_executable(${PROJECT_NAME}
add_executable(${TARGET_NAME}
${PROJECT_SOURCES}
)
endif()
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::HttpServer Qt${QT_VERSION_MAJOR}::Network Qt${QT_VERSION_MAJOR}::Concurrent QCloudMusicApi)

target_compile_definitions(${PROJECT_NAME} PRIVATE
PROJECT_NAME="${PROJECT_NAME}"
target_compile_definitions(${TARGET_NAME} PRIVATE
TARGET_NAME="${TARGET_NAME}"
)

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
target_link_libraries(${TARGET_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::HttpServer
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Concurrent
QCloudMusicApi
)

if(QT_VERSION_MAJOR EQUAL 6)
qt_finalize_executable(${PROJECT_NAME})
qt_finalize_executable(${TARGET_NAME})
endif()

install(FILES ${PUBLIC_HEADERS} DESTINATION $<CONFIG>/include/${TARGET_NAME})
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION $<CONFIG>/bin ARCHIVE DESTINATION $<CONFIG>/lib)
File renamed without changes.
4 changes: 4 additions & 0 deletions src/ApiServer/logger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "logger.h"

Q_LOGGING_CATEGORY(LOGGER_NAME, TARGET_NAME)

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/Debug/src)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/Release/src)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/bin/${PROJECT_NAME} CACHE PATH "Specify Install Dir" FORCE)

add_subdirectory(QCloudMusicApi)
if(MUSICAPI_TEST)
add_subdirectory(Test)
endif()
find_package(QT NAMES Qt6 Qt5)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS HttpServer)
if(Qt${QT_VERSION_MAJOR}HttpServer_FOUND)
# Qt6.4后才支持QHttpServer库
if(MUSICAPI_SERVER)
add_subdirectory(ApiServer)
endif()
endif()
57 changes: 57 additions & 0 deletions src/QCloudMusicApi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
set(TARGET_NAME QCloudMusicApi)

# Provides dependency openssl
option( WITH_APPS "Build applications" OFF )
#find_package(OpenSSL QUIET)
if(NOT OPENSSL_FOUND)
add_subdirectory(
${CMAKE_CURRENT_SOURCE_DIR}/openssl-cmake
${CMAKE_CURRENT_BINARY_DIR}/openssl-cmake
EXCLUDE_FROM_ALL
)
set(OPENSSL_SSL_LIBRARY ssl)
set(OPENSSL_CRYPTO_LIBRARY crypto)
set(OPENSSL_INCLUDE_DIR "${openssl_BINARY_DIR}/include" "${openssl_BINARY_DIR}")
set(OPENSSL_FOUND ON)
set(OPENSSL_BUILD_SHARED_LIBS ON)
message(STATUS "Build OpenSSL: ${openssl_BINARY_DIR}")
endif()

set (HAVE_OPENSSL 1)
include_directories (${OPENSSL_INCLUDE_DIR})

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network Gui)

FILE(GLOB HEADERS ./*.h ./util/*.h)
FILE(GLOB SOURCES ./*.cpp ./util/*.cpp)

FILE(GLOB PUBLIC_HEADERS ./*.h)

add_library(${TARGET_NAME}
${HEADERS}
${SOURCES}
)
target_compile_definitions(${TARGET_NAME} PRIVATE
QCLOUDMUSICAPI_LIBRARY
TARGET_NAME="${TARGET_NAME}"
)
target_compile_definitions(${TARGET_NAME} PRIVATE QT_MESSAGELOGCONTEXT)
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")

target_link_libraries(${TARGET_NAME}
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Gui
${OPENSSL_SSL_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
)

if(BUILD_SHARED_LIBS)
target_compile_definitions(${TARGET_NAME} PRIVATE BUILD_SHARED_LIBS)
endif()

install(FILES ${PUBLIC_HEADERS} DESTINATION $<CONFIG>/include/${TARGET_NAME})
install(TARGETS ${TARGET_NAME} RUNTIME DESTINATION $<CONFIG>/bin ARCHIVE DESTINATION $<CONFIG>/lib)
install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG}/ CONFIGURATIONS Debug DESTINATION $<CONFIG>/bin FILES_MATCHING PATTERN *.pdb)
install(DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE}/ CONFIGURATIONS Release DESTINATION $<CONFIG>/bin FILES_MATCHING PATTERN *.pdb)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "logger.h"

namespace QCloudMusicApi {
Q_LOGGING_CATEGORY(LOGGER_NAME, PROJECT_NAME)
Q_LOGGING_CATEGORY(LOGGER_NAME, TARGET_NAME)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f1fd91c

Please sign in to comment.