Add export symbol support to CMake
This commit is contained in:
parent
3b2560feb3
commit
3b8cf47307
@ -4,6 +4,9 @@ include(CheckLibraryExists)
|
|||||||
include(CheckIncludeFiles)
|
include(CheckIncludeFiles)
|
||||||
include(CheckTypeSize)
|
include(CheckTypeSize)
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
|
||||||
|
include(cmake_export_symbol)
|
||||||
|
|
||||||
project (LibreSSL C)
|
project (LibreSSL C)
|
||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
@ -5,7 +5,7 @@ pkgconfigdir = $(libdir)/pkgconfig
|
|||||||
pkgconfig_DATA = libcrypto.pc libssl.pc libtls.pc openssl.pc
|
pkgconfig_DATA = libcrypto.pc libssl.pc libtls.pc openssl.pc
|
||||||
|
|
||||||
EXTRA_DIST = README.md README.windows VERSION config scripts
|
EXTRA_DIST = README.md README.windows VERSION config scripts
|
||||||
EXTRA_DIST += CMakeLists.txt cmake_uninstall.cmake.in
|
EXTRA_DIST += CMakeLists.txt cmake_export_symbol.cmake cmake_uninstall.cmake.in
|
||||||
|
|
||||||
.PHONY: install_sw
|
.PHONY: install_sw
|
||||||
install_sw: install
|
install_sw: install
|
||||||
|
41
cmake_export_symbol.cmake
Normal file
41
cmake_export_symbol.cmake
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
macro(export_symbol TARGET FILENAME)
|
||||||
|
|
||||||
|
set(FLAG "")
|
||||||
|
|
||||||
|
if(WIN32)
|
||||||
|
string(REPLACE ".sym" ".def" DEF_FILENAME ${FILENAME})
|
||||||
|
target_sources(${TARGET} PRIVATE ${DEF_FILENAME})
|
||||||
|
|
||||||
|
elseif(APPLE)
|
||||||
|
set(FLAG "-exported_symbols_list ${FILENAME}")
|
||||||
|
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||||
|
|
||||||
|
elseif(CMAKE_SYSTEM_NAME MATCHES "HP-UX")
|
||||||
|
file(READ ${FILENAME} SYMBOLS)
|
||||||
|
string(REGEX REPLACE "\n$" "" SYMBOLS ${SYMBOLS})
|
||||||
|
string(REPLACE "\n" "\n+e " SYMBOLS ${SYMBOLS})
|
||||||
|
string(REPLACE ".sym" ".opt" OPT_FILENAME ${FILENAME})
|
||||||
|
file(WRITE ${OPT_FILENAME} "+e ${SYMBOLS}")
|
||||||
|
set(FLAG "-Wl,-c,${OPT_FILENAME}")
|
||||||
|
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||||
|
|
||||||
|
elseif(CMAKE_SYSTEM_NAME MATCHES "SunOS")
|
||||||
|
file(READ ${FILENAME} SYMBOLS)
|
||||||
|
string(REPLACE "\n" ";\n" SYMBOLS ${SYMBOLS})
|
||||||
|
string(REPLACE ".sym" ".ver" VER_FILENAME ${FILENAME})
|
||||||
|
file(WRITE ${VER_FILENAME}
|
||||||
|
"{\nglobal:\n${SYMBOLS}\nlocal:\n*;\n};\n")
|
||||||
|
set(FLAG "-Wl,-M${VER_FILENAME}")
|
||||||
|
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||||
|
|
||||||
|
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||||
|
file(READ ${FILENAME} SYMBOLS)
|
||||||
|
string(REPLACE "\n" ";\n" SYMBOLS ${SYMBOLS})
|
||||||
|
string(REPLACE ".sym" ".ver" VER_FILENAME ${FILENAME})
|
||||||
|
file(WRITE ${VER_FILENAME}
|
||||||
|
"{\nglobal:\n${SYMBOLS}\nlocal:\n*;\n};\n")
|
||||||
|
set(FLAG "-Wl,--version-script,\"${VER_FILENAME}\"")
|
||||||
|
set_target_properties(${TARGET} PROPERTIES LINK_FLAGS ${FLAG})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endmacro()
|
@ -52,9 +52,8 @@ add_library(ssl-objects OBJECT ${SSL_SRC})
|
|||||||
if (BUILD_SHARED)
|
if (BUILD_SHARED)
|
||||||
add_library(ssl STATIC $<TARGET_OBJECTS:ssl-objects>)
|
add_library(ssl STATIC $<TARGET_OBJECTS:ssl-objects>)
|
||||||
add_library(ssl-shared SHARED $<TARGET_OBJECTS:ssl-objects>)
|
add_library(ssl-shared SHARED $<TARGET_OBJECTS:ssl-objects>)
|
||||||
|
export_symbol(ssl-shared ${CMAKE_CURRENT_SOURCE_DIR}/ssl.sym)
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_sources(ssl-shared PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/ssl.def)
|
|
||||||
target_link_libraries(ssl-shared crypto-shared Ws2_32.lib)
|
target_link_libraries(ssl-shared crypto-shared Ws2_32.lib)
|
||||||
set(SSL_POSTFIX -${SSL_MAJOR_VERSION})
|
set(SSL_POSTFIX -${SSL_MAJOR_VERSION})
|
||||||
endif()
|
endif()
|
||||||
|
@ -33,9 +33,8 @@ add_library(tls-objects OBJECT ${TLS_SRC})
|
|||||||
if (BUILD_SHARED)
|
if (BUILD_SHARED)
|
||||||
add_library(tls STATIC $<TARGET_OBJECTS:tls-objects>)
|
add_library(tls STATIC $<TARGET_OBJECTS:tls-objects>)
|
||||||
add_library(tls-shared SHARED $<TARGET_OBJECTS:tls-objects>)
|
add_library(tls-shared SHARED $<TARGET_OBJECTS:tls-objects>)
|
||||||
|
export_symbol(tls-shared ${CMAKE_CURRENT_SOURCE_DIR}/tls.sym)
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_sources(tls-shared PRIVATE
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tls.def)
|
|
||||||
target_link_libraries(tls-shared ssl-shared crypto-shared Ws2_32.lib)
|
target_link_libraries(tls-shared ssl-shared crypto-shared Ws2_32.lib)
|
||||||
set(TLS_POSTFIX -${TLS_MAJOR_VERSION})
|
set(TLS_POSTFIX -${TLS_MAJOR_VERSION})
|
||||||
endif()
|
endif()
|
||||||
|
Loading…
Reference in New Issue
Block a user