2013-08-08 01:57:59 +08:00
|
|
|
|
include(CMakeParseArguments)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# 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
|
2013-08-08 01:57:59 +08:00
|
|
|
|
cmake_parse_arguments(THIS "" "" "SOURCES;DEPENDS;EXTERNAL_LIBS" ${ARGN})
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# create the target
|
|
|
|
|
add_library(${target} ${THIS_SOURCES})
|
|
|
|
|
|
2012-01-21 17:34:17 +08:00
|
|
|
|
# define the export symbol of the module
|
|
|
|
|
string(REPLACE "-" "_" NAME_UPPER "${target}")
|
|
|
|
|
string(TOUPPER "${NAME_UPPER}" NAME_UPPER)
|
|
|
|
|
set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS)
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
# adjust the output file prefix/suffix to match our conventions
|
|
|
|
|
if(BUILD_SHARED_LIBS)
|
2013-10-09 14:01:10 +08:00
|
|
|
|
if(SFML_OS_WINDOWS)
|
2010-11-05 05:21:32 +08:00
|
|
|
|
# include the major version number in Windows shared library names (but not import library names)
|
|
|
|
|
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
|
|
|
|
set_target_properties(${target} PROPERTIES SUFFIX "-${VERSION_MAJOR}${CMAKE_SHARED_LIBRARY_SUFFIX}")
|
|
|
|
|
else()
|
|
|
|
|
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
|
|
|
|
|
endif()
|
2013-10-09 14:01:10 +08:00
|
|
|
|
if (SFML_OS_WINDOWS AND SFML_COMPILER_GCC)
|
2010-11-05 05:21:32 +08:00
|
|
|
|
# on Windows/gcc get rid of "lib" prefix for shared libraries,
|
|
|
|
|
# and transform the ".dll.a" suffix into ".a" for import libraries
|
2010-08-19 23:59:24 +08:00
|
|
|
|
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)
|
2012-02-09 02:31:55 +08:00
|
|
|
|
set_target_properties(${target} PROPERTIES MINSIZEREL_POSTFIX -s)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
2010-11-05 05:21:32 +08:00
|
|
|
|
# set the version and soversion of the target (for compatible systems -- mostly Linuxes)
|
2011-05-16 14:00:30 +08:00
|
|
|
|
set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR})
|
|
|
|
|
set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
2013-02-26 02:17:46 +08:00
|
|
|
|
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
|
|
|
|
set_target_properties(${target} PROPERTIES FOLDER "SFML")
|
|
|
|
|
|
2012-04-19 01:07:47 +08:00
|
|
|
|
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
2013-10-15 21:46:50 +08:00
|
|
|
|
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)
|
2011-05-16 05:53:36 +08:00
|
|
|
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
2013-10-15 21:46:50 +08:00
|
|
|
|
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
|
|
|
|
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
|
2010-08-19 23:59:24 +08:00
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2013-02-26 02:17:46 +08:00
|
|
|
|
# if using gcc >= 4.0 or clang >= 3.0 on a non-Windows platform, we must hide public symbols by default
|
2011-10-17 01:30:37 +08:00
|
|
|
|
# (exported ones are explicitely marked)
|
2013-10-09 14:01:10 +08:00
|
|
|
|
if(NOT SFML_OS_WINDOWS AND ((SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4") OR (SFML_COMPILER_CLANG AND NOT SFML_CLANG_VERSION VERSION_LESS "3")))
|
2011-12-29 05:20:15 +08:00
|
|
|
|
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
|
2011-10-17 01:30:37 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
2014-04-13 18:42:14 +08:00
|
|
|
|
# On OS X, use Objective-C ARC
|
|
|
|
|
if(SFML_OS_MACOSX)
|
|
|
|
|
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fobjc-arc)
|
|
|
|
|
endif()
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
# link the target to its SFML dependencies
|
|
|
|
|
if(THIS_DEPENDS)
|
|
|
|
|
target_link_libraries(${target} ${THIS_DEPENDS})
|
|
|
|
|
endif()
|
|
|
|
|
|
2011-10-17 01:30:37 +08:00
|
|
|
|
# build frameworks or dylibs
|
2013-10-09 14:01:10 +08:00
|
|
|
|
if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS)
|
2012-04-19 01:07:47 +08:00
|
|
|
|
if(SFML_BUILD_FRAMEWORKS)
|
2011-10-17 01:30:37 +08:00
|
|
|
|
# adapt target to build frameworks instead of dylibs
|
2014-04-13 18:42:14 +08:00
|
|
|
|
set_target_properties(${target} PROPERTIES
|
2011-10-17 01:30:37 +08:00
|
|
|
|
FRAMEWORK TRUE
|
|
|
|
|
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
|
|
|
|
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.${target}
|
|
|
|
|
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
|
|
|
|
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
|
|
|
|
|
endif()
|
2014-04-13 18:42:14 +08:00
|
|
|
|
|
2011-10-17 01:30:37 +08:00
|
|
|
|
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
2014-04-13 18:42:14 +08:00
|
|
|
|
set_target_properties(${target} PROPERTIES
|
|
|
|
|
BUILD_WITH_INSTALL_RPATH 1
|
2011-10-17 01:30:37 +08:00
|
|
|
|
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
|
|
|
|
endif()
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
# link the target to its external dependencies
|
|
|
|
|
if(THIS_EXTERNAL_LIBS)
|
2013-10-17 02:47:14 +08:00
|
|
|
|
target_link_libraries(${target} ${THIS_EXTERNAL_LIBS})
|
2010-08-19 23:59:24 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# add the install rule
|
|
|
|
|
install(TARGETS ${target}
|
|
|
|
|
RUNTIME DESTINATION bin COMPONENT bin
|
2014-04-13 18:42:14 +08:00
|
|
|
|
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
|
2011-10-17 01:30:37 +08:00
|
|
|
|
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
|
2011-08-20 18:14:55 +08:00
|
|
|
|
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
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
|
2013-08-08 01:57:59 +08:00
|
|
|
|
cmake_parse_arguments(THIS "GUI_APP" "" "SOURCES;DEPENDS" ${ARGN})
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
2013-02-22 03:25:11 +08:00
|
|
|
|
# set a source group for the source files
|
|
|
|
|
source_group("" FILES ${THIS_SOURCES})
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
# create the target
|
2013-10-09 14:01:10 +08:00
|
|
|
|
if(THIS_GUI_APP AND SFML_OS_WINDOWS)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
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)
|
|
|
|
|
|
2013-02-26 02:17:46 +08:00
|
|
|
|
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
|
|
|
|
set_target_properties(${target} PROPERTIES FOLDER "Examples")
|
|
|
|
|
|
2012-04-19 01:07:47 +08:00
|
|
|
|
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
|
2013-10-15 21:46:50 +08:00
|
|
|
|
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)
|
2011-05-16 05:53:36 +08:00
|
|
|
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-static-libgcc -static-libstdc++")
|
2013-10-15 21:46:50 +08:00
|
|
|
|
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
|
|
|
|
|
set_target_properties(${target} PROPERTIES LINK_FLAGS "-shared-libgcc -shared-libstdc++")
|
2010-08-19 23:59:24 +08:00
|
|
|
|
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)
|
|
|
|
|
|
2013-04-06 16:20:58 +08:00
|
|
|
|
# install the example's source code
|
|
|
|
|
install(FILES ${THIS_SOURCES}
|
|
|
|
|
DESTINATION ${INSTALL_MISC_DIR}/examples/${target}
|
|
|
|
|
COMPONENT examples)
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
# 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}
|
2013-04-06 16:20:58 +08:00
|
|
|
|
COMPONENT examples)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
endif()
|
2013-08-08 01:57:59 +08:00
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
endmacro()
|