Skip to content

Commit

Permalink
Use -stdlib=libc++ on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceylo committed Jan 30, 2018
1 parent 1062e95 commit 92e0b69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -356,6 +356,9 @@ else()
# create SFML.framework
add_library(SFML ${SFML_SOURCES})

# set the target flags to use the appropriate C++ standard library
sfml_set_stdlib(SFML)

# edit target properties
set_target_properties(SFML PROPERTIES
FRAMEWORK TRUE
Expand Down
42 changes: 26 additions & 16 deletions cmake/Macros.cmake
@@ -1,5 +1,27 @@
include(CMakeParseArguments)

# set the appropriate standard library on each platform for the given target
# ex: sfml_set_stdlib(sfml-system)
function(sfml_set_stdlib target)
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
target_link_libraries(${target} "-static-libgcc" "-static-libstdc++")
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
target_link_libraries(${target} "-shared-libgcc" "-shared-libstdc++")
endif()
endif()

if (SFML_OS_MACOSX)
if (${CMAKE_GENERATOR} MATCHES "Xcode")
set_property(TARGET ${target} PROPERTY XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
else()
target_compile_options(${target} PRIVATE "-stdlib=libc++")
target_link_libraries(${target} "-stdlib=libc++")
endif()
endif()
endfunction()

# add a new target which is a SFML library
# ex: sfml_add_library(sfml-graphics
# SOURCES sprite.cpp image.cpp ...
Expand Down Expand Up @@ -50,14 +72,8 @@ macro(sfml_add_library target)
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
set_target_properties(${target} PROPERTIES FOLDER "SFML")

# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
endif()
endif()
# set the target flags to use the appropriate C++ standard library
sfml_set_stdlib(${target})

# For Visual Studio on Windows, export debug symbols (PDB files) to lib directory
if(SFML_GENERATE_PDB)
Expand Down Expand Up @@ -182,14 +198,8 @@ macro(sfml_add_example target)
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
set_target_properties(${target} PROPERTIES FOLDER "Examples")

# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
endif()
endif()
# set the target flags to use the appropriate C++ standard library
sfml_set_stdlib(${target})

# link the target to its SFML dependencies
if(THIS_DEPENDS)
Expand Down

0 comments on commit 92e0b69

Please sign in to comment.