Added support for the CMake build system
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1550 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
aa612ec63a
commit
a991fe8e4d
144 changed files with 2086 additions and 7033 deletions
48
cmake/Config.cmake
Normal file
48
cmake/Config.cmake
Normal file
|
@ -0,0 +1,48 @@
|
|||
|
||||
# detect the OS
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
||||
set(WINDOWS 1)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(LINUX 1)
|
||||
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
set(MACOSX 1)
|
||||
else()
|
||||
message(WARNING "Unsupported operating system")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# detect the architecture
|
||||
# note: this test won't work for cross-compilation
|
||||
include(CheckTypeSize)
|
||||
check_type_size(void* SIZEOF_VOID_PTR)
|
||||
if(${SIZEOF_VOID_PTR} MATCHES "^8$")
|
||||
set(ARCH_BITS 64)
|
||||
else()
|
||||
set(ARCH_BITS 32)
|
||||
endif()
|
||||
|
||||
# detect the compiler and its version
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(COMPILER_GCC 1)
|
||||
execute_process(COMMAND "${CMAKE_CXX_COMPILER}" "-dumpversion" OUTPUT_VARIABLE GCC_VERSION_OUTPUT)
|
||||
string(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" GCC_VERSION "${GCC_VERSION_OUTPUT}")
|
||||
elseif(MSVC_VERSION EQUAL 1400)
|
||||
set(COMPILER_MSVC 1)
|
||||
set(MSVC_VERSION 2005)
|
||||
elseif(MSVC_VERSION EQUAL 1500)
|
||||
set(COMPILER_MSVC 1)
|
||||
set(MSVC_VERSION 2008)
|
||||
elseif(MSVC_VERSION EQUAL 1600)
|
||||
set(COMPILER_MSVC 1)
|
||||
set(MSVC_VERSION 2010)
|
||||
else()
|
||||
message(WARNING "Unsupported compiler")
|
||||
return()
|
||||
endif()
|
||||
|
||||
# define the install directory for miscellaneous files
|
||||
if(WINDOWS)
|
||||
set(INSTALL_MISC_DIR .)
|
||||
elseif(UNIX)
|
||||
set(INSTALL_MISC_DIR share/SFML)
|
||||
endif()
|
191
cmake/Macros.cmake
Normal file
191
cmake/Macros.cmake
Normal file
|
@ -0,0 +1,191 @@
|
|||
|
||||
# some of these macros are inspired from the boost/cmake macros
|
||||
|
||||
# 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
|
||||
# - we don't do anything for other compilers and OSes; static build is not encouraged on Unix (Linux, Mac OS X)
|
||||
# where shared libraries are properly managed and have many advantages over static libraries
|
||||
macro(sfml_static_add_libraries target)
|
||||
if(WINDOWS AND COMPILER_GCC)
|
||||
# Windows - gcc
|
||||
foreach(lib ${ARGN})
|
||||
if(NOT ${lib} MATCHES ".*/.*")
|
||||
string(REGEX REPLACE "(.*)/bin/.*\\.exe" "\\1" STANDARD_LIBS_PATH "${CMAKE_CXX_COMPILER}")
|
||||
set(lib "${STANDARD_LIBS_PATH}/lib/lib${lib}.a")
|
||||
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(MSVC)
|
||||
# Visual C++
|
||||
set(LIBRARIES "")
|
||||
foreach(lib ${ARGN})
|
||||
if(NOT ${lib} MATCHES ".*\\.lib")
|
||||
set(lib ${lib}.lib)
|
||||
endif()
|
||||
set(LIBRARIES "${LIBRARIES} ${lib}")
|
||||
endforeach()
|
||||
set_target_properties(${target} PROPERTIES STATIC_LIBRARY_FLAGS ${LIBRARIES})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# check if a value is contained in a list
|
||||
# sets ${var} to TRUE if the value is found
|
||||
macro(sfml_list_contains var value)
|
||||
set(${var})
|
||||
foreach(value2 ${ARGN})
|
||||
if(${value} STREQUAL ${value2})
|
||||
set(${var} TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
# parse a list of arguments and options
|
||||
# ex: sfml_parse_arguments(THIS "SOURCES;DEPENDS" "FLAG" FLAG SOURCES s1 s2 s3 DEPENDS d1 d2)
|
||||
# will define the following variables:
|
||||
# - THIS_SOURCES (s1 s2 s3)
|
||||
# - THIS_DEPENDS (d1 d2)
|
||||
# - THIS_FLAG TRUE
|
||||
macro(sfml_parse_arguments prefix arg_names option_names)
|
||||
foreach(arg_name ${arg_names})
|
||||
set(${prefix}_${arg_name})
|
||||
endforeach()
|
||||
foreach(option_name ${option_names})
|
||||
set(${prefix}_${option_name} FALSE)
|
||||
endforeach()
|
||||
set(current_arg_name)
|
||||
set(current_arg_list)
|
||||
foreach(arg ${ARGN})
|
||||
sfml_list_contains(is_arg_name ${arg} ${arg_names})
|
||||
if(is_arg_name)
|
||||
set(${prefix}_${current_arg_name} ${current_arg_list})
|
||||
set(current_arg_name ${arg})
|
||||
set(current_arg_list)
|
||||
else()
|
||||
sfml_list_contains(is_option ${arg} ${option_names})
|
||||
if(is_option)
|
||||
set(${prefix}_${arg} TRUE)
|
||||
else()
|
||||
set(current_arg_list ${current_arg_list} ${arg})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
set(${prefix}_${current_arg_name} ${current_arg_list})
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML library
|
||||
# ex: sfml_add_library(sfml-graphics
|
||||
# SOURCES sprite.cpp image.cpp ...
|
||||
# DEPENDS sfml-window sfml-system
|
||||
# EXTERNAL_LIBS opengl freetype ...)
|
||||
macro(sfml_add_library target)
|
||||
|
||||
# parse the arguments
|
||||
sfml_parse_arguments(THIS "SOURCES;DEPENDS;EXTERNAL_LIBS" "" ${ARGN})
|
||||
|
||||
# create the target
|
||||
add_library(${target} ${THIS_SOURCES})
|
||||
|
||||
# adjust the output file prefix/suffix to match our conventions
|
||||
if(BUILD_SHARED_LIBS)
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
if (WINDOWS AND COMPILER_GCC)
|
||||
set_target_properties(${target} PROPERTIES PREFIX "")
|
||||
set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".a")
|
||||
endif()
|
||||
else()
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -s-d)
|
||||
set_target_properties(${target} PROPERTIES RELEASE_POSTFIX -s)
|
||||
endif()
|
||||
|
||||
# insert the major version number in the output filename
|
||||
string(REGEX REPLACE "sfml(-.*)" "sfml${VERSION_MAJOR}\\1" OUTPUT_NAME ${target})
|
||||
set_target_properties(${target} PROPERTIES OUTPUT_NAME ${OUTPUT_NAME})
|
||||
|
||||
# for gcc 4.x on Windows, we add the -static-libgcc linker flag to get rid of an extra gcc DLL
|
||||
if(WINDOWS AND COMPILER_GCC)
|
||||
if(${GCC_VERSION} MATCHES "4\\..*")
|
||||
set_target_properties(${target} PROPERTIES LINK_FLAGS -static-libgcc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# link the target to its SFML dependencies
|
||||
if(THIS_DEPENDS)
|
||||
target_link_libraries(${target} ${THIS_DEPENDS})
|
||||
endif()
|
||||
|
||||
# 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()
|
||||
endif()
|
||||
|
||||
# add the install rule
|
||||
install(TARGETS ${target}
|
||||
RUNTIME DESTINATION bin COMPONENT bin
|
||||
LIBRARY DESTINATION lib COMPONENT bin
|
||||
ARCHIVE DESTINATION lib COMPONENT devel)
|
||||
|
||||
endmacro()
|
||||
|
||||
# add a new target which is a SFML example
|
||||
# ex: sfml_add_example(ftp
|
||||
# SOURCES ftp.cpp ...
|
||||
# DEPENDS sfml-network sfml-system)
|
||||
macro(sfml_add_example target)
|
||||
|
||||
# parse the arguments
|
||||
sfml_parse_arguments(THIS "SOURCES;DEPENDS" "GUI_APP" ${ARGN})
|
||||
|
||||
# create the target
|
||||
if(THIS_GUI_APP AND WINDOWS)
|
||||
add_executable(${target} WIN32 ${THIS_SOURCES})
|
||||
target_link_libraries(${target} sfml-main)
|
||||
else()
|
||||
add_executable(${target} ${THIS_SOURCES})
|
||||
endif()
|
||||
|
||||
# set the debug suffix
|
||||
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
||||
|
||||
# for gcc 4.x on Windows, we add the -static-libgcc linker flag to get rid of an extra gcc DLL
|
||||
if(WINDOWS AND COMPILER_GCC)
|
||||
if(${GCC_VERSION} MATCHES "4\\..*")
|
||||
set_target_properties(${target} PROPERTIES LINK_FLAGS -static-libgcc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# link the target to its SFML dependencies
|
||||
if(THIS_DEPENDS)
|
||||
target_link_libraries(${target} ${THIS_DEPENDS})
|
||||
endif()
|
||||
|
||||
# add the install rule
|
||||
install(TARGETS ${target}
|
||||
RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples)
|
||||
|
||||
# install the example's resources as well
|
||||
set(EXAMPLE_RESOURCES "${CMAKE_SOURCE_DIR}/examples/${target}/resources")
|
||||
if(EXISTS ${EXAMPLE_RESOURCES})
|
||||
install(DIRECTORY ${EXAMPLE_RESOURCES}
|
||||
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
||||
COMPONENT examples
|
||||
PATTERN ".svn" EXCLUDE)
|
||||
endif()
|
||||
endmacro()
|
62
cmake/Modules/FindGLEW.cmake
Normal file
62
cmake/Modules/FindGLEW.cmake
Normal file
|
@ -0,0 +1,62 @@
|
|||
#
|
||||
# Try to find GLEW library and include path.
|
||||
# Once done this will define
|
||||
#
|
||||
# GLEW_FOUND
|
||||
# GLEW_INCLUDE_PATH
|
||||
# GLEW_LIBRARY
|
||||
#
|
||||
|
||||
IF (WIN32)
|
||||
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
||||
$ENV{PROGRAMFILES}/GLEW/include
|
||||
${GLEW_ROOT_DIR}/include
|
||||
DOC "The directory where GL/glew.h resides")
|
||||
|
||||
IF (NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||
FIND_LIBRARY( GLEW_LIBRARY
|
||||
NAMES glew64 glew64s
|
||||
PATHS
|
||||
$ENV{PROGRAMFILES}/GLEW/lib
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
||||
DOC "The GLEW library (64-bit)"
|
||||
)
|
||||
ELSE(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||
FIND_LIBRARY( GLEW_LIBRARY
|
||||
NAMES glew GLEW glew32 glew32s
|
||||
PATHS
|
||||
$ENV{PROGRAMFILES}/GLEW/lib
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
|
||||
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
|
||||
DOC "The GLEW library"
|
||||
)
|
||||
ENDIF(NV_SYSTEM_PROCESSOR STREQUAL "AMD64")
|
||||
ELSE (WIN32)
|
||||
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
|
||||
/usr/include
|
||||
/usr/local/include
|
||||
/sw/include
|
||||
/opt/local/include
|
||||
${GLEW_ROOT_DIR}/include
|
||||
DOC "The directory where GL/glew.h resides")
|
||||
|
||||
FIND_LIBRARY( GLEW_LIBRARY
|
||||
NAMES GLEW glew
|
||||
PATHS
|
||||
/usr/lib64
|
||||
/usr/lib
|
||||
/usr/local/lib64
|
||||
/usr/local/lib
|
||||
/sw/lib
|
||||
/opt/local/lib
|
||||
${GLEW_ROOT_DIR}/lib
|
||||
DOC "The GLEW library")
|
||||
ENDIF (WIN32)
|
||||
|
||||
SET(GLEW_FOUND "NO")
|
||||
IF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
||||
SET(GLEW_LIBRARIES ${GLEW_LIBRARY})
|
||||
SET(GLEW_FOUND "YES")
|
||||
ENDIF (GLEW_INCLUDE_PATH AND GLEW_LIBRARY)
|
||||
|
29
cmake/Modules/FindSndfile.cmake
Normal file
29
cmake/Modules/FindSndfile.cmake
Normal file
|
@ -0,0 +1,29 @@
|
|||
# - Find sndfile
|
||||
# Find the native sndfile includes and libraries
|
||||
#
|
||||
# SNDFILE_INCLUDE_DIR - where to find sndfile.h, etc.
|
||||
# SNDFILE_LIBRARIES - List of libraries when using libsndfile.
|
||||
# SNDFILE_FOUND - True if libsndfile found.
|
||||
|
||||
if(SNDFILE_INCLUDE_DIR)
|
||||
# Already in cache, be silent
|
||||
set(SNDFILE_FIND_QUIETLY TRUE)
|
||||
endif(SNDFILE_INCLUDE_DIR)
|
||||
|
||||
find_path(SNDFILE_INCLUDE_DIR sndfile.h)
|
||||
|
||||
find_library(SNDFILE_LIBRARY NAMES sndfile sndfile-1)
|
||||
|
||||
# Handle the QUIETLY and REQUIRED arguments and set SNDFILE_FOUND to TRUE if
|
||||
# all listed variables are TRUE.
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(SNDFILE DEFAULT_MSG
|
||||
SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY)
|
||||
|
||||
if(SNDFILE_FOUND)
|
||||
set(SNDFILE_LIBRARIES ${SNDFILE_LIBRARY})
|
||||
else(SNDFILE_FOUND)
|
||||
set(SNDFILE_LIBRARIES)
|
||||
endif(SNDFILE_FOUND)
|
||||
|
||||
mark_as_advanced(SNDFILE_INCLUDE_DIR SNDFILE_LIBRARY)
|
Loading…
Add table
Add a link
Reference in a new issue