CMakeLists.txt 2.62 KB
Newer Older
Xiaofeng Wang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# MIT License
#
# Copyright (c) 2016-2022 The ZLMediaKit project authors. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#

24
include(GenerateExportHeader)
Xiaofeng Wang committed
25 26 27 28 29 30 31
file(GLOB API_SRC_LIST
  include/*.h
  source/*.c
  source/*.cpp
  source/*.h)

set(LINK_LIBRARIES ${MK_LINK_LIBRARIES} jsoncpp)
32

Xiaofeng Wang committed
33 34 35 36 37
if(IOS)
  add_library(mk_api STATIC ${API_SRC_LIST})
  target_link_libraries(mk_api
    PRIVATE ${LINK_LIBRARIES})
  return()
38 39
endif ()

Xiaofeng Wang committed
40 41
set(COMPILE_DEFINITIONS ${MK_COMPILE_DEFINITIONS})
list(APPEND COMPILE_DEFINITIONS GENERATE_EXPORT)
xiongziliang committed
42

Xiaofeng Wang committed
43 44 45 46 47 48
if(ENABLE_API_STATIC_LIB)
  add_library(mk_api STATIC ${API_SRC_LIST})
  list(APPEND COMPILE_DEFINITIONS MediaKitApi_STATIC)
else()
  add_library(mk_api SHARED ${API_SRC_LIST})
endif()
49

Xiaofeng Wang committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63
target_compile_definitions(mk_api
  PRIVATE ${COMPILE_DEFINITIONS})
target_include_directories(mk_api
  PRIVATE
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
  PUBLIC
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>")

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
  target_link_libraries(mk_api -Wl,--start-group ${LINK_LIBRARIES} -Wl,--end-group)
else()
  target_link_libraries(mk_api jsoncpp ${LINK_LIBRARIES})
endif()
64 65

generate_export_header(mk_api
Xiaofeng Wang committed
66 67 68 69
  EXPORT_MACRO_NAME API_EXPORT
  BASE_NAME MK_API
  STATIC_DEFINE MediaKitApi_STATIC
  EXPORT_FILE_NAME "${CMAKE_BINARY_DIR}/mk_export.h")
70

71 72
add_subdirectory(tests)

Xiaofeng Wang committed
73 74 75 76 77 78
file(GLOB API_HEADER_LIST include/*.h ${CMAKE_CURRENT_BINARY_DIR}/*.h)
install(FILES ${API_HEADER_LIST}
  DESTINATION ${INSTALL_PATH_INCLUDE})
install(TARGETS mk_api
  ARCHIVE DESTINATION ${INSTALL_PATH_LIB}
  LIBRARY DESTINATION ${INSTALL_PATH_LIB})