Skip to content

Commit

Permalink
added default prepend/postpend values for CMAKE_HOST_APPLE and CMAKE_…
Browse files Browse the repository at this point in the history
…HOST_UNIX
  • Loading branch information
rrsettgast committed Jun 5, 2018
1 parent c52d2df commit 788fc5f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
41 changes: 35 additions & 6 deletions cmake/BLTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -922,20 +922,49 @@ 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" )
set( _lib_type SHARED )
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}
Expand Down
2 changes: 2 additions & 0 deletions tests/internal/src/combine_static_library_test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ int main( int , char ** )
{
Foo1 foo1;
Foo2 foo2;
Foo3 foo3;

std::cout<<foo1.output()<<std::endl;
std::cout<<foo2.output()<<std::endl;
std::cout<<foo3.output()<<std::endl;

return 0;
}

0 comments on commit 788fc5f

Please sign in to comment.