mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
cmake构建时自动生成mk_export头文件,解决msvc链接设备问题 (#1660)
* 解决msvc下链接问题 * CMAKE添加自动生成mk api export头文件 * 兼容非cmake构建时情况 Co-authored-by: baiyfcu <baiyfcu@gmail.com>
This commit is contained in:
parent
989e7b2e75
commit
e2908e9775
@ -178,7 +178,7 @@ endif ()
|
|||||||
|
|
||||||
configure_file(
|
configure_file(
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/version.h.ini
|
${CMAKE_CURRENT_SOURCE_DIR}/version.h.ini
|
||||||
${CMAKE_BINARY_DIR}/Version.h
|
${CMAKE_BINARY_DIR}/version.h
|
||||||
@ONLY
|
@ONLY
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,30 +1,36 @@
|
|||||||
include_directories(include source)
|
include_directories(include source)
|
||||||
|
include(GenerateExportHeader)
|
||||||
file(GLOB api_src_list include/*.h source/*.cpp source/*.h source/*.c)
|
file(GLOB api_src_list include/*.h source/*.cpp source/*.h source/*.c)
|
||||||
|
|
||||||
if (IOS)
|
if (IOS)
|
||||||
add_library(mk_api STATIC ${api_src_list})
|
add_library(mk_api STATIC ${api_src_list})
|
||||||
target_link_libraries(mk_api ${LINK_LIB_LIST} jsoncpp)
|
target_link_libraries(mk_api ${LINK_LIB_LIST} jsoncpp)
|
||||||
else ()
|
else ()
|
||||||
if(ENABLE_API_STATIC_LIB)
|
if (ENABLE_API_STATIC_LIB)
|
||||||
add_library(mk_api STATIC ${api_src_list})
|
add_library(mk_api STATIC ${api_src_list})
|
||||||
if (WIN32)
|
|
||||||
add_definitions(-DMediaKitApi_STATIC)
|
|
||||||
endif ()
|
|
||||||
else ()
|
else ()
|
||||||
add_library(mk_api SHARED ${api_src_list})
|
add_library(mk_api SHARED ${api_src_list})
|
||||||
if (WIN32)
|
endif ()
|
||||||
add_definitions(-DMediaKitApi_EXPORTS)
|
|
||||||
endif ()
|
|
||||||
endif()
|
|
||||||
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||||
target_link_libraries(mk_api -Wl,--start-group jsoncpp ${LINK_LIB_LIST} -Wl,--end-group)
|
target_link_libraries(mk_api -Wl,--start-group jsoncpp ${LINK_LIB_LIST} -Wl,--end-group)
|
||||||
else ()
|
else ()
|
||||||
target_link_libraries(mk_api jsoncpp ${LINK_LIB_LIST})
|
target_link_libraries(mk_api jsoncpp ${LINK_LIB_LIST})
|
||||||
endif ()
|
endif ()
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
|
endif ()
|
||||||
|
|
||||||
file(GLOB api_header_list include/*.h)
|
add_definitions(-DGENERATE_EXPORT)
|
||||||
|
include_directories(${CMAKE_BINARY_DIR})
|
||||||
|
generate_export_header(mk_api
|
||||||
|
EXPORT_MACRO_NAME API_EXPORT
|
||||||
|
BASE_NAME MK_API
|
||||||
|
STATIC_DEFINE MediaKitApi_STATIC
|
||||||
|
EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/mk_export.h"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT IOS)
|
||||||
|
file(GLOB api_header_list include/*.h ${CMAKE_BINARY_DIR}/*.h)
|
||||||
install(FILES ${api_header_list} DESTINATION ${INSTALL_PATH_INCLUDE})
|
install(FILES ${api_header_list} DESTINATION ${INSTALL_PATH_INCLUDE})
|
||||||
install(TARGETS mk_api ARCHIVE DESTINATION ${INSTALL_PATH_LIB} LIBRARY DESTINATION ${INSTALL_PATH_LIB})
|
install(TARGETS mk_api ARCHIVE DESTINATION ${INSTALL_PATH_LIB} LIBRARY DESTINATION ${INSTALL_PATH_LIB})
|
||||||
endif ()
|
endif ()
|
@ -14,21 +14,26 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#if defined(GENERATE_EXPORT)
|
||||||
|
#include "mk_export.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) && defined(_MSC_VER)
|
#if defined(_WIN32) && defined(_MSC_VER)
|
||||||
# ifndef MediaKitApi_STATIC
|
# define API_CALL __cdecl
|
||||||
# if defined(MediaKitApi_EXPORTS)
|
|
||||||
# define API_EXPORT __declspec(dllexport)
|
|
||||||
# else
|
|
||||||
# define API_EXPORT __declspec(dllimport)
|
|
||||||
# endif
|
|
||||||
# define API_CALL __cdecl
|
|
||||||
# else
|
|
||||||
# define API_EXPORT
|
|
||||||
# define API_CALL
|
|
||||||
# endif
|
|
||||||
#else
|
#else
|
||||||
|
# define API_CALL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(_WIN32) && defined(_MSC_VER)
|
||||||
|
# if !defined(GENERATE_EXPORT)
|
||||||
|
# if defined(MediaKitApi_EXPORTS)
|
||||||
|
# define API_EXPORT __declspec(dllexport)
|
||||||
|
# else
|
||||||
|
# define API_EXPORT __declspec(dllimport)
|
||||||
|
# endif
|
||||||
|
# endif
|
||||||
|
#elif !defined(GENERATE_EXPORT)
|
||||||
# define API_EXPORT
|
# define API_EXPORT
|
||||||
# define API_CALL
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
using namespace mediakit;
|
using namespace mediakit;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#define XX(name, type, value, str, mpeg_id) const int MK##name = value;
|
#define XX(name, type, value, str, mpeg_id) API_EXPORT const int MK##name = value;
|
||||||
CODEC_MAP(XX)
|
CODEC_MAP(XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
aux_source_directory(. TEST_SRC_LIST)
|
aux_source_directory(. TEST_SRC_LIST)
|
||||||
|
include_directories(${PROJECT_BINARY_DIR}/api)
|
||||||
|
|
||||||
foreach(TEST_SRC ${TEST_SRC_LIST})
|
foreach(TEST_SRC ${TEST_SRC_LIST})
|
||||||
STRING(REGEX REPLACE "^\\./|\\.c[a-zA-Z0-9_]*$" "" TEST_EXE_NAME ${TEST_SRC})
|
STRING(REGEX REPLACE "^\\./|\\.c[a-zA-Z0-9_]*$" "" TEST_EXE_NAME ${TEST_SRC})
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ENABLE_VERSION)
|
#if defined(ENABLE_VERSION)
|
||||||
#include "Version.h"
|
#include "version.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
using namespace toolkit;
|
using namespace toolkit;
|
||||||
|
|
||||||
#if defined(ENABLE_VERSION)
|
#if defined(ENABLE_VERSION)
|
||||||
#include "Version.h"
|
#include "version.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
Loading…
Reference in New Issue
Block a user