1616
1717set (PROJECT_VERSION 2.6.1)
1818
19+ option (ENABLE_STATIC "Build static library" ON )
20+ option (ENABLE_SHARED "Build shared library" ON )
21+
1922if (EXISTS "/etc/debian_version" )
2023 cmake_minimum_required (VERSION 3.7.2)
2124else ()
@@ -257,20 +260,23 @@ source_group(src
257260 ${LIBKQUEUE_SOURCES} )
258261
259262add_library (objlib OBJECT ${LIBKQUEUE_SOURCES} ${LIBKQUEUE_HEADERS} )
260- add_library (kqueue SHARED $<TARGET_OBJECTS:objlib>)
261- add_library (kqueue_static STATIC $<TARGET_OBJECTS:objlib>)
262- if (CMAKE_SYSTEM_NAME MATCHES Windows)
263- set_target_properties (kqueue_static
264- PROPERTIES
265- OUTPUT_NAME kqueue_static
266- ARCHIVE_OUTPUT_DIRECTORY kqueueStatic)
267- else ()
268- set_target_properties (kqueue_static PROPERTIES OUTPUT_NAME kqueue)
263+ if (ENABLE_SHARED)
264+ add_library (kqueue SHARED $<TARGET_OBJECTS:objlib>)
265+ # We should have absolute ABI compatibility between versions as none
266+ # of the public function signatures of variables will change.
267+ set_target_properties (kqueue PROPERTIES SOVERSION 0)
268+ endif ()
269+ if (ENABLE_STATIC)
270+ add_library (kqueue_static STATIC $<TARGET_OBJECTS:objlib>)
271+ if (CMAKE_SYSTEM_NAME MATCHES Windows)
272+ set_target_properties (kqueue_static
273+ PROPERTIES
274+ OUTPUT_NAME kqueue_static
275+ ARCHIVE_OUTPUT_DIRECTORY kqueueStatic)
276+ else ()
277+ set_target_properties (kqueue_static PROPERTIES OUTPUT_NAME kqueue)
278+ endif ()
269279endif ()
270-
271- # We should have absolute ABI compatibility between versions as none
272- # of the public function signatures of variables will change.
273- set_target_properties (kqueue PROPERTIES SOVERSION 0)
274280
275281if (WIN32 )
276282 target_compile_definitions (objlib PRIVATE _USRDLL;_WINDLL)
@@ -309,7 +315,9 @@ endif()
309315if (CMAKE_SYSTEM_NAME STREQUAL Emscripten)
310316 target_compile_options (objlib PRIVATE -pthread)
311317else ()
312- target_link_libraries (kqueue PRIVATE Threads::Threads)
318+ if (ENABLE_SHARED)
319+ target_link_libraries (kqueue PRIVATE Threads::Threads)
320+ endif ()
313321endif ()
314322
315323configure_file (${CMAKE_CURRENT_SOURCE_DIR} /config.h.in
@@ -331,11 +339,16 @@ install(FILES
331339 DESTINATION
332340 "${CMAKE_INSTALL_FULL_INCLUDEDIR} /kqueue/sys"
333341 COMPONENT headers)
334- install (TARGETS
335- kqueue kqueue_static
336- DESTINATION
337- "${CMAKE_INSTALL_FULL_LIBDIR} "
338- COMPONENT libraries)
342+ if (TARGET kqueue)
343+ install (TARGETS kqueue
344+ DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR} "
345+ COMPONENT libraries)
346+ endif ()
347+ if (TARGET kqueue_static)
348+ install (TARGETS kqueue_static
349+ DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR} "
350+ COMPONENT libraries)
351+ endif ()
339352install (FILES
340353 "${CMAKE_SOURCE_DIR} /kqueue.2"
341354 DESTINATION
0 commit comments