Skip to content

Commit

Permalink
refactor:更新CMakeLists.txt,增加是否编译测试程序、HttpServer的选项;
Browse files Browse the repository at this point in the history
需要重新CMake
  • Loading branch information
s12mmm3 committed Mar 2, 2024
1 parent 8db43c0 commit 7415897
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
4 changes: 3 additions & 1 deletion CApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE CAPI_LIBRARY)
set(PUBLIC_HEADERS
capi.h
)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_HEADER_OUTPUT_DIRECTORY})
if(MUSICAPI_SETOUTPUTPATH)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_HEADER_OUTPUT_DIRECTORY})
endif()
42 changes: 27 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,43 @@ project(QCloudMusicApiProject VERSION 1.0)

set(CMAKE_CXX_STANDARD 17)

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

# 生成动态库
set(BUILD_SHARED_LIBS ON)

# set default output path
if(NOT ANDROID AND NOT IOS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_HEADER_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/include)
else()
if(MUSICAPI_SETOUTPUTPATH)
# set default output path
if(NOT ANDROID AND NOT IOS)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib)
set(CMAKE_HEADER_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/include)

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

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

find_package(QT NAMES Qt6 Qt5)
find_package(Qt${QT_VERSION_MAJOR})
if(NOT ANDROID AND NOT IOS)
add_subdirectory(CApi)
if(MUSICAPI_CAPI)
add_subdirectory(CApi)
endif()
find_package(QT NAMES Qt6 Qt5)
find_package(Qt${QT_VERSION_MAJOR})
if(${QT_VERSION} VERSION_GREATER 6.4.0)
add_subdirectory(ApiServer)
# Qt6.4后才支持QHttpServer库
if(MUSICAPI_SERVER)
add_subdirectory(ApiServer)
endif()
endif()
endif()

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

6 changes: 5 additions & 1 deletion QCloudMusicApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Provides dependency openssl
option( WITH_APPS "Build applications" OFF )
#find_package(OpenSSL QUIET)
if(NOT OPENSSL_FOUND)
add_subdirectory(
Expand Down Expand Up @@ -47,4 +48,7 @@ endif()
set(PUBLIC_HEADERS
module.h
)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_HEADER_OUTPUT_DIRECTORY})

if(MUSICAPI_SETOUTPUTPATH)
install(FILES ${PUBLIC_HEADERS} DESTINATION ${CMAKE_HEADER_OUTPUT_DIRECTORY})
endif()

0 comments on commit 7415897

Please sign in to comment.