2017-11-01 11:57:51 -07:00
cmake_minimum_required ( VERSION 3.0.2 )
2013-09-12 14:44:36 -07:00
2015-01-30 07:39:05 -08:00
# Define a macro that helps defining an option
2013-09-12 14:44:36 -07:00
macro ( tgui_set_option var default type docstring )
if ( NOT DEFINED ${ var } )
set ( ${ var } ${ default } )
endif ( )
set ( ${ var } ${ ${var } } CACHE ${ type } ${ docstring } FORCE )
endmacro ( )
2015-11-04 01:24:02 -08:00
# Define a macro to add compiler flags
macro ( tgui_add_cxx_flag flag )
string ( REGEX REPLACE "\\+" "\\\\+" escapedFlag ${ flag } )
if ( NOT ( ${ CMAKE_CXX_FLAGS } MATCHES ".*${escapedFlag}.*" ) )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" CACHE STRING "C++ compiler flags" FORCE )
endif ( )
endmacro ( )
2017-09-07 06:38:35 -07:00
macro ( tgui_remove_cxx_flag flagToRemove )
string ( REPLACE " " ";" TGUI_CXX_FLAGS_LIST ${ CMAKE_CXX_FLAGS } )
set ( TGUI_TEMP_CXX_FLAGS "" )
foreach ( flag ${ TGUI_CXX_FLAGS_LIST } )
if ( NOT ( ${ flag } STREQUAL "${flagToRemove}" ) )
set ( TGUI_TEMP_CXX_FLAGS "${TGUI_TEMP_CXX_FLAGS} ${flag}" )
endif ( )
endforeach ( flag )
set ( CMAKE_CXX_FLAGS "${TGUI_TEMP_CXX_FLAGS}" )
endmacro ( )
2015-01-30 07:39:05 -08:00
# Set a default build type and module path if none was provided
tgui_set_option ( CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)" )
tgui_set_option ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" STRING "The path to the cmake modules. This path must contain the FindSFML.cmake file." )
2013-09-12 14:44:36 -07:00
2015-08-27 17:22:58 -07:00
# Android specific stuff which has to be set before CMake detects/configures the toolchain.
# If not building on android they will be unset later.
# Define the minimum API level to be used
tgui_set_option ( ANDROID_API_MIN 9 STRING "Choose the Android API level to be used (minimum 9)" )
# Mirror the setting for the toolchain file
set ( ANDROID_NATIVE_API_LEVEL ${ ANDROID_API_MIN } )
# Define the path to the Android NDK
tgui_set_option ( ANDROID_NDK "$ENV{ANDROID_NDK}" PATH "Path to the Android NDK" )
# Define the STL implementation to be used
tgui_set_option ( ANDROID_STL c++_shared STRING "Choose the STL implementation to be used (experimental)" )
# Default the ABI to ARM v7a for hardware floating point
if ( NOT ANDROID_ABI )
set ( ANDROID_ABI armeabi-v7a )
endif ( )
2015-01-30 07:39:05 -08:00
# Project name
2013-09-12 14:44:36 -07:00
project ( tgui )
# project version
SET ( MAJOR_VERSION 0 )
2016-06-30 07:12:43 -07:00
SET ( MINOR_VERSION 8 )
2014-03-21 09:27:37 -07:00
SET ( PATCH_VERSION 0 )
2013-09-12 14:44:36 -07:00
2015-01-30 07:39:05 -08:00
# Include the configuration file
2013-09-26 03:49:53 -07:00
include ( ${ CMAKE_CURRENT_SOURCE_DIR } /cmake/Config.cmake )
2015-01-30 07:39:05 -08:00
# Add an option for choosing the build type (shared or static)
if ( NOT ( SFML_OS_IOS OR SFML_OS_ANDROID ) )
tgui_set_option ( TGUI_SHARED_LIBS TRUE BOOL "TRUE to build TGUI as a shared library, FALSE to build it as a static library" )
else ( )
if ( SFML_OS_IOS )
set ( TGUI_SHARED_LIBS FALSE )
elseif ( SFML_OS_ANDROID )
set ( TGUI_SHARED_LIBS TRUE )
endif ( )
endif ( )
2015-07-19 09:20:11 -07:00
# Add option to build the examples
if ( SFML_OS_IOS OR SFML_OS_ANDROID )
set ( TGUI_BUILD_EXAMPLES FALSE )
else ( )
tgui_set_option ( TGUI_BUILD_EXAMPLES FALSE BOOL "TRUE to build the TGUI examples, FALSE to ignore them" )
endif ( )
2015-01-30 07:39:05 -08:00
2017-08-26 08:27:28 -07:00
tgui_set_option ( TGUI_BUILD_TESTS FALSE BOOL "TRUE to build the TGUI tests" )
tgui_set_option ( TGUI_BUILD_GUI_BUILDER FALSE BOOL "TRUE to compile the GUI Builder" )
tgui_set_option ( TGUI_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it" )
2015-01-30 07:39:05 -08:00
# Set compile flags for gcc and clang
if ( SFML_OS_ANDROID )
2017-09-07 06:38:35 -07:00
tgui_remove_cxx_flag ( -fno-exceptions )
tgui_remove_cxx_flag ( -fno-rtti )
2015-01-30 07:39:05 -08:00
2017-09-07 06:38:35 -07:00
# TGUI was only successfully tested on Android with NDK 12b, which did not work when -std=c++1y (or -std=c++14) is defined
tgui_add_cxx_flag ( -std=c++11 )
2015-01-30 07:39:05 -08:00
2015-11-04 01:24:02 -08:00
tgui_add_cxx_flag ( -fexceptions )
tgui_add_cxx_flag ( -frtti )
2014-02-06 06:57:40 -08:00
2016-02-09 07:23:58 -08:00
set ( TGUI_ACTIVITY_CMAKE_CXX_FLAGS ${ CMAKE_CXX_FLAGS } )
2015-11-04 01:24:02 -08:00
elseif ( SFML_COMPILER_GCC OR SFML_COMPILER_CLANG )
tgui_add_cxx_flag ( -Wall )
tgui_add_cxx_flag ( -Wextra )
tgui_add_cxx_flag ( -Wshadow )
tgui_add_cxx_flag ( -Wno-long-long )
tgui_add_cxx_flag ( -pedantic )
2017-09-13 10:38:01 -07:00
2017-09-17 05:32:10 -07:00
if ( SFML_COMPILER_GCC AND SFML_OS_WINDOWS )
# gnu++14 instead of c++14 because TDM-GCC 5.1 did not declare _fullpath without enabling GNU extensions (other tested MinGW versions did not require it)
tgui_add_cxx_flag ( -std=gnu++14 )
else ( )
# The -std=c++14 flag was added in GCC 4.9 and Clang 3.5
tgui_add_cxx_flag ( -std=c++14 )
endif ( )
2015-11-04 01:24:02 -08:00
# On mac, clang needs another parameter
if ( SFML_COMPILER_CLANG AND SFML_OS_MACOSX )
tgui_add_cxx_flag ( -stdlib=libc++ )
2013-10-11 13:55:00 -07:00
endif ( )
2013-09-12 14:44:36 -07:00
endif ( )
# Define an option for choosing between static and dynamic C runtime (VC++ only)
2015-01-30 07:39:05 -08:00
if ( SFML_OS_WINDOWS )
2013-09-12 14:44:36 -07:00
tgui_set_option ( TGUI_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs. This option has to match with the one from sfml." )
2013-10-16 03:38:47 -07:00
# The following combination of flags is not valid
2013-10-16 07:46:01 -07:00
if ( TGUI_SHARED_LIBS AND TGUI_USE_STATIC_STD_LIBS )
message ( FATAL_ERROR "TGUI_SHARED_LIBS and TGUI_USE_STATIC_STD_LIBS cannot be used together" )
2013-10-16 03:38:47 -07:00
endif ( )
2013-09-12 14:44:36 -07:00
# Apply it globally by modifying the compiler flags
2013-10-16 03:38:47 -07:00
if ( SFML_COMPILER_MSVC AND TGUI_USE_STATIC_STD_LIBS )
2013-09-12 14:44:36 -07:00
foreach ( flag
C M A K E _ C X X _ F L A G S C M A K E _ C X X _ F L A G S _ D E B U G C M A K E _ C X X _ F L A G S _ R E L E A S E
C M A K E _ C X X _ F L A G S _ M I N S I Z E R E L C M A K E _ C X X _ F L A G S _ R E L W I T H D E B I N F O )
if ( ${ flag } MATCHES "/MD" )
string ( REGEX REPLACE "/MD" "/MT" ${ flag } "${${flag}}" )
endif ( )
endforeach ( )
endif ( )
endif ( )
2015-01-30 07:39:05 -08:00
# Mac OS X specific options
if ( SFML_OS_MACOSX )
2015-02-05 14:21:47 -08:00
# Add an option to build framework instead of dylib (release only)
tgui_set_option ( TGUI_BUILD_FRAMEWORK FALSE BOOL "TRUE to build TGUI as a framework library (release only), FALSE to build according to TGUI_SHARED_LIBS" )
2015-01-30 07:39:05 -08:00
2015-02-05 14:21:47 -08:00
# Add an option to let the user specify a custom directory for framework installation
tgui_set_option ( CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory" )
2016-09-15 05:19:44 -07:00
# Only the default architecture (i.e. 64-bit) is supported
if ( CMAKE_OSX_ARCHITECTURES AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64" )
message ( FATAL_ERROR "Only 64-bit architecture is supported" )
return ( )
2015-02-05 14:21:47 -08:00
endif ( )
# Enable to use of rpath according to CMake Policy CMP0042
set ( CMAKE_MACOSX_RPATH 1 )
if ( TGUI_BUILD_FRAMEWORK )
# Frameworks are only available for release (because cmake currently doesn't allow specifying a custom framework name so XXX-d is not possible)
if ( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
message ( FATAL_ERROR "CMAKE_BUILD_TYPE should be \" Release\ " when TGUI_BUILD_FRAMEWORK is TRUE" )
return ( )
endif ( )
# Frameworks only work with TGUI_SHARED_LIBS enabled
if ( NOT TGUI_SHARED_LIBS )
message ( FATAL_ERROR "TGUI_SHARED_LIBS should be TRUE when TGUI_BUILD_FRAMEWORK is TRUE" )
return ( )
endif ( )
endif ( )
2015-01-30 07:39:05 -08:00
endif ( )
# Android options
if ( SFML_OS_ANDROID )
2015-08-27 17:22:58 -07:00
if ( ${ ANDROID_API_MIN } LESS 9 )
message ( FATAL_ERROR "Android API level must be equal or greater than 9. Please adjust the CMake variable 'ANDROID_API_MIN'." )
endif ( )
if ( NOT ANDROID_NDK )
message ( FATAL_ERROR "The Android NDK couldn't be found. Please adjust the CMake variable 'ANDROID_NDK' to point to the NDK directory." )
endif ( )
2015-01-30 07:39:05 -08:00
2015-08-27 17:22:58 -07:00
# CMake doesn't support defining the STL to be used with Nsight Tegra, so warn the user
if ( CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android" )
message ( WARNING "CMake might not properly support setting the STL. Make sure to adjust all generated library projects!" )
2013-10-12 02:48:37 -07:00
endif ( )
2015-01-30 07:39:05 -08:00
# Install everything in $NDK/sources/ because this path is appended by the NDK (convenient)
set ( CMAKE_INSTALL_PREFIX ${ ANDROID_NDK } /sources/tgui )
# We install libs in a subdirectory named after the ABI (e.g. lib/armeabi/libtgui.so)
set ( LIB_SUFFIX "/${ANDROID_ABI}" )
2015-08-27 17:22:58 -07:00
# Pass shared STL configuration (if any)
if ( ANDROID_STL MATCHES "_shared" )
add_definitions ( "-DSTL_LIBRARY=${ANDROID_STL}" )
endif ( )
# Macro to find packages on the host OS
# This is the same as in the toolchain file, which is here for Nsight Tegra VS since it won't use the Android toolchain file
if ( CMAKE_VS_PLATFORM_NAME STREQUAL "Tegra-Android" )
macro ( find_host_package )
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER )
if ( CMAKE_HOST_WIN32 )
set ( WIN32 1 )
set ( UNIX )
elseif ( CMAKE_HOST_APPLE )
set ( APPLE 1 )
set ( UNIX )
endif ( )
find_package ( ${ ARGN } )
set ( WIN32 )
set ( APPLE )
set ( UNIX 1 )
set ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
endmacro ( )
endif ( )
else ( )
unset ( ANDROID_ABI CACHE )
unset ( ANDROID_API_MIN CACHE )
unset ( ANDROID_STL CACHE )
unset ( ANDROID_NATIVE_API_LEVEL CACHE )
unset ( ANDROID_NDK CACHE )
2013-10-12 02:48:37 -07:00
endif ( )
2017-08-27 02:52:50 -07:00
# Link SFML in the same way as TGUI, unless SFML_STATIC_LIBRARIES is manually specified
if ( NOT DEFINED SFML_STATIC_LIBRARIES )
if ( TGUI_SHARED_LIBS )
set ( SFML_STATIC_LIBRARIES FALSE )
else ( )
2013-09-12 14:44:36 -07:00
set ( SFML_STATIC_LIBRARIES TRUE )
2017-08-27 02:52:50 -07:00
endif ( )
endif ( )
2014-01-15 10:35:40 -08:00
2017-08-27 02:52:50 -07:00
# Attempt to find the SFML dependencies when linking statically
if ( NOT TGUI_SHARED_LIBS )
2014-01-15 10:35:40 -08:00
if ( SFML_ROOT )
if ( SFML_OS_WINDOWS )
set ( CMAKE_INCLUDE_PATH ${ CMAKE_INCLUDE_PATH } "${SFML_ROOT}/extlibs/headers" )
2016-06-30 07:12:43 -07:00
if ( ARCH_32BITS )
if ( SFML_COMPILER_MSVC AND MSVC_VERSION LESS 1900 ) # older than VC++14
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-msvc/x86" )
elseif ( SFML_COMPILER_MSVC ) # VC++14 or newer
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-msvc-universal/x86" )
else ( ) # gcc
2014-01-15 10:35:40 -08:00
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-mingw/x86" )
endif ( )
2016-06-30 07:12:43 -07:00
elseif ( ARCH_64BITS )
if ( SFML_COMPILER_MSVC AND MSVC_VERSION LESS 1900 ) # older than VC++14
2014-01-15 10:35:40 -08:00
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-msvc/x64" )
2016-06-30 07:12:43 -07:00
elseif ( SFML_COMPILER_MSVC ) # VC++14 or newer
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-msvc-universal/x64" )
else ( ) # gcc
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-mingw/x64" )
2014-01-15 10:35:40 -08:00
endif ( )
endif ( )
elseif ( SFML_OS_MACOSX )
set ( CMAKE_INCLUDE_PATH ${ CMAKE_INCLUDE_PATH } "${SFML_ROOT}/extlibs/headers" )
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-osx/lib/" )
2015-01-30 07:39:05 -08:00
elseif ( SFML_OS_ANDROID )
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${ANDROID_NDK}/sources/sfml/extlibs/lib/armeabi/" )
2015-02-07 16:42:56 -08:00
elseif ( SFML_OS_IOS )
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-ios/" )
2014-01-15 10:35:40 -08:00
endif ( )
endif ( )
2013-09-12 14:44:36 -07:00
endif ( )
# Find sfml (also look for the main component when using Visual Studio)
2013-10-16 03:38:47 -07:00
if ( SFML_OS_WINDOWS AND SFML_COMPILER_MSVC )
2015-01-30 07:39:05 -08:00
find_package ( SFML 2 COMPONENTS main graphics window system )
elseif ( SFML_OS_ANDROID )
find_host_package ( SFML 2 COMPONENTS graphics window system )
2013-09-12 14:44:36 -07:00
else ( )
2015-01-30 07:39:05 -08:00
find_package ( SFML 2 COMPONENTS graphics window system )
2013-09-12 14:44:36 -07:00
endif ( )
# FindSFML couldn't find SFML.
if ( NOT SFML_FOUND )
set ( SFML_ROOT "" CACHE PATH "SFML root directory" )
message ( FATAL_ERROR "CMake couldn't find SFML. Set the SFML_ROOT entry to SFML's root directory (containing \" include\ " and \" lib\ " directories)." )
endif ( )
# Set the path for the libraries
set ( LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib" )
2015-07-19 09:20:11 -07:00
# Add the sfml and tgui include directories
include_directories ( "${PROJECT_SOURCE_DIR}/include" )
include_directories ( ${ SFML_INCLUDE_DIR } )
2017-10-15 02:55:10 -07:00
set ( TGUI_EXT_LIBS ${ SFML_LIBRARIES } ${ SFML_DEPENDENCIES } )
2015-07-19 09:20:11 -07:00
if ( SFML_OS_ANDROID )
2017-10-15 02:55:10 -07:00
# We need to link to an extra library on android (to use the asset manager)
2015-07-19 09:20:11 -07:00
set ( TGUI_EXT_LIBS ${ TGUI_EXT_LIBS } "-landroid" )
endif ( )
2015-09-06 04:52:24 -07:00
# Generate .gcno files when requested
if ( TGUI_BUILD_TESTS AND TGUI_USE_GCOV )
2015-11-04 01:24:02 -08:00
tgui_add_cxx_flag ( -fprofile-arcs )
tgui_add_cxx_flag ( -ftest-coverage )
2015-09-06 04:52:24 -07:00
endif ( )
2013-09-12 14:44:36 -07:00
# Jump to the CMakeLists.txt file in the source folder
add_subdirectory ( src/TGUI )
2017-09-21 05:02:36 -07:00
# Install the themes on linux
2013-10-16 03:38:47 -07:00
if ( SFML_OS_LINUX )
2017-09-21 05:02:36 -07:00
install ( DIRECTORY themes DESTINATION "${INSTALL_MISC_DIR}" )
2013-09-26 03:49:53 -07:00
endif ( )
2013-09-18 09:16:03 -07:00
# Build the documentation when requested
if ( TGUI_BUILD_DOC )
add_subdirectory ( doc )
endif ( )
2015-07-19 09:20:11 -07:00
# Build the examples if requested
if ( TGUI_BUILD_EXAMPLES )
add_subdirectory ( examples )
endif ( )
# Build the tests if requested
if ( TGUI_BUILD_TESTS )
2015-08-07 05:03:22 -07:00
if ( NOT ${ CMAKE_BUILD_TYPE } STREQUAL "Debug" )
message ( FATAL_ERROR "TGUI_BUILD_TESTS should only be enabled when CMAKE_BUILD_TYPE is Debug" )
endif ( )
2015-07-19 09:20:11 -07:00
add_subdirectory ( tests )
endif ( )
2017-08-26 08:27:28 -07:00
# Build the GUI Builder if requested
if ( TGUI_BUILD_GUI_BUILDER )
add_subdirectory ( "${PROJECT_SOURCE_DIR}/gui-builder" )
endif ( )
2014-08-14 16:06:16 -07:00
# Install include files
2015-02-05 14:21:47 -08:00
if ( NOT TGUI_BUILD_FRAMEWORK )
install ( DIRECTORY include
D E S T I N A T I O N .
C O M P O N E N T d e v e l
F I L E S _ M A T C H I N G P A T T E R N " * . h p p " P A T T E R N " * . i n l " )
endif ( )
2013-09-12 14:44:36 -07:00
2014-08-14 16:06:16 -07:00
# Install FindTGUI.cmake file
if ( NOT SFML_OS_ANDROID )
install ( FILES cmake/Modules/FindTGUI.cmake DESTINATION "${INSTALL_MISC_DIR}/cmake/Modules" )
endif ( )
2015-01-30 07:39:05 -08:00
# Install Android.mk so the NDK knows how to set up TGUI
if ( SFML_OS_ANDROID )
install ( FILES Android.mk DESTINATION . )
endif ( )
2015-02-07 16:42:56 -08:00
# Fix CMake install rules broken for iOS (see http://public.kitware.com/Bug/view.php?id=12506)
if ( SFML_OS_IOS )
install ( DIRECTORY "${CMAKE_BINARY_DIR}/lib/\$ENV{CONFIGURATION}/" DESTINATION lib ${ LIB_SUFFIX } )
2015-07-19 09:20:11 -07:00
endif ( )