Permalink
Browse files

Removed the hack that copied external libs into SFML static libs, use…

…rs now have to link them explicitly
  • Loading branch information...
LaurentGomila committed Oct 16, 2013
1 parent c2a9ed6 commit dbf01a775b7545bf83fbee0e1464f3f323723187
Showing with 17 additions and 71 deletions.
  1. +13 −4 CMakeLists.txt
  2. +1 −60 cmake/Macros.cmake
  3. +3 −7 src/SFML/Graphics/CMakeLists.txt
View
@@ -190,13 +190,22 @@ install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake
install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR})
install(FILES readme.txt DESTINATION ${INSTALL_MISC_DIR})
# install 3rd-party libraries and tools on Windows and OS X
if(SFML_OS_WINDOWS)
if(ARCH_32BITS)
install(FILES extlibs/bin/x86/libsndfile-1.dll DESTINATION bin)
install(FILES extlibs/bin/x86/openal32.dll DESTINATION bin)
install(DIRECTORY extlibs/bin/x86/ DESTINATION bin)
if(SFML_COMPILER_MSVC)
install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION lib)
else()
install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION lib)
endif()
elseif(ARCH_64BITS)
install(FILES extlibs/bin/x64/libsndfile-1.dll DESTINATION bin)
install(FILES extlibs/bin/x64/openal32.dll DESTINATION bin)
install(DIRECTORY extlibs/bin/x64/ DESTINATION bin)
if(SFML_COMPILER_MSVC)
install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION lib)
else()
install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION lib)
endif()
endif()
elseif(SFML_OS_MACOSX)
install(DIRECTORY extlibs/libs-osx/Frameworks/sndfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
View
@@ -1,57 +1,5 @@
include(CMakeParseArguments)
# this macro adds external dependencies to a static target,
# compensating for the lack of a link step when building a static library.
# every compiler has its own way of doing it:
# - VC++ supports it directly through the static library flags
# - MinGW/gcc doesn't support it, but as a static library is nothing more than an archive,
# we can simply merge the external dependencies to our generated target as a post-build step
# - for other compilers and OSes, static build is not encouraged so we don't try to
# pre-link dependencies, we just "link" them so that the SFML samples can compile
# out-of-the-box (CMake forwards the dependencies automatically)
macro(sfml_static_add_libraries target)
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC)
# Windows - gcc
foreach(lib ${ARGN})
if(NOT ${lib} MATCHES ".*/.*")
string(REGEX REPLACE "(.*)/bin/.*\\.exe" "\\1" STANDARD_LIBS_PATH "${CMAKE_CXX_COMPILER}")
if(SFML_COMPILER_GCC_W64)
set(lib "${STANDARD_LIBS_PATH}/${GCC_MACHINE}/lib/lib${lib}.a")
else()
set(lib "${STANDARD_LIBS_PATH}/lib/lib${lib}.a")
endif()
endif()
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
get_target_property(TARGET_FILENAME ${target} ${BUILD_TYPE}_LOCATION)
add_custom_command(TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_AR} x ${lib}
COMMAND ${CMAKE_AR} rcs ${TARGET_FILENAME} *.o
COMMAND del *.o /f /q
VERBATIM)
endforeach()
elseif(SFML_COMPILER_MSVC)
# Visual C++
set(LIBRARIES "")
foreach(lib ${ARGN})
if(NOT ${lib} MATCHES ".*\\.lib")
set(lib ${lib}.lib)
endif()
if(MSVC_IDE AND SFML_MSVC_VERSION LESS 10)
# for Visual Studio projects < 10, we must add double quotes
# around paths because they may contain spaces
set(LIBRARIES "${LIBRARIES} &quot\\;${lib}&quot\\;")
else()
set(LIBRARIES "${LIBRARIES} \"${lib}\"")
endif()
endforeach()
set_target_properties(${target} PROPERTIES STATIC_LIBRARY_FLAGS ${LIBRARIES})
else()
# All other platforms
target_link_libraries(${target} ${ARGN})
endif()
endmacro()
# add a new target which is a SFML library
# ex: sfml_add_library(sfml-graphics
# SOURCES sprite.cpp image.cpp ...
@@ -138,14 +86,7 @@ macro(sfml_add_library target)
# link the target to its external dependencies
if(THIS_EXTERNAL_LIBS)
if(BUILD_SHARED_LIBS)
# in shared build, we use the regular linker commands
target_link_libraries(${target} ${THIS_EXTERNAL_LIBS})
else()
# in static build there's no link stage, but with some compilers it is possible to force
# the generated static library to directly contain the symbols from its dependencies
sfml_static_add_libraries(${target} ${THIS_EXTERNAL_LIBS})
endif()
target_link_libraries(${target} ${THIS_EXTERNAL_LIBS})
endif()
# add the install rule
@@ -110,13 +110,9 @@ endif()
include_directories(${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR})
# build the list of libraries to link
# GL and X11 are only needed for shared build, as they are already linked by sfml-window
set(GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY})
if(BUILD_SHARED_LIBS)
set(GRAPHICS_EXT_LIBS ${GRAPHICS_EXT_LIBS} ${OPENGL_gl_LIBRARY})
if(SFML_OS_LINUX)
set(GRAPHICS_EXT_LIBS ${GRAPHICS_EXT_LIBS} ${X11_LIBRARIES})
endif()
set(GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY} ${OPENGL_gl_LIBRARY})
if(SFML_OS_LINUX)
set(GRAPHICS_EXT_LIBS ${GRAPHICS_EXT_LIBS} ${X11_LIBRARIES})
endif()
# add preprocessor symbols

6 comments on commit dbf01a7

@Wizzard033

This comment has been minimized.

Show comment
Hide comment
@Wizzard033

Wizzard033 Oct 19, 2013

SO many issues I used to have were just fixed by this

Wizzard033 replied Oct 19, 2013

SO many issues I used to have were just fixed by this

@LaurentGomila

This comment has been minimized.

Show comment
Hide comment
@LaurentGomila

LaurentGomila Oct 20, 2013

Member

Out of curiosity, what were these issues?

Member

LaurentGomila replied Oct 20, 2013

Out of curiosity, what were these issues?

@Oberon00

This comment has been minimized.

Show comment
Hide comment
@Oberon00

Oberon00 Oct 20, 2013

Contributor

Shouldn't FindSFML.cmake be updated to support including the external libraries?

Contributor

Oberon00 replied Oct 20, 2013

Shouldn't FindSFML.cmake be updated to support including the external libraries?

@LaurentGomila

This comment has been minimized.

Show comment
Hide comment
@Wizzard033

This comment has been minimized.

Show comment
Hide comment
@Wizzard033

Wizzard033 Oct 20, 2013

When I was searching for a GUI library, I started with wanting to take a look at CEGUI
However, CEGUI and SFML both relied on GLEW and so it took me 2 days to find out how to get them to work together
When I tried to use libRocket, I ran into a similar issue, but practice with CEGUI fixed it fast
These were SFML-specific issues because most libraries force you to link a bunch of stuff to avoid this
Since then, I've ran into the issue a couple more times as well
Sometimes, I was unable to find a solution without tearing either SFML or the other library apart
Since I use nightly builds on things I use usually, that means tearing apart every nightly build
This meant that I actually avoided usage of some libraries purely because of this linking issue
I did not want to spend 10 minutes applying a fix every time a new build was released

Wizzard033 replied Oct 20, 2013

When I was searching for a GUI library, I started with wanting to take a look at CEGUI
However, CEGUI and SFML both relied on GLEW and so it took me 2 days to find out how to get them to work together
When I tried to use libRocket, I ran into a similar issue, but practice with CEGUI fixed it fast
These were SFML-specific issues because most libraries force you to link a bunch of stuff to avoid this
Since then, I've ran into the issue a couple more times as well
Sometimes, I was unable to find a solution without tearing either SFML or the other library apart
Since I use nightly builds on things I use usually, that means tearing apart every nightly build
This meant that I actually avoided usage of some libraries purely because of this linking issue
I did not want to spend 10 minutes applying a fix every time a new build was released

@LaurentGomila

This comment has been minimized.

Show comment
Hide comment
@LaurentGomila

LaurentGomila Oct 20, 2013

Member

Thanks for the details.

Member

LaurentGomila replied Oct 20, 2013

Thanks for the details.

Please sign in to comment.