I want to check if all my dependencies are compiled using libc++ or not. If that's not the case, then return a warning or an error. Some of my dependencies are shared libraries and some are static. For a shared library I currently do like this
if(MYLIB_FOUND)
    set (MYLIB_LIB "${MYLIB_LIBDIR}/lib${MYLIB_LIBRARIES}.so")
    set(MYLIB_FOUND TRUE)
    # Check if library has been compiled with -stdlib=libc++
    if(${CMAKE_VERSION} VERSION_LESS "3.16.0") 
        include(GetPrerequisites)
        GET_PREREQUISITES(${MYLIB_LIB} PREREQUISITES FALSE FALSE "" "")
        if (PREREQUISITES MATCHES "/libc\\+\\+")
            if(NOT USE_LIBCXX)
                message(WARNING "MyLib compiled using libc++ but this project does not use this flag")
                set(MYLIB_FOUND FALSE)
            endif()
        else()
            if(USE_LIBCXX)
                message(WARNING "MyLib not compiled using libc++ but this project requires this flag")
                set(MYLIB_FOUND FALSE)
            endif()
        endif()
    else()
        file(GET_RUNTIME_DEPENDENCIES RESOLVED_DEPENDENCIES_VAR MYLIB_DEPENDENCIES LIBRARIES ${MYLIB_LIB})
        if (MYLIB_DEPENDENCIES MATCHES "/libc\\+\\+")
            if(NOT USE_LIBCXX)
                message(WARNING "MyLib compiled using libc++ but this project does not use this flag")
                set(JMYLIB_FOUND FALSE)
            endif()
        else()
            if(USE_LIBCXX)
                message(WARNING "MyLib not compiled using libc++ but this project requires this flag")
                set(MYLIB_FOUND FALSE)
            endif()
        endif()
    endif()
else()
    set(MYLIB_FOUND FALSE)
endif()
How can I do the same for a static library? (Mostly CMake 3.8 and onward)
 
    