mirror of
https://github.com/SFML/CSFML.git
synced 2025-10-18 18:28:07 +08:00
65 lines
3.0 KiB
CMake
65 lines
3.0 KiB
CMake
|
|
# add a new target which is a CSFML library
|
|
# ex: csfml_add_library(csfml-graphics
|
|
# SOURCES sprite.cpp image.cpp ...
|
|
# DEPENDS sfml-window sfml-system)
|
|
macro(csfml_add_library target)
|
|
|
|
# parse the arguments
|
|
cmake_parse_arguments(THIS "" "" "SOURCES;DEPENDS;EXTERNAL_LIBS" ${ARGN})
|
|
|
|
# create the target
|
|
add_library(${target} ${THIS_SOURCES})
|
|
|
|
# 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)
|
|
|
|
if(SFML_OS_WINDOWS)
|
|
# 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()
|
|
if (SFML_OS_WINDOWS AND SFML_COMPILER_GCC)
|
|
# on Windows/gcc get rid of "lib" prefix for shared libraries,
|
|
# and transform the ".dll.a" suffix into ".a" for import libraries
|
|
set_target_properties(${target} PROPERTIES PREFIX "")
|
|
set_target_properties(${target} PROPERTIES IMPORT_SUFFIX ".a")
|
|
endif()
|
|
|
|
# set the version and soversion of the target (for compatible systems -- mostly Linuxes)
|
|
set_target_properties(${target} PROPERTIES SOVERSION ${VERSION_MAJOR})
|
|
set_target_properties(${target} PROPERTIES VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
|
|
|
|
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
|
|
set_target_properties(${target} PROPERTIES FOLDER "CSFML")
|
|
|
|
# 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()
|
|
|
|
# if using gcc >= 4.0 or clang >= 3.0 on a non-Windows platform, we must hide public symbols by default
|
|
# (exported ones are explicitely marked)
|
|
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")))
|
|
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
|
|
endif()
|
|
|
|
# link the target to its external dependencies (C++ SFML libraries)
|
|
target_link_libraries(${target} ${THIS_DEPENDS})
|
|
|
|
# add the install rule
|
|
install(TARGETS ${target}
|
|
RUNTIME DESTINATION bin COMPONENT bin
|
|
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
|
|
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel)
|
|
|
|
endmacro()
|