pkg-config, PIE, API breakages fixes (#23)

* Update protolib to pick up new fixes

* CMake: restore SONAME_VERSION to 1

* CMake: generate pkg-config file

* CMake: set -fvisibility=hidden and POSITION_INDEPENDENT_CODE

Need to build everything with fPIC, and also hide symbols by default,
since public ones are explicitly marked as such.

* Revert public API incompatible changes

NormSetId and NormCountCompletedObjects were part of the public API in
released versions, so they cannot be just removed without breaking API/ABI
compatibility.
NormSendCommandTo is a private symbol, but was marked for export by
mistake.

* Add BUILD_STATIC_LIBS option to allow building both static and shared objects

CMake does not support this out of the box, so it has to be implemented
manually. It results in the libnorm build being repeated twice, as there's
no object sharing.
pull/27/head
Luca Boccassi 2021-02-01 15:20:20 +00:00 committed by GitHub
parent 213adb3938
commit 9c367b50bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 14 deletions

View File

@ -3,6 +3,10 @@ cmake_policy(SET CMP0077 NEW)
# set the project name # set the project name
project(norm VERSION 1.5.8) project(norm VERSION 1.5.8)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(COMMON src/common) set(COMMON src/common)
option(NORM_BUILD_EXAMPLES "Enables building of the examples in /examples." OFF) option(NORM_BUILD_EXAMPLES "Enables building of the examples in /examples." OFF)
@ -121,12 +125,26 @@ target_compile_options(norm PUBLIC ${PLATFORM_FLAGS})
target_include_directories(norm PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(norm PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(norm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>) target_include_directories(norm PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
if(BUILD_SHARED_LIBS AND WIN32) if(BUILD_SHARED_LIBS)
set_target_properties(norm PROPERTIES SOVERSION 1)
if(WIN32)
target_compile_definitions(norm PUBLIC NORM_USE_DLL) target_compile_definitions(norm PUBLIC NORM_USE_DLL)
endif() endif()
endif()
if(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS)
add_library(norm-static STATIC ${PLATFORM_SOURCE_FILES} ${COMMON_SOURCE_FILES} ${PUBLIC_HEADER_FILES})
target_link_libraries(norm-static PRIVATE protokit::protokit)
target_compile_definitions(norm-static PUBLIC ${PLATFORM_DEFINITIONS})
target_compile_options(norm-static PUBLIC ${PLATFORM_FLAGS})
target_include_directories(norm-static PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_include_directories(norm-static PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
set_target_properties(norm-static PROPERTIES OUTPUT_NAME "norm" PREFIX "lib")
set(NORM_STATIC "norm-static")
endif()
# Install target # Install target
install( TARGETS norm protokit EXPORT normTargets install( TARGETS norm ${NORM_STATIC} protokit EXPORT normTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
@ -142,6 +160,16 @@ install( EXPORT normTargets
install(FILES include/normApi.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(FILES include/normApi.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Create pkg-config file norm.pc
# TODO: once waf is removed, norm.pc.in can be edited to use the variables CMake sets directly, and
# remove these re-definitions
set(VERSION ${PROJECT_VERSION})
set(PREFIX ${CMAKE_INSTALL_PREFIX})
set(LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(STATIC_LIBS "libprotokit.a")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/norm.pc.in ${CMAKE_CURRENT_BINARY_DIR}/norm.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/norm.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Create a ConfigVersion.cmake file # Create a ConfigVersion.cmake file
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
write_basic_package_version_file( write_basic_package_version_file(

View File

@ -338,9 +338,9 @@ bool NormPresetObjectInfo(NormSessionHandle sessionHandle, // FEC O
UINT16 segmentSize, UINT16 segmentSize,
UINT16 numData, UINT16 numData,
UINT16 numParity); UINT16 numParity);
// non-public on purpose
//NORM_API_LINKAGE NORM_API_LINKAGE
//void NormSetId(NormSessionHandle sessionHandle, NormNodeId normId); void NormSetId(NormSessionHandle sessionHandle, NormNodeId normId);
// This does not affect the rx_socket binding if already bound (sender or receiver already started) // This does not affect the rx_socket binding if already bound (sender or receiver already started)
// (i.e., just affects where NORM packets are sent) // (i.e., just affects where NORM packets are sent)

View File

@ -1,6 +1,6 @@
prefix=@PREFIX@ prefix=@PREFIX@
exec_prefix=${prefix} exec_prefix=${prefix}
libdir=@LIBDIR@ libdir=${prefix}/@LIBDIR@
includedir=${prefix}/include includedir=${prefix}/include
Name: norm Name: norm
@ -8,4 +8,5 @@ Version: @VERSION@
Description: NACK-Oriented Reliable Multicast (NORM) library Description: NACK-Oriented Reliable Multicast (NORM) library
Libs: -L${libdir} -lnorm Libs: -L${libdir} -lnorm
Libs.private: @STATIC_LIBS@ Libs.private: @STATIC_LIBS@
Requires.private: @REQUIRES_PRIVATE@
Cflags: -I${includedir} Cflags: -I${includedir}

@ -1 +1 @@
Subproject commit 702e909945446275f0313846e988612883fca94a Subproject commit 66092403ffeda703ad5e563be068db345f111a3c

View File

@ -739,8 +739,7 @@ void NormInstance::Shutdown()
notify_pool.Destroy(); notify_pool.Destroy();
} // end NormInstance::Shutdown() } // end NormInstance::Shutdown()
/* // This function doesn't make sense?
This function doesn't make sense?
UINT32 NormInstance::CountCompletedObjects(NormSession* session) UINT32 NormInstance::CountCompletedObjects(NormSession* session)
{ {
UINT32 result = 0UL; UINT32 result = 0UL;
@ -756,7 +755,6 @@ UINT32 NormInstance::CountCompletedObjects(NormSession* session)
} }
return result; return result;
} // end NormInstance::CountCompletedObjects() } // end NormInstance::CountCompletedObjects()
*/
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// NORM API FUNCTION IMPLEMENTATIONS // NORM API FUNCTION IMPLEMENTATIONS
@ -2313,7 +2311,6 @@ void NormCancelCommand(NormSessionHandle sessionHandle)
// This one is not part of the public API (for NormSocket use currently) // This one is not part of the public API (for NormSocket use currently)
NORM_API_LINKAGE
bool NormSendCommandTo(NormSessionHandle sessionHandle, bool NormSendCommandTo(NormSessionHandle sessionHandle,
const char* cmdBuffer, const char* cmdBuffer,
unsigned int cmdLength, unsigned int cmdLength,
@ -3064,7 +3061,6 @@ void NormNodeRelease(NormNodeHandle nodeHandle)
// is done so that this current approach is not very costly) // is done so that this current approach is not very costly)
// //
/*
// Not sure why this function exists. It just counts the number // Not sure why this function exists. It just counts the number
// of RX_OBJECT_COMPLETED events currently in notification queue // of RX_OBJECT_COMPLETED events currently in notification queue
// which is a temporary and transitory thing??? // which is a temporary and transitory thing???
@ -3081,4 +3077,3 @@ UINT32 NormCountCompletedObjects(NormSessionHandle sessionHandle)
} }
return result; return result;
} // end NormCountCompletedObjects() } // end NormCountCompletedObjects()
*/