# cmake -G "Visual Studio 10" ..
# start libevent.sln
#
-if (APPLE)
- cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
-else()
- cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR)
-endif()
+
+cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
# what? why would you get id of other useful build types? - Ellzey
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "Limited configurations" FORCE)
+set(EVENT__LIBRARY_TYPE DEFAULT CACHE STRING
+ "Set library type to SHARED/STATIC/BOTH (default BOTH)")
+
project(libevent C)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
set(GNUC 1)
endif()
+# Detect library type
+set(EVENT_LIBRARY_TYPE)
+if ("${EVENT__LIBRARY_TYPE}" STREQUAL "DEFAULT")
+ set(EVENT_LIBRARY_TYPE BOTH)
+else()
+ string(TOUPPER "${EVENT__LIBRARY_TYPE}" EVENT_LIBRARY_TYPE)
+endif()
+set(EVENT_LIBRARY_STATIC OFF)
+set(EVENT_LIBRARY_SHARED OFF)
+if ("${EVENT_LIBRARY_TYPE}" STREQUAL "BOTH")
+ set(EVENT_LIBRARY_STATIC ON)
+ set(EVENT_LIBRARY_SHARED ON)
+elseif ("${EVENT_LIBRARY_TYPE}" STREQUAL "STATIC")
+ set(EVENT_LIBRARY_STATIC ON)
+elseif ("${EVENT_LIBRARY_TYPE}" STREQUAL "SHARED")
+ set(EVENT_LIBRARY_SHARED ON)
+else()
+ message(FATAL_ERROR "${EVENT_LIBRARY_TYPE} is not supported")
+endif()
+
# GNUC specific options.
if (${GNUC})
option(EVENT__DISABLE_GCC_WARNINGS "Disable verbose warnings with GCC" OFF)
add_executable(${name} ${ARGN})
target_link_libraries(${name}
- event_extra_static
- event_core_static
+ event_extra
+ event_core
${LIB_APPS}
${LIB_PLATFORM})
if (${ssl})
- target_link_libraries(${name} event_openssl_static)
+ target_link_libraries(${name} event_openssl)
endif()
endmacro()
if (NOT EVENT__DISABLE_SAMPLES)
macro(add_bench_prog prog)
add_executable(${prog} ${ARGN})
target_link_libraries(${prog}
- event_extra_static
- event_core_static
+ event_extra
+ event_core
${LIB_APPS}
${LIB_PLATFORM})
endmacro()
target_link_libraries(${prog}
${LIB_APPS}
${LIB_PLATFORM}
- event_core_shared
- event_extra_shared
+ event_core
+ event_extra
${ARGN})
endmacro()
if (NOT EVENT__DISABLE_TESTS)
target_link_libraries(regress
${LIB_APPS}
${LIB_PLATFORM}
- event_core_shared
- event_extra_shared)
+ event_core
+ event_extra)
if (NOT EVENT__DISABLE_OPENSSL)
- target_link_libraries(regress event_openssl_shared)
+ target_link_libraries(regress event_openssl)
endif()
if (CMAKE_USE_PTHREADS_INIT)
- target_link_libraries(regress event_pthreads_shared)
+ target_link_libraries(regress event_pthreads)
endif()
else()
message(WARNING "No suitable Python interpreter found, cannot generate regress tests!")
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})
# - HDR_PUBLIC
# - EVENT_INSTALL_INCLUDE_DIR
# - EVENT_SHARED_FLAGS
+# - EVENT_LIBRARY_STATIC
+# - EVENT_LIBRARY_SHARED
#
# Exported variables:
# - LIBEVENT_SHARED_LIBRARIES
${ARGN}
)
- add_library("${LIB_NAME}_static" STATIC ${LIB_SOURCES})
- add_library("${LIB_NAME}_shared" SHARED ${LIB_SOURCES})
+ set(ADD_EVENT_LIBRARY_TARGETS)
+ set(ADD_EVENT_LIBRARY_INTERFACE)
- 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()
+ if (${EVENT_LIBRARY_STATIC})
+ add_library("${LIB_NAME}_static" STATIC ${LIB_SOURCES})
+ set_target_properties("${LIB_NAME}_static" PROPERTIES
+ OUTPUT_NAME "${LIB_NAME}"
+ CLEAN_DIRECT_OUTPUT 1)
+ set_target_properties(
+ "${LIB_NAME}_static" PROPERTIES
+ PUBLIC_HEADER "${HDR_PUBLIC}")
- set_event_lib_properties("${LIB_NAME}"
- OUTPUT_NAME "${LIB_NAME}"
- CLEAN_DIRECT_OUTPUT 1
- )
+ list(APPEND LIBEVENT_STATIC_LIBRARIES "${LIB_NAME}_static")
+ list(APPEND ADD_EVENT_LIBRARY_TARGETS "${LIB_NAME}_static")
- set_target_properties(
- "${LIB_NAME}_shared" PROPERTIES
- PUBLIC_HEADER "${HDR_PUBLIC}")
- set_target_properties(
- "${LIB_NAME}_static" PROPERTIES
- PUBLIC_HEADER "${HDR_PUBLIC}")
+ set(ADD_EVENT_LIBRARY_INTERFACE "${LIB_NAME}_static")
+ endif()
- set_target_properties(
- "${LIB_NAME}_shared" PROPERTIES
- SOVERSION ${EVENT_ABI_LIBVERSION}
- )
+ if (${EVENT_LIBRARY_SHARED})
+ 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_target_properties("${LIB_NAME}_shared" PROPERTIES
+ OUTPUT_NAME "${LIB_NAME}"
+ CLEAN_DIRECT_OUTPUT 1)
+ set_target_properties(
+ "${LIB_NAME}_shared" PROPERTIES
+ PUBLIC_HEADER "${HDR_PUBLIC}")
+ set_target_properties(
+ "${LIB_NAME}_shared" PROPERTIES
+ SOVERSION ${EVENT_ABI_LIBVERSION}
+ )
+
+ list(APPEND LIBEVENT_SHARED_LIBRARIES "${LIB_NAME}_shared")
+ list(APPEND ADD_EVENT_LIBRARY_TARGETS "${LIB_NAME}_shared")
+
+ set(ADD_EVENT_LIBRARY_INTERFACE "${LIB_NAME}_shared")
+ endif()
- export(TARGETS "${LIB_NAME}_static" "${LIB_NAME}_shared"
+ export(TARGETS ${ADD_EVENT_LIBRARY_TARGETS}
FILE "${PROJECT_BINARY_DIR}/LibeventTargets.cmake"
APPEND
)
- install(TARGETS "${LIB_NAME}_static" "${LIB_NAME}_shared"
+ install(TARGETS ${ADD_EVENT_LIBRARY_TARGETS}
EXPORT LibeventTargets
LIBRARY DESTINATION "lib" COMPONENT lib
ARCHIVE DESTINATION "lib" COMPONENT lib
COMPONENT dev
)
- list(APPEND LIBEVENT_SHARED_LIBRARIES "${LIB_NAME}_shared")
- list(APPEND LIBEVENT_STATIC_LIBRARIES "${LIB_NAME}_static")
+ add_library(${LIB_NAME} INTERFACE)
+ target_link_libraries(${LIB_NAME} INTERFACE ${ADD_EVENT_LIBRARY_INTERFACE})
generate_pkgconfig("${LIB_NAME}")
endmacro()