Cmake test: was there a library compiled / linked to libC ++ or libstd ++?

I use cmake to manage my project, which uses a third-party library.

This library could be compiled / linked to libC ++ or libstd ++ (depending on version).

I know how to tell cmake to compile / link my project with libC ++ or libstdC ++, but I do not know how to verify that the library that I use was compiled / linked to libC ++ or libstd ++. Is there any cmake command to test this?

+4
source share
2 answers

For shared libraries, you can use the standard GetPrerequisites module to check if the library depends on libst ++ or lib ++.

, , boost program_options libst++ lib++:

set (_library "/usr/local/lib/libboost_program_options.dylib")
set (_prequesites "")
set (_exclude_system FALSE)
set (_recurse FALSE)
set (_exePath "")
set (_searchDirs "")
get_prerequisites(${_library} _prequesites ${_exclude_system} ${_recurse} "${_exePath}" "${_searchDirs}")
if (_prequesites MATCHES "/libstdc\\+\\+")
    message("using libstc++")
elseif (_prequesites MATCHES "/libc\\+\\+")
    message("using libc++")
else()
    message("using neither libstc++ nor libc++")
endif()

, , nm , , , __gnu_.

+5

, ? , try_compile CMake. :

try_compile(
  TRY_COMPILE_SUCCESS
  ${CMAKE_BINARY_DIR}/tmpTryDir
  ${CMAKE_MODULES_DIR}/SourceFile.cpp
  CMAKE_FLAGS
    "-DINCLUDE_DIRECTORIES=${TRY_INCLUDE_DIRS}"
    "-DLINK_DIRECTORIES=${TRY_LIBRARY_DIRS}"
    "-DLINK_LIBRARIES=${TRY_LIBRARIES}"
  COMPILE_DEFINITIONS
    "-DCOMPILER_OPTION"
)

CMake TRY_COMPILE_SUCCESS TRUE FALSE .

+2

All Articles