Rather than listing in a variable, list sources, libs etc directly on targets.

This commit is contained in:
Jim Hague 2019-10-21 13:32:05 +01:00
parent 87177cc103
commit 41741f6cc4
1 changed files with 59 additions and 86 deletions

View File

@ -349,8 +349,7 @@ if (HAVE_STRPTIME)
endif () endif ()
# Main library # Main library
add_library(getdns_objects OBJECT
set(getdns_SOURCES
src/anchor.c src/anchor.c
src/const-info.c src/const-info.c
src/convert.c src/convert.c
@ -399,34 +398,23 @@ set(getdns_SOURCES
${CMAKE_CURRENT_BINARY_DIR}/version.c ${CMAKE_CURRENT_BINARY_DIR}/version.c
) )
if (NOT HAVE_GETTIMEOFDAY) if (NOT HAVE_GETTIMEOFDAY)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/gettimeofday.c)
src/compat/gettimeofday.c
)
endif () endif ()
if (NOT HAVE_DECL_INET_PTON) if (NOT HAVE_DECL_INET_PTON)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/inet_pton.c)
src/compat/inet_pton.c
)
endif () endif ()
if (NOT HAVE_DECL_INET_NTOP) if (NOT HAVE_DECL_INET_NTOP)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/inet_ntop.c)
src/compat/inet_ntop.c
)
endif () endif ()
if (NOT HAVE_DECL_MKSTEMP) if (NOT HAVE_DECL_MKSTEMP)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/mkstemp.c)
src/compat/mkstemp.c
)
endif () endif ()
if (NOT HAVE_DECL_STRLCPY) if (NOT HAVE_DECL_STRLCPY)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/strlcpy.c)
src/compat/strlcpy.c
)
endif () endif ()
if (NOT HAVE_DECL_ARC4RANDOM) if (NOT HAVE_DECL_ARC4RANDOM)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE
src/compat/arc4random.c src/compat/arc4random.c
src/compat/explicit_bzero.c src/compat/explicit_bzero.c
src/compat/arc4_lock.c src/compat/arc4_lock.c
@ -434,32 +422,21 @@ if (NOT HAVE_DECL_ARC4RANDOM)
if (NOT HAVE_DECL_GETENTROPY) if (NOT HAVE_DECL_GETENTROPY)
if (DEFINED GETDNS_ON_WINDOWS) if (DEFINED GETDNS_ON_WINDOWS)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/getentropy_win.c)
src/compat/getentropy_win.c
)
elseif (APPLE) elseif (APPLE)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/getentropy_osx.c)
src/compat/getentropy_osx.c
)
elseif (DEFINED LINUX) elseif (DEFINED LINUX)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/getentropy_linux.c)
src/compat/getentropy_linux.c
)
endif () endif ()
endif () endif ()
endif () endif ()
if (NOT HAVE_DECL_ARC4RANDOM_UNIFORM) if (NOT HAVE_DECL_ARC4RANDOM_UNIFORM)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/arc4random_uniform.c)
src/compat/arc4random_uniform.c
)
endif () endif ()
if (NOT STRPTIME_WORKS) if (NOT STRPTIME_WORKS)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/compat/strptime.c)
src/compat/strptime.c
)
endif () endif ()
target_include_directories(getdns_objects
set(getdns_INCLUDES
PUBLIC PUBLIC
src src
@ -471,40 +448,45 @@ set(getdns_INCLUDES
stubby/src # Wrong, wrong, wrong. stubby/src # Wrong, wrong, wrong.
${OPENSSL_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR}
${LIBBSD_INCLUDE_DIRS}
Threads::Threads
) )
set(getdns_LIBS
PUBLIC
${OPENSSL_LIBRARIES}
Threads::Threads
${getdns_system_libs}
)
if (NOT HAVE_SSL_DANE_ENABLE) if (NOT HAVE_SSL_DANE_ENABLE)
list(APPEND getdns_SOURCES target_sources(getdns_objects PRIVATE src/ssl_dane/danessl.c)
src/ssl_dane/danessl.c target_include_directories(getdns_objects PRIVATE src/ssl_dane)
)
list(APPEND getdns_INCLUDES
PRIVATE src/ssl_dane
)
set(USE_DANESSL 1) set(USE_DANESSL 1)
endif () endif ()
# Don't compile separate objects for shared and static libraries. # Don't compile separate objects for shared and static libraries.
# Yes, -fPIC is slightly suboptimal for static libraries, but it looks # Yes, -fPIC is slightly suboptimal for static libraries, but it looks
# to me that it's the behaviour the autoconf build follows. # to me that it's the behaviour the autoconf build follows.
add_library(getdns_objects OBJECT ${getdns_SOURCES})
target_include_directories(getdns_objects ${getdns_INCLUDES})
set_property(TARGET getdns_objects PROPERTY POSITION_INDEPENDENT_CODE 1) set_property(TARGET getdns_objects PROPERTY POSITION_INDEPENDENT_CODE 1)
set_property(TARGET getdns_objects PROPERTY C_STANDARD 11)
# Static library version of main library.
add_library(getdns STATIC $<TARGET_OBJECTS:getdns_objects>) add_library(getdns STATIC $<TARGET_OBJECTS:getdns_objects>)
target_include_directories(getdns ${getdns_INCLUDES}) target_include_directories(getdns PUBLIC src)
target_link_libraries(getdns ${getdns_LIBS}) target_link_libraries(getdns
PUBLIC
OpenSSL::SSL
OpenSSL::Crypto
Threads::Threads
${getdns_system_libs}
)
set_target_properties(getdns PROPERTIES OUTPUT_NAME getdns${static_lib_suffix}) set_target_properties(getdns PROPERTIES OUTPUT_NAME getdns${static_lib_suffix})
# Generate either a Win32 .def file with DLL exports, or a GNU ld # Shared library version of main library.
add_library(getdns_shared SHARED $<TARGET_OBJECTS:getdns_objects>)
target_include_directories(getdns PUBLIC src)
target_link_libraries(getdns_shared
PUBLIC
OpenSSL::SSL
OpenSSL::Crypto
Threads::Threads
${getdns_system_libs}
)
set_target_properties(getdns_shared PROPERTIES VERSION ${GETDNS_SHAREDLIBVERSION})
set_target_properties(getdns_shared PROPERTIES OUTPUT_NAME getdns)
# Generate platform-specific link file with the export symbols.
# link file specifying the exports. # link file specifying the exports.
file(STRINGS src/libgetdns.symbols symbols) file(STRINGS src/libgetdns.symbols symbols)
set(getdns_EXTRA_LINK "") set(getdns_EXTRA_LINK "")
@ -514,13 +496,14 @@ if (WIN32)
foreach (symbol IN LISTS symbols) foreach (symbol IN LISTS symbols)
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.def" " ${symbol}\n") file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.def" " ${symbol}\n")
endforeach () endforeach ()
set(getdns_EXTRA_LINK "${CMAKE_CURRENT_BINARY_DIR}/getdns.def") target_sources(getdns_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/getdns.def")
elseif (APPLE) elseif (APPLE)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/getdns.syms" "") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/getdns.syms" "")
foreach (symbol IN LISTS symbols) foreach (symbol IN LISTS symbols)
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.syms" "_${symbol}\n") file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.syms" "_${symbol}\n")
endforeach () endforeach ()
set(getdns_EXTRA_LINK_FLAGS "-exported_symbols_list getdns.syms") target_sources(getdns_shared PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/getdns.syms")
target_link_libraries(getdns_shared PRIVATE "-exported_symbols_list getdns.syms")
else () else ()
# Assume GNU ld. # Assume GNU ld.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/getdns.ver" "{ global:\n") file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/getdns.ver" "{ global:\n")
@ -528,27 +511,15 @@ else ()
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.ver" " ${symbol};\n") file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.ver" " ${symbol};\n")
endforeach () endforeach ()
file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.ver" "local:\n *;\n};\n") file(APPEND "${CMAKE_CURRENT_BINARY_DIR}/getdns.ver" "local:\n *;\n};\n")
set(getdns_EXTRA_LINK_FLAGS "-Wl,--version-script=getdns.ver") target_link_libraries(getdns_shared PRIVATE "-Wl,--version-script=getdns.ver")
endif () endif ()
add_library(getdns_shared SHARED $<TARGET_OBJECTS:getdns_objects> ${getdns_EXTRA_LINK})
target_include_directories(getdns_shared ${getdns_INCLUDES})
target_link_libraries(getdns_shared ${getdns_LIBS} ${getdns_EXTRA_LINK_FLAGS})
set_target_properties(getdns_shared PROPERTIES VERSION ${GETDNS_SHAREDLIBVERSION})
set_target_properties(getdns_shared PROPERTIES OUTPUT_NAME getdns)
set_property(TARGET getdns PROPERTY C_STANDARD 11) # The tools.
add_executable(getdns_query src/tools/getdns_query.c)
set(getdns_query_SOURCES
src/tools/getdns_query.c
)
if (NOT HAVE_GETTIMEOFDAY) if (NOT HAVE_GETTIMEOFDAY)
list(APPEND getdns_query_SOURCES target_sources(getdns_query PRIVATE src/compat/gettimeofday.c)
src/compat/gettimeofday.c
)
endif () endif ()
add_executable(getdns_query ${getdns_query_SOURCES})
target_include_directories(getdns_query PRIVATE getdns) target_include_directories(getdns_query PRIVATE getdns)
target_link_libraries(getdns_query PRIVATE getdns) target_link_libraries(getdns_query PRIVATE getdns)
@ -556,11 +527,13 @@ add_executable(getdns_server_mon src/tools/getdns_server_mon.c)
target_include_directories(getdns_server_mon target_include_directories(getdns_server_mon
PRIVATE PRIVATE
getdns getdns
${OPENSSL_INCLUDE_DIR} OpenSSL:SSL
OpenSSL:Crypto
) )
target_link_libraries(getdns_server_mon target_link_libraries(getdns_server_mon
PUBLIC PUBLIC
${OPENSSL_LIBRARIES} OpenSSL::SSL
OpenSSL::Crypto
PRIVATE PRIVATE
getdns getdns
) )