weak-link libraries
Linking Python modules modules is tricky, they must be weak-linked (can crash on osx otherwise), but on some platforms it's not possible afaik (win).
An elegant idea is to be found in vtk, where they first check if libraries allow undefined symbols (VTK_UNDEFINED_SYMBOLS_ALLOWED is defined when including the file TargetLinkLibrariesWithDynamicLookup.cmake) then a macro to weak link a target is defined:
macro( target_link_libraries_with_dynamic_lookup target )
if ( ${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
set_target_properties( ${target} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup" )
elseif(VTK_UNDEFINED_SYMBOLS_ALLOWED)
# linker allows undefined symbols, let's just not link
else()
target_link_libraries ( ${target} ${ARGN} )
endif()
endmacro()
then you would use:
target_link_libraries_with_dynamic_lookup (foo ${PYTHON_LIBRARIES})
I dont know if such a feature is already exposed in cmake, or if it could be included as a new command, sub-option of target_link_libraries, as a built-in module.
Edited by Julien Schueller