From 77e8190b6ccf8de231d802de32df0b798bc05623 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 16 Feb 2016 16:04:01 +0100 Subject: [PATCH] cmake: fix symbol visibility issues libnghttp2.so was missing -fvisibility=hidden. libnghttp2_asio.so on the other hand had hidden visibility which resulted in no exported symbols and a broken asio client examples. Just build a static nghttp2 library to solve this issue. --- CMakeLists.txt | 6 ------ lib/CMakeLists.txt | 22 ++++++++++++++++------ src/CMakeLists.txt | 1 - tests/CMakeLists.txt | 12 ++++++++---- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13d11b90..04fddf55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,11 +347,6 @@ if(NOT CMAKE_C_COMPILER_ID STREQUAL "MSVC") ) endif() -set(EXTRACFLAG) -extract_valid_c_flags(EXTRACFLAG - -fvisibility=hidden -) - if(ENABLE_DEBUG) set(DEBUGBUILD 1) endif() @@ -449,7 +444,6 @@ message(STATUS "summary of build options: CXXFLAGS: ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${_build_type}} WARNCFLAGS: ${WARNCFLAGS} CXX1XCXXFLAGS: ${CXX1XCXXFLAGS} - EXTRACFLAG: ${EXTRACFLAG} Library: Shared: ${enable_shared} Static: ${enable_static} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7b012acb..a6adc04d 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -24,14 +24,24 @@ set(NGHTTP2_SOURCES nghttp2_http.c ) -add_library(nghttp2-obj OBJECT ${NGHTTP2_SOURCES}) +# Public shared library +add_library(nghttp2 SHARED ${NGHTTP2_SOURCES}) # Needed because the object files are linked into a shared library. -set_target_properties(nghttp2-obj PROPERTIES - POSITION_INDEPENDENT_CODE ON) -add_library(nghttp2 SHARED $) set_target_properties(nghttp2 PROPERTIES - COMPILE_FLAGS "${WARNCFLAGS} ${EXTRACFLAG}" - VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION}) + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} + C_VISIBILITY_PRESET hidden +) + +if(HAVE_CUNIT) + # Static library (for unittests because of symbol visibility) + add_library(nghttp2_static STATIC ${NGHTTP2_SOURCES}) + set_target_properties(nghttp2_static PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} + ARCHIVE_OUTPUT_NAME nghttp2 + ) +endif() install(TARGETS nghttp2 LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 08c89b0e..1d6af25c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -248,7 +248,6 @@ if(ENABLE_ASIO_LIB) ) # XXX use add_compile_options with a list instead of COMPILE_FLAGS set_target_properties(nghttp2_asio PROPERTIES - COMPILE_FLAGS "${EXTRACFLAG}" VERSION 1.0.0 SOVERSION 1) install(TARGETS nghttp2_asio diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1ffa16c7..5a641834 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,10 +26,12 @@ if(HAVE_CUNIT) add_executable(main EXCLUDE_FROM_ALL ${MAIN_SOURCES} - $ ) target_include_directories(main PRIVATE ${CUNIT_INCLUDE_DIRS}) - target_link_libraries(main ${CUNIT_LIBRARIES}) + target_link_libraries(main + nghttp2_static + ${CUNIT_LIBRARIES} + ) add_test(main main) if(ENABLE_FAILMALLOC) @@ -40,9 +42,11 @@ if(HAVE_CUNIT) ) add_executable(failmalloc EXCLUDE_FROM_ALL ${FAILMALLOC_SOURCES} - $ ) - target_link_libraries(failmalloc ${CUNIT_LIBRARIES}) + target_link_libraries(failmalloc + nghttp2_static + ${CUNIT_LIBRARIES} + ) add_test(failmalloc failmalloc) endif()