Reputation: 4269
I would like to compile my c++ library with both clang and gnu using cmake. Cmake figures out the compiler for me, bu For clang I want to use libc++ and for gnu libstdc++ as they are the corresponding standard libraries. Is there a way to write this in a cmake script conditionally on the compiler. Writing -stdlib=libc++ gives problems with gcc and vice-versa.
Anyone knows how to handle this?
Or can I set my compiler such that it picks the right library automatically?
Cheers, Mike
Upvotes: 5
Views: 2509
Reputation: 1061
Something like this should work:
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
Upvotes: 4