diff --git a/cmake/BLTMacros.cmake b/cmake/BLTMacros.cmake index 07e15995a..a7344c194 100644 --- a/cmake/BLTMacros.cmake +++ b/cmake/BLTMacros.cmake @@ -897,8 +897,8 @@ endmacro(blt_find_libraries) ## ## The LINK_PREPEND argument will be prepended to the library on the link line, ## while the LINK_POSTPEND will be appended to the libray on the link line. These -## values are typically "-Wl,--whole-archive", and "-Wl,--no-whole-archive" -## on linux systems +## values are defaulted to the appropriate values for CMAKE_HOST_APPLE and +## CMAKE_HOST_UNIX. CMAKE_HOST_WIN32 is not yet supported. ## ##------------------------------------------------------------------------------ macro(blt_combine_static_libraries) @@ -922,12 +922,41 @@ macro(blt_combine_static_libraries) if( NOT arg_SOURCE_LIBS ) message(FATAL_ERROR "blt_combine_static_libraries(NAME ${arg_NAME} ...) called with no given source libraries") endif() - + + if( NOT arg_LINK_PREPEND ) + if( CMAKE_HOST_APPLE ) + set( _link_prepend "-Wl,-force_load" ) + elseif( CMAKE_HOST_UNIX ) + set( _link_prepend "-Wl,--whole-archive" ) + elseif( CMAKE_HOST_WIN32 ) + set( _link_prepend "/WHOLEARCHIVE:" ) + else() + message(FATAL_ERROR "blt_combine_static_libraries does not support ${CMAKE_HOST_SYSTEM}") + endif() + else() + set( _link_prepend ${arg_LINK_PREPEND}) + endif() + + + if( NOT arg_LINK_POSTPEND ) + if( CMAKE_HOST_APPLE ) + set( _link_postpend "" ) + elseif( CMAKE_HOST_UNIX ) + set( _link_postpend "-Wl,--no-whole-archive" ) + elseif( CMAKE_HOST_WIN32 ) + set( _link_postpend "" ) + else() + message(FATAL_ERROR "blt_combine_static_libraries does not support ${CMAKE_HOST_SYSTEM}") + endif() + else() + set( _link_postpend ${arg_LINK_POSTPEND}) + endif() + set( libLinkLine "" ) foreach( lib ${arg_SOURCE_LIBS} ) - list( APPEND libLinkLine ${arg_LINK_PREPEND} ${lib} ${arg_LINK_POSTPEND} ) + list( APPEND libLinkLine ${_link_prepend} ${lib} ${_link_postpend} ) endforeach() - + if( ${arg_LIB_TYPE} STREQUAL "STATIC" ) set( _lib_type STATIC ) elseif( ${arg_LIB_TYPE} STREQUAL "SHARED" ) @@ -935,7 +964,7 @@ macro(blt_combine_static_libraries) else() message(FATAL_ERROR "blt_combine_static_libraries(NAME ${arg_NAME} ...) LIB_TYPE must be SHARED OR STATIC") endif() - + add_library ( ${arg_NAME} ${_lib_type} ${BLT_ROOT_DIR}/tests/internal/src/combine_static_library_test/dummy.cpp) target_link_libraries( ${arg_NAME} PRIVATE ${libLinkLine}) blt_register_library( NAME ${arg_NAME} diff --git a/tests/internal/src/combine_static_library_test/main.cpp b/tests/internal/src/combine_static_library_test/main.cpp index c4c57410e..6d147af1a 100644 --- a/tests/internal/src/combine_static_library_test/main.cpp +++ b/tests/internal/src/combine_static_library_test/main.cpp @@ -7,9 +7,11 @@ int main( int , char ** ) { Foo1 foo1; Foo2 foo2; + Foo3 foo3; std::cout<