So it looks like it is actually impossible to link static libraries into a static library as I was trying to do, but it is possible to conditionally include a library/libraries if they do not exist. The following CMakeLists code shows a basic way of checking if some required libraries exist and if they do including them in the final library, and giving a #define
in the code to know if they are available to you or not:
cmake_minimum_required(VERSION 2.8)
project(simplog)
configure_file (
"SimpLogConfig.h.in"
"SimpLogConfig.h"
@ONLY
)
set( CMAKE_C_COMPILER "clang" )
find_library( BFD_LIBRARY bfd )
find_library( IBERTY_LIBRARY iberty )
find_path(
IBERTY_HEADER_PATH libiberty.h
PATHS
/usr/include/libiberty
/usr/local/include/libiberty.h
)
include_directories(
${IBERTY_HEADER_PATH}
${PROJECT_BINARY_DIR}
)
set( PACKAGE "SimpLog" )
set( PACKAGE_VERSION "0.0.1" )
if( BFD_LIBRARY AND IBERTY_LIBRARY )
option( BETTER_BACKTRACE "" ON )
add_library( backtrace-symbols STATIC backtrace-symbols.c )
target_link_libraries( backtrace-symbols ${BFD_LIBRARY} ${IBERTY_LIBRARY} ${CMAKE_DL_LIBS} )
set( LIBS $(LIBS) backtrace-symbols )
else()
option( BETTER_BACKTRACE "" OFF )
set( LIBS $(LIBS) "" )
endif()
add_library( simplog STATIC simplog.c )
target_link_libraries( simplog $(LIBS) )