2018-03-30 14:03:18 -07:00
if ( CMAKE_SYSTEM_NAME MATCHES "Android" )
2018-04-01 06:38:13 -07:00
cmake_minimum_required ( VERSION 3.7 ) # CMake's built-in Android support requires 3.7
2018-03-30 14:03:18 -07:00
else ( )
2018-04-01 06:38:13 -07:00
cmake_minimum_required ( VERSION 3.5 ) # Can be at most 3.5.1 as long as Ubuntu 16.04 is supported
2018-03-30 14:03:18 -07:00
endif ( )
2013-09-12 14:44:36 -07:00
2018-04-01 06:38:13 -07:00
# Use new RPATH behavior on macOS
2018-05-07 13:48:18 -07:00
if ( POLICY CMP0068 )
2018-03-30 14:03:18 -07:00
cmake_policy ( SET CMP0068 NEW )
endif ( )
2018-04-01 06:38:13 -07:00
include ( ${ CMAKE_CURRENT_SOURCE_DIR } /cmake/Macros.cmake )
2017-09-07 06:38:35 -07:00
2018-04-01 06:38:13 -07:00
# Set a default build type
2015-01-30 07:39:05 -08:00
tgui_set_option ( CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)" )
2015-08-27 17:22:58 -07:00
2018-03-30 14:03:18 -07:00
# Set CMAKE_MODULE_PATH to find SFML < 2.5 without manually having to specify a module path
2018-04-01 06:38:13 -07:00
if ( NOT SFML_DIR AND NOT CMAKE_MODULE_PATH )
2018-03-30 14:03:18 -07:00
set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules" )
endif ( )
2015-08-27 17:22:58 -07:00
2018-04-01 06:38:13 -07:00
# Project name and version
2018-04-01 06:44:45 -07:00
project ( TGUI VERSION 0.8.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)
2018-04-01 06:38:13 -07:00
if ( NOT TGUI_OS_IOS AND NOT TGUI_OS_ANDROID )
2015-01-30 07:39:05 -08:00
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 ( )
2018-04-01 06:38:13 -07:00
if ( TGUI_OS_IOS )
2015-01-30 07:39:05 -08:00
set ( TGUI_SHARED_LIBS FALSE )
2018-04-01 06:38:13 -07:00
elseif ( TGUI_OS_ANDROID )
2015-01-30 07:39:05 -08:00
set ( TGUI_SHARED_LIBS TRUE )
endif ( )
endif ( )
2015-07-19 09:20:11 -07:00
# Add option to build the examples
2018-04-08 11:00:13 -07:00
if ( NOT TGUI_OS_ANDROID )
2015-07-19 09:20:11 -07:00
tgui_set_option ( TGUI_BUILD_EXAMPLES FALSE BOOL "TRUE to build the TGUI examples, FALSE to ignore them" )
2018-04-01 06:38:13 -07:00
else ( )
set ( TGUI_BUILD_EXAMPLES FALSE )
2015-07-19 09:20:11 -07:00
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
2018-04-01 06:38:13 -07:00
# Define the install directory for miscellaneous files
if ( TGUI_OS_WINDOWS OR TGUI_OS_IOS )
set ( DEFAULT_INSTALL_MISC_DIR . )
2018-04-01 09:24:31 -07:00
elseif ( TGUI_OS_LINUX OR TGUI_OS_BSD )
2018-04-01 06:38:13 -07:00
set ( DEFAULT_INSTALL_MISC_DIR share/tgui- ${ TGUI_VERSION_MAJOR } . ${ TGUI_VERSION_MINOR } )
elseif ( TGUI_OS_MACOSX )
set ( DEFAULT_INSTALL_MISC_DIR /usr/local/share/tgui- ${ TGUI_VERSION_MAJOR } . ${ TGUI_VERSION_MINOR } )
elseif ( TGUI_OS_ANDROID )
set ( DEFAULT_INSTALL_MISC_DIR ${ CMAKE_ANDROID_NDK } /sources/third_party/tgui )
endif ( )
tgui_set_option ( TGUI_MISC_INSTALL_PREFIX "${DEFAULT_INSTALL_MISC_DIR}" PATH "Prefix installation path for miscellaneous files" )
mark_as_advanced ( TGUI_MISC_INSTALL_PREFIX )
2015-11-04 01:24:02 -08:00
2018-04-01 06:38:13 -07:00
if ( TGUI_USE_CPP17 )
message ( WARNING "The library is being build with c++17 features. Keep in mind that you MUST define TGUI_USE_CPP17 in the project using the library as well." )
2013-09-12 14:44:36 -07:00
endif ( )
2018-04-15 06:45:52 -07:00
# Define an option for choosing between static and dynamic C runtime
2018-04-01 06:38:13 -07:00
if ( TGUI_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
2018-04-01 06:38:13 -07:00
if ( TGUI_SHARED_LIBS AND TGUI_USE_STATIC_STD_LIBS )
2013-10-16 07:46:01 -07:00
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
endif ( )
2015-01-30 07:39:05 -08:00
# Mac OS X specific options
2018-04-01 06:38:13 -07:00
if ( TGUI_OS_MACOSX )
2015-01-30 07:39:05 -08:00
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
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 )
2018-04-01 06:38:13 -07:00
if ( TGUI_BUILD_FRAMEWORK )
# Frameworks are only available for release (because cmake currently doesn't allow specifying a custom framework name so TGUI-d is not possible)
2015-02-05 14:21:47 -08:00
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
2018-04-01 06:38:13 -07:00
if ( NOT TGUI_SHARED_LIBS )
2015-02-05 14:21:47 -08:00
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
2018-04-01 06:38:13 -07:00
if ( TGUI_OS_ANDROID )
2015-01-30 07:39:05 -08:00
2018-03-30 14:03:18 -07:00
# Make sure there's the android library available
2018-04-01 06:38:13 -07:00
if ( CMAKE_ANDROID_API LESS 19 )
2018-03-30 14:03:18 -07:00
message ( FATAL_ERROR "Android API level (${CMAKE_ANDROID_API}) must be equal or greater than 19." )
2015-08-27 17:22:58 -07:00
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)
2018-03-30 14:03:18 -07:00
set ( CMAKE_INSTALL_PREFIX ${ CMAKE_ANDROID_NDK } /sources/third_party/tgui )
2015-01-30 07:39:05 -08:00
# We install libs in a subdirectory named after the ABI (e.g. lib/armeabi/libtgui.so)
2018-03-30 14:03:18 -07:00
set ( LIB_SUFFIX "/${CMAKE_ANDROID_ARCH_ABI}" )
2013-10-12 02:48:37 -07:00
endif ( )
2018-05-07 13:48:18 -07:00
# Set the c++ library used by all targets (not allowed through interface library apparently)
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
if ( TGUI_USE_CPP17 )
set ( CMAKE_CXX_STANDARD 17 )
else ( )
set ( CMAKE_CXX_STANDARD 14 )
endif ( )
# Create an interface library to pass the warnings to all targets
add_library ( interface_warnings INTERFACE )
if ( TGUI_COMPILER_MSVC )
target_compile_options ( interface_warnings INTERFACE /W4 )
else ( )
target_compile_options ( interface_warnings
I N T E R F A C E
- W a l l
- W e x t r a
- W s h a d o w
- W n o n - v i r t u a l - d t o r
- W o l d - s t y l e - c a s t
- W c a s t - a l i g n
- W u n u s e d
- W o v e r l o a d e d - v i r t u a l
- W p e d a n t i c
- W m i s l e a d i n g - i n d e n t a t i o n
- W d u p l i c a t e d - c o n d
- W d u p l i c a t e d - b r a n c h e s
- W l o g i c a l - o p
- W n u l l - d e r e f e r e n c e
- W u s e l e s s - c a s t
- W d o u b l e - p r o m o t i o n
- W f o r m a t = 2 )
endif ( )
# Create an interface library to pass the standard library to all targets
add_library ( interface_stdlib INTERFACE )
if ( TGUI_OS_MACOSX )
# Use libc++ on macOS
if ( ${ CMAKE_GENERATOR } MATCHES "Xcode" )
set_target_properties ( interface_stdlib PROPERTY XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" )
else ( )
target_compile_options ( interface_stdlib INTERFACE "-stdlib=libc++" )
target_link_libraries ( interface_stdlib INTERFACE "-stdlib=libc++" )
endif ( )
endif ( )
if ( TGUI_OS_WINDOWS )
# Apply the TGUI_USE_STATIC_STD_LIBS option on windows
if ( TGUI_COMPILER_GCC )
if ( TGUI_USE_STATIC_STD_LIBS AND NOT TGUI_COMPILER_GCC_TDM )
target_link_libraries ( interface_stdlib INTERFACE "-static-libgcc" "-static-libstdc++" )
elseif ( NOT TGUI_USE_STATIC_STD_LIBS AND TGUI_COMPILER_GCC_TDM )
target_link_libraries ( interface_stdlib INTERFACE "-shared-libgcc" "-shared-libstdc++" )
endif ( )
elseif ( TGUI_COMPILER_MSVC AND TGUI_USE_STATIC_STD_LIBS )
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 ( )
2017-08-27 02:52:50 -07:00
# Link SFML in the same way as TGUI, unless SFML_STATIC_LIBRARIES is manually specified
2018-04-01 06:38:13 -07:00
if ( NOT DEFINED SFML_STATIC_LIBRARIES )
if ( TGUI_SHARED_LIBS )
2017-08-27 02:52:50 -07:00
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 )
2018-04-01 06:38:13 -07:00
if ( SFML_ROOT )
if ( TGUI_OS_WINDOWS )
2014-01-15 10:35:40 -08:00
set ( CMAKE_INCLUDE_PATH ${ CMAKE_INCLUDE_PATH } "${SFML_ROOT}/extlibs/headers" )
2016-06-30 07:12:43 -07:00
if ( ARCH_32BITS )
2018-04-01 06:38:13 -07:00
if ( TGUI_COMPILER_MSVC AND MSVC_VERSION LESS 1900 ) # older than VC++14
2016-06-30 07:12:43 -07:00
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-msvc/x86" )
2018-04-01 06:38:13 -07:00
elseif ( TGUI_COMPILER_MSVC ) # VC++14 or newer
2016-06-30 07:12:43 -07:00
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 )
2018-04-01 06:38:13 -07:00
if ( TGUI_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" )
2018-04-01 06:38:13 -07:00
elseif ( TGUI_COMPILER_MSVC ) # VC++14 or newer
2016-06-30 07:12:43 -07:00
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 ( )
2018-04-01 06:38:13 -07:00
elseif ( TGUI_OS_MACOSX )
2014-01-15 10:35:40 -08:00
set ( CMAKE_INCLUDE_PATH ${ CMAKE_INCLUDE_PATH } "${SFML_ROOT}/extlibs/headers" )
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${SFML_ROOT}/extlibs/libs-osx/lib/" )
2018-04-01 06:38:13 -07:00
elseif ( TGUI_OS_ANDROID )
2018-03-30 14:03:18 -07:00
set ( CMAKE_LIBRARY_PATH ${ CMAKE_LIBRARY_PATH } "${CMAKE_ANDROID_NDK}/sources/third_party/sfml/extlibs/lib/${CMAKE_ANDROID_ARCH_ABI}/" )
2018-04-01 06:38:13 -07:00
elseif ( TGUI_OS_IOS )
2015-02-07 16:42:56 -08:00
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 ( )
2018-03-30 14:03:18 -07:00
# Find sfml
2018-04-01 06:38:13 -07:00
if ( TGUI_OS_WINDOWS AND TGUI_COMPILER_MSVC ) # Also look for the main component when using Visual Studio
2015-01-30 07:39:05 -08:00
find_package ( SFML 2 COMPONENTS main graphics window system )
2018-04-02 05:24:04 -07:00
elseif ( TGUI_OS_ANDROID ) # Search for SFML in the android NDK (if no other directory is specified)
find_package ( SFML 2 COMPONENTS graphics window system PATHS "${CMAKE_ANDROID_NDK}/sources/third_party/sfml/lib/cmake/SFML" )
2018-04-01 06:38:13 -07:00
elseif ( TGUI_OS_IOS ) # Use the find_host_package macro from the toolchain on iOS
2018-04-12 13:32:52 -07:00
find_host_package ( SFML 2 COMPONENTS main 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 ( )
2018-04-01 06:38:13 -07:00
# find_package couldn't find SFML
if ( NOT SFML_FOUND )
2018-03-30 14:03:18 -07:00
set ( SFML_DIR "" CACHE PATH "Path to SFMLConfig.cmake" )
set ( SFML_ROOT "" CACHE PATH "SFML root directory" )
message ( FATAL_ERROR "CMake couldn't find SFML.\nEither set SFML_DIR to the directory containing SFMLConfig.cmake or set the SFML_ROOT entry to SFML's root directory (containing \" include\ " and \" lib\ " directories)." )
2013-09-12 14:44:36 -07:00
endif ( )
# Set the path for the libraries
2018-04-01 06:38:13 -07:00
set ( LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib" )
2015-09-06 04:52:24 -07:00
2013-09-12 14:44:36 -07:00
# Jump to the CMakeLists.txt file in the source folder
add_subdirectory ( src/TGUI )
2013-09-18 09:16:03 -07:00
# Build the documentation when requested
2018-04-01 06:38:13 -07:00
if ( TGUI_BUILD_DOC )
2013-09-18 09:16:03 -07:00
add_subdirectory ( doc )
endif ( )
2015-07-19 09:20:11 -07:00
# Build the examples if requested
2018-04-01 06:38:13 -07:00
if ( TGUI_BUILD_EXAMPLES )
2015-07-19 09:20:11 -07:00
add_subdirectory ( examples )
endif ( )
# Build the tests if requested
2018-04-01 06:38:13 -07:00
if ( TGUI_BUILD_TESTS )
if ( NOT ${ CMAKE_BUILD_TYPE } STREQUAL "Debug" )
2015-08-07 05:03:22 -07:00
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
2018-04-01 06:38:13 -07:00
if ( TGUI_BUILD_GUI_BUILDER )
2017-08-26 08:27:28 -07:00
add_subdirectory ( "${PROJECT_SOURCE_DIR}/gui-builder" )
endif ( )
2014-08-14 16:06:16 -07:00
# Install include files
2018-04-01 06:38:13 -07:00
if ( NOT TGUI_BUILD_FRAMEWORK )
2015-02-05 14:21:47 -08:00
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
2018-04-01 06:38:13 -07:00
# Install miscellaneous files
install ( FILES license.txt DESTINATION ${ TGUI_MISC_INSTALL_PREFIX } )
install ( FILES README.md DESTINATION ${ TGUI_MISC_INSTALL_PREFIX } )
install ( DIRECTORY themes DESTINATION "${TGUI_MISC_INSTALL_PREFIX}" )
2014-08-14 16:06:16 -07:00
2015-01-30 07:39:05 -08:00
# Install Android.mk so the NDK knows how to set up TGUI
2018-04-01 06:38:13 -07:00
if ( TGUI_OS_ANDROID )
2015-01-30 07:39:05 -08:00
install ( FILES Android.mk DESTINATION . )
endif ( )
2015-02-07 16:42:56 -08:00
2018-04-01 06:38:13 -07:00
# Generate the TGUIConfig.cmake file
tgui_export_target ( TGUIConfigExport )