libevent/cmake/AddEventLibrary.cmake
Azat Khuzhin b1e8a4138f cmake: use APPEND during exporting targets (for old cmake)
On centos with cmake 2.8.12.2:
  CMake Error at cmake/AddEventLibrary.cmake:92 (export):
    export called with target "event_extra_shared" which requires target
    "event_core_shared" that is not in the export list.

    If the required target is not easy to reference in this call, consider
    using the APPEND option with multiple separate calls.

But on newer cmake I guess everything is ok.

Fixes: 7182c2f561570cd9ceb704623ebe9ae3608c7b43 ("cmake: build SHARED
and STATIC libraries (like autoconf does)")
2017-03-14 13:37:59 +03:00

110 lines
3.0 KiB
CMake

include(CMakeParseArguments)
set(LIBEVENT_SHARED_LIBRARIES "")
set(LIBEVENT_STATIC_LIBRARIES "")
macro(set_event_lib_properties LIB_NAME)
set_target_properties("${LIB_NAME}_static" PROPERTIES ${ARGN})
set_target_properties("${LIB_NAME}_shared" PROPERTIES ${ARGN})
endmacro()
macro(set_event_shared_lib_flags LIB_NAME)
set_target_properties("${LIB_NAME}_shared" PROPERTIES
COMPILE_FLAGS ${ARGN})
set_target_properties("${LIB_NAME}_shared" PROPERTIES
LINK_FLAGS ${ARGN})
endmacro()
macro(generate_pkgconfig LIB_NAME)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
set(includedir ${CMAKE_INSTALL_PREFIX}/include)
set(VERSION ${EVENT_ABI_LIBVERSION})
set(LIBS "")
foreach (LIB ${LIB_PLATFORM})
set(LIBS "${LIBS} -L${LIB}")
endforeach()
set(OPENSSL_LIBS "")
foreach(LIB ${OPENSSL_LIBRARIES})
set(OPENSSL_LIBS "${OPENSSL_LIBS} -L${LIB}")
endforeach()
configure_file("lib${LIB_NAME}.pc.in" "lib${LIB_NAME}.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/lib${LIB_NAME}.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig"
)
endmacro()
# Global variables that it uses:
# - EVENT_ABI_LIBVERSION
# - CMAKE_THREAD_LIBS_INIT LIB_PLATFORM
# - OPENSSL_LIBRARIES
# - HDR_PUBLIC
# - EVENT_INSTALL_INCLUDE_DIR
# - EVENT_SHARED_FLAGS
#
# Exported variables:
# - LIBEVENT_SHARED_LIBRARIES
# - LIBEVENT_STATIC_LIBRARIES
macro(add_event_library LIB_NAME)
cmake_parse_arguments(LIB
"" # Options
"VERSION" # One val
"SOURCES;LIBRARIES" # Multi val
${ARGN}
)
add_library("${LIB_NAME}_static" STATIC ${LIB_SOURCES})
add_library("${LIB_NAME}_shared" SHARED ${LIB_SOURCES})
target_link_libraries("${LIB_NAME}_shared"
${CMAKE_THREAD_LIBS_INIT}
${LIB_PLATFORM}
${LIB_LIBRARIES})
if (EVENT_SHARED_FLAGS)
set_event_shared_lib_flags("${LIB_NAME}" "${EVENT_SHARED_FLAGS}")
endif()
set_event_lib_properties("${LIB_NAME}"
OUTPUT_NAME "${LIB_NAME}"
CLEAN_DIRECT_OUTPUT 1
)
set_target_properties(
"${LIB_NAME}_shared" PROPERTIES
PUBLIC_HEADER "${HDR_PUBLIC}")
set_target_properties(
"${LIB_NAME}_static" PROPERTIES
PUBLIC_HEADER "${HDR_PUBLIC}")
set_target_properties(
"${LIB_NAME}_shared" PROPERTIES
SOVERSION ${EVENT_ABI_LIBVERSION}
)
export(TARGETS "${LIB_NAME}_static" "${LIB_NAME}_shared"
FILE "${PROJECT_BINARY_DIR}/LibeventTargets.cmake"
APPEND
)
install(TARGETS "${LIB_NAME}_static" "${LIB_NAME}_shared"
EXPORT LibeventTargets
LIBRARY DESTINATION "lib" COMPONENT lib
ARCHIVE DESTINATION "lib" COMPONENT lib
PUBLIC_HEADER DESTINATION "include/event2"
COMPONENT dev
)
list(APPEND LIBEVENT_SHARED_LIBRARIES "${LIB_NAME}_shared")
list(APPEND LIBEVENT_STATIC_LIBRARIES "${LIB_NAME}_static")
generate_pkgconfig("${LIB_NAME}")
endmacro()