option(LIBIPC_BUILD_SHARED_LIBS 'Build shared libraries (DLLs).' OFF)

This commit is contained in:
mutouyun 2021-07-10 13:50:46 +08:00
parent 57e5298006
commit cca4664e84
3 changed files with 24 additions and 12 deletions

View File

@ -44,9 +44,11 @@
*/ */
#ifndef IPC_EXPORT #ifndef IPC_EXPORT
#if defined(__IPC_LIBRARY__) #if defined(LIBIPC_LIBRARY_SHARED_BUILDING__)
# define IPC_EXPORT IPC_DECL_EXPORT # define IPC_EXPORT IPC_DECL_EXPORT
#else #elif defined(LIBIPC_LIBRARY_SHARED_USING__)
# define IPC_EXPORT IPC_DECL_IMPORT # define IPC_EXPORT IPC_DECL_IMPORT
#else
# define IPC_EXPORT
#endif #endif
#endif /*IPC_EXPORT*/ #endif /*IPC_EXPORT*/

View File

@ -1,6 +1,6 @@
project(ipc) project(ipc)
add_compile_options(-D__IPC_LIBRARY__) option(LIBIPC_BUILD_SHARED_LIBS "Build shared libraries (DLLs)." OFF)
if(NOT MSVC) if(NOT MSVC)
add_compile_options(-fPIC) add_compile_options(-fPIC)
@ -26,7 +26,17 @@ file(GLOB HEAD_FILES
${LIBIPC_PROJECT_DIR}/src/libipc/platform/*.h ${LIBIPC_PROJECT_DIR}/src/libipc/platform/*.h
${LIBIPC_PROJECT_DIR}/src/libipc/utility/*.h) ${LIBIPC_PROJECT_DIR}/src/libipc/utility/*.h)
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES}) if (LIBIPC_BUILD_SHARED_LIBS)
add_library(${PROJECT_NAME} SHARED ${SRC_FILES} ${HEAD_FILES})
target_compile_definitions(${PROJECT_NAME}
INTERFACE
LIBIPC_LIBRARY_SHARED_USING__
PRIVATE
LIBIPC_LIBRARY_SHARED_BUILDING__)
else()
add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${HEAD_FILES})
endif()
if(NOT MSVC) if(NOT MSVC)
target_link_libraries(${PROJECT_NAME} PUBLIC target_link_libraries(${PROJECT_NAME} PUBLIC
pthread pthread