Bon j'ai un problème quand je coche l'option Build shared libs, il me met un message d'erreur "bad realoc" pour un de mes fichier cpp de SFGL.
Donc je dois compiler avec l'option build shared lib de décochée, pas le choix.
Par contre, je ne parviens pas à lier SFML seul dynamiquement car l'option build shared libs est utilisée pour toutes les libs, hors que moi je voudrais lier seulement SFMl dynamiquement. (et pas sfgl sinon ça bug)
Cependant je ne vois pas comment faire, je suppose que si une librairie est liée statiquement les autres doivent l'être aussi non ?
Sinon comment le faire sans devoir utiliser la macro sfml_add_library ?
Pour l'instant je fais ça :
# add include paths of external libraries
include_directories(${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR} ${SFML_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} ${SFML_LIBRARIES})
.......Définition des autres librairies externe à lier......
sfgl_add_library(sfgl
SOURCES ${SRC}
EXTERNAL_LIBS ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY} ${GRAPHICS_EXT_LIBS} ${SYSTEM_EXT_LIBS} ${WINDOW_EXT_LIBS} ${NETWORK_EXT_LIBS})
Faudrait que je modifie la macro pour lui passer une option static ou bien shared....
Mais je ne sais pas si je peux vraiment faire ça.
Oui, c'est vrai, je ne les utilises pas à part glew.h que j'ai copié dans le dossier include de mingw.
Par contre j'ai essayer de linker SFML dynamiquement mais malgré ça j'ai des undefined reference si je ne link pas les .a de sfml à mon projet :
# include the SFGL specific macros
include(${PROJECT_SOURCE_DIR}/cmake/Macros.cmake)
# let CMake know about our additional libraries paths (on Windows and OS X)
if (WINDOWS)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers")
if(COMPILER_GCC)
if(ARCH_32BITS)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-mingw/x86")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/bin/x86")
elseif(ARCH_64BITS)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-mingw/x64")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/bin/x64")
endif()
elseif(COMPILER_MSVC)
if(ARCH_32BITS)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-msvc/x86")
elseif(ARCH_64BITS)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-msvc/x64")
endif()
endif()
elseif(MACOSX)
set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${PROJECT_SOURCE_DIR}/extlibs/headers")
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-osx/lib/")
endif()
# add the SFGL sources path
include_directories(${PROJECT_SOURCE_DIR}/src)
# define the path of our additional CMake modules
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
# set the output directory for SFGL libraries
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")
include_directories(${SFML_INCLUDE_DIR})
add_definitions(-DSFML_DYNAMIC -DSTBI_FAILURE_USERMSG)
set(INCROOT ${PROJECT_SOURCE_DIR}/include/SFGL)
set(SRCROOT ${PROJECT_SOURCE_DIR}/src/SFGL)
set(SRC
${INCROOT}/erreur.h
${SRCROOT}/erreur.cpp
${INCROOT}/utilities.h
${SRCROOT}/utilities.cpp)
sfgl_add_library(sfgl
SOURCES ${SRC}
EXTERNAL_LIBS ${SFML_LIBRARIES})
# add the modules subdirectories
add_subdirectory(Math)
add_subdirectory(BoundingAreas)
add_subdirectory(Graphics)
add_subdirectory(Lighting)
add_subdirectory(Script)
add_subdirectory(World)
add_subdirectory(Main)
PS : si tu veux un aperçu de mon autre fichier :
cmake_minimum_required(VERSION 2.8)
# define a macro that helps defining an option
macro(sfgl_set_option var default type docstring)
if(NOT DEFINED ${var})
set(${var} ${default})
endif()
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
endmacro()
# set a default build type if none was provided
# this has to be done before the project() instruction!
sfgl_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
# project name
project(SFGL)
# include the configuration file
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake)
# setup version numbers
set(VERSION_MAJOR 1)
set(VERSION_MINOR 0)
set(VERSION_PATCH 0)
set(CMAKE_CXX_FLAGS "-std=c++11 -O3 -Os ${CMAKE_CXX_FLAGS} ")
# add the sfgl header path
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
# add an option for choosing the build type (shared or static)
sfgl_set_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE to build sfgl as shared libraries, FALSE to build it as static libraries")
# add an option for building the examples
sfgl_set_option(SFGL_BUILD_EXAMPLES FALSE BOOL "TRUE to build the sfgl examples, FALSE to ignore them")
# add an option for building the API documentation
sfgl_set_option(SFGL_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
# Mac OS X specific options
if(MACOSX)
# add an option to build frameworks instead of dylibs (release only)
sfgl_set_option(SFGL_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build sfgl as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
# add an option to let the user specify a custom directory for frameworks installation (sfgl, sndfile, ...)
sfgl_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory")
endif()
# define sfgl_STATIC if the build type is not set to 'shared'
if(NOT BUILD_SHARED_LIBS)
add_definitions(-DSFGL_STATIC)
endif()
# remove SL security warnings with Visual C++
if(COMPILER_MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
endif()
# define an option for choosing between static and dynamic C runtime (Windows only)
if(WINDOWS)
sfgl_set_option(SFGL_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
# the following combination of flags is not valid
if (BUILD_SHARED_LIBS AND SFGL_USE_STATIC_STD_LIBS)
message(FATAL_ERROR "BUILD_SHARED_LIBS and sfgl_USE_STATIC_STD_LIBS cannot be used together")
endif()
# for VC++, we can apply it globally by modifying the compiler flags
if(COMPILER_MSVC AND SFGL_USE_STATIC_STD_LIBS)
foreach(flag
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
if(${flag} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
endif()
endforeach()
endif()
endif()
# disable the rpath stuff
set(CMAKE_SKIP_BUILD_RPATH TRUE)
# setup Mac OS X stuff
if(MACOSX)
# sfgl_BUILD_FRAMEWORKS needs two things :
# first, it's available only for release
# (because cmake currently doesn't allow specifying a custom framework name so XXX-d is not possible)
# secondly, it works only with BUILD_SHARED_LIBS enabled
if(SFGL_BUILD_FRAMEWORKS)
# requirement #1
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
message(FATAL_ERROR "CMAKE_BUILD_TYPE should be \"Release\" when sfgl_BUILD_FRAMEWORKS is TRUE")
return()
endif()
# requirement #2
if(NOT BUILD_SHARED_LIBS)
message(FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when sfgl_BUILD_FRAMEWORKS is TRUE")
return()
endif()
endif()
endif()
if(LINUX)
if(BUILD_SHARED_LIBS)
sfgl_set_option(SFGL_INSTALL_PKGCONFIG_FILES TRUE BOOL "TRUE to automatically install pkg-config files so other projects can find sfgl")
if(SFGL_INSTALL_PKGCONFIG_FILES)
foreach(sfgl_module IN ITEMS all)
CONFIGURE_FILE(
"tools/pkg-config/sfgl-${sfgl_module}.pc.in"
"tools/pkg-config/sfgl-${sfgl_module}.pc"
@ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfgl-${sfgl_module}.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig")
endforeach()
endif()
else()
if(SFGL_INSTALL_PKGCONFIG_FILES)
message(WARNING "No pkg-config files are provided for the static sfgl libraries (sfgl_INSTALL_PKGCONFIG_FILES will be ignored).")
endif()
endif()
endif()
# enable project folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
# add the subdirectories
add_subdirectory(src/SFGL)
if(SFGL_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(SFGL_BUILD_DOC)
add_subdirectory(doc)
endif()
# setup the install rules
if(NOT SFGL_BUILD_FRAMEWORKS)
install(DIRECTORY include
DESTINATION .
COMPONENT devel
PATTERN ".svn" EXCLUDE)
else()
# find only "root" headers
file(GLOB SFGL_HEADERS RELATIVE ${PROJECT_SOURCE_DIR} "include/SFGL/*")
# in fact we have to fool cmake to copy all the headers in subdirectories
# to do that we have to add the "root" headers to the PUBLIC_HEADER
# then we can run a post script to copy the remaining headers
# we need a dummy file in order to compile the framework
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
set(SFGL_SOURCES ${SFGL_HEADERS})
list(APPEND SFGL_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
# create sfgl.framework
add_library(SFGL ${SFGL_SOURCES})
# edit target properties
set_target_properties(SFGL PROPERTIES
FRAMEWORK TRUE
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
MACOSX_FRAMEWORK_IDENTIFIER org.sfgl-dev.sfgl
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
PUBLIC_HEADER "${SFGL_HEADERS}")
# add the remaining headers
add_custom_command(TARGET SFGL
POST_BUILD
COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFGL/* SFGL.framework/Versions/${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}/Headers)
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
# NOTE : it's not required to link agains sfgl.framework
set_target_properties(SFGL PROPERTIES
BUILD_WITH_INSTALL_RPATH 1
INSTALL_NAME_DIR "@executable_path/../Frameworks")
# install rule
install(TARGETS SFGL
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}
COMPONENT devel)
endif()
install(FILES cmake/Modules/FindSFGL.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules)
install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR})
install(FILES readme.txt DESTINATION ${INSTALL_MISC_DIR})
if(WINDOWS)
if(ARCH_32BITS)
install(FILES extlibs/bin/x86/sfml-system-2.dll DESTINATION bin)
install(FILES extlibs/bin/x86/sfml-window-2.dll DESTINATION bin)
install(FILES extlibs/bin/x86/sfml-graphics-2.dll DESTINATION bin)
install(FILES extlibs/bin/x86/sfml-network-2.dll DESTINATION bin)
install(FILES extlibs/bin/x86/sfml-audio-2.dll DESTINATION bin)
install(FILES extlibs/bin/x86/libsndfile-1.dll DESTINATION bin)
install(FILES extlibs/bin/x86/openal32.dll DESTINATION bin)
elseif(ARCH_64BITS)
install(FILES extlibs/bin/x64/libsndfile-1.dll DESTINATION bin)
install(FILES extlibs/bin/x64/openal32.dll DESTINATION bin)
endif()
elseif(MACOSX)
install(DIRECTORY extlibs/libs-osx/Frameworks/sndfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif()