Skip to content

Commit

Permalink
refactor:生成动态库由变量BUILD_SHARED_LIBS控制,默认动态链接
Browse files Browse the repository at this point in the history
  • Loading branch information
s12mmm3 committed Feb 10, 2024
1 parent afd611b commit 2b5a578
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ project(QCloudMusicApiProject VERSION 1.0)
# C++标准
set(CMAKE_CXX_STANDARD 17)

# 生成动态库
set(BUILD_SHARED_LIBS ON)

# set default output path
if(NOT ANDROID)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/bin)
Expand Down
10 changes: 6 additions & 4 deletions QCloudMusicApi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(BUILD_SHARED_LIBS ON)
# Provides dependency openssl
#find_package(OpenSSL QUIET)
if(NOT OPENSSL_FOUND)
Expand All @@ -33,14 +32,17 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Network)

FILE(GLOB HEADERS ./*.h ./util/*.h)
FILE(GLOB SOURCES ./*.cpp ./util/*.cpp)
add_library(QCloudMusicApi SHARED
add_library(${PROJECT_NAME}
${HEADERS}
${SOURCES}
)

target_link_libraries(QCloudMusicApi Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Network ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})

target_compile_definitions(QCloudMusicApi PRIVATE QCLOUDMUSICAPI_LIBRARY)
target_compile_definitions(${PROJECT_NAME} PRIVATE QCLOUDMUSICAPI_LIBRARY)
if(BUILD_SHARED_LIBS)
target_compile_definitions(${PROJECT_NAME} PRIVATE BUILD_SHARED_LIBS)
endif()

set(PUBLIC_HEADERS
module.h
Expand Down
4 changes: 4 additions & 0 deletions QCloudMusicApi/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
#define Q_DECL_IMPORT __attribute__((visibility("default")))
#endif

#if defined(BUILD_SHARED_LIBS)
#if defined(QCLOUDMUSICAPI_LIBRARY)
# define QCLOUDMUSICAPI_EXPORT Q_DECL_EXPORT
#else
# define QCLOUDMUSICAPI_EXPORT Q_DECL_IMPORT
#endif
#else
# define QCLOUDMUSICAPI_EXPORT
#endif

class QCLOUDMUSICAPI_EXPORT NeteaseCloudMusicApi: public QObject {
Q_OBJECT
Expand Down

0 comments on commit 2b5a578

Please sign in to comment.