@@ -31,6 +31,8 @@ set(NGHTTP2_SOURCES
3131)
3232
3333set (NGHTTP2_RES "" )
34+ set (STATIC_LIB "nghttp2_static" )
35+ set (SHARED_LIB "nghttp2" )
3436
3537if (WIN32 )
3638 configure_file (
@@ -41,40 +43,61 @@ if(WIN32)
4143 set (NGHTTP2_RES ${CMAKE_CURRENT_BINARY_DIR} /version .rc)
4244endif ()
4345
46+ set (EXPORT_SET "${PROJECT_NAME} -targets" )
47+
4448# Public shared library
45- if (ENABLE_SHARED_LIB)
46- add_library (nghttp2 SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES} )
47- set_target_properties (nghttp2 PROPERTIES
49+ if (BUILD_SHARED_LIBS )
50+ add_library (${SHARED_LIB} SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES} )
51+
52+ set_target_properties (${SHARED_LIB} PROPERTIES
4853 COMPILE_FLAGS "${WARNCFLAGS} "
4954 VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
5055 C_VISIBILITY_PRESET hidden
5156 )
52- target_include_directories (nghttp2 INTERFACE
53- "${CMAKE_CURRENT_BINARY_DIR} /includes"
54- "${CMAKE_CURRENT_SOURCE_DIR} /includes"
57+
58+ target_include_directories (${SHARED_LIB} INTERFACE
59+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /includes>
60+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR} /includes>
61+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
5562 )
5663
57- install (TARGETS nghttp2
58- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} "
59- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
60- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR} " )
64+ install (TARGETS ${SHARED_LIB} EXPORT ${EXPORT_SET} )
65+ list (APPEND nghttp2_exports ${SHARED_LIB} )
6166endif ()
6267
63- if (HAVE_CUNIT OR ENABLE_STATIC_LIB)
64- # Static library (for unittests because of symbol visibility)
65- add_library (nghttp2_static STATIC ${NGHTTP2_SOURCES} )
66- set_target_properties (nghttp2_static PROPERTIES
67- COMPILE_FLAGS "${WARNCFLAGS} "
68- VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
69- ARCHIVE_OUTPUT_NAME nghttp2${STATIC_LIB_SUFFIX}
70- )
71- target_compile_definitions (nghttp2_static PUBLIC "-DNGHTTP2_STATICLIB" )
72- if (ENABLE_STATIC_LIB)
73- install (TARGETS nghttp2_static
74- DESTINATION "${CMAKE_INSTALL_LIBDIR} " )
75- endif ()
68+ # Static library (for unittests because of symbol visibility)
69+ add_library (${STATIC_LIB} STATIC ${NGHTTP2_SOURCES} )
70+
71+ set_target_properties (${STATIC_LIB} PROPERTIES
72+ COMPILE_FLAGS "${WARNCFLAGS} "
73+ VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
74+ ARCHIVE_OUTPUT_NAME nghttp2${STATIC_LIB_SUFFIX}
75+ )
76+
77+ target_include_directories (${STATIC_LIB} INTERFACE
78+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /includes>
79+ $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR} /includes>
80+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
81+ )
82+
83+ target_compile_definitions (${STATIC_LIB} PUBLIC "-DNGHTTP2_STATICLIB" )
84+
85+ if (BUILD_STATIC_LIBS)
86+ install (TARGETS ${STATIC_LIB} EXPORT ${EXPORT_SET} )
87+ list (APPEND nghttp2_exports ${STATIC_LIB} )
7688endif ()
7789
90+ if (BUILD_SHARED_LIBS )
91+ set (LIB_SELECTED ${SHARED_LIB} )
92+ else ()
93+ set (LIB_SELECTED ${STATIC_LIB} )
94+ endif ()
95+
96+ add_library (${PROJECT_NAME} ::nghttp2 ALIAS ${LIB_SELECTED} )
7897
7998install (FILES "${CMAKE_CURRENT_BINARY_DIR} /libnghttp2.pc"
8099 DESTINATION "${CMAKE_INSTALL_LIBDIR} /pkgconfig" )
100+
101+ install (EXPORT ${EXPORT_SET}
102+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME}
103+ NAMESPACE ${PROJECT_NAME} ::)
0 commit comments