@@ -31,6 +31,8 @@ set(NGHTTP2_SOURCES
31
31
)
32
32
33
33
set (NGHTTP2_RES "" )
34
+ set (STATIC_LIB "nghttp2_static" )
35
+ set (SHARED_LIB "nghttp2" )
34
36
35
37
if (WIN32 )
36
38
configure_file (
@@ -41,40 +43,61 @@ if(WIN32)
41
43
set (NGHTTP2_RES ${CMAKE_CURRENT_BINARY_DIR} /version .rc)
42
44
endif ()
43
45
46
+ set (EXPORT_SET "${PROJECT_NAME} -targets" )
47
+
44
48
# 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
48
53
COMPILE_FLAGS "${WARNCFLAGS} "
49
54
VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}
50
55
C_VISIBILITY_PRESET hidden
51
56
)
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} >
55
62
)
56
63
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} )
61
66
endif ()
62
67
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} )
76
88
endif ()
77
89
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} )
78
97
79
98
install (FILES "${CMAKE_CURRENT_BINARY_DIR} /libnghttp2.pc"
80
99
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