2013-09-12 14:44:36 -07:00
cmake_minimum_required ( VERSION 2.8 )
# define a macro that helps defining an option
macro ( tgui_set_option var default type docstring )
if ( NOT DEFINED ${ var } )
set ( ${ var } ${ default } )
endif ( )
set ( ${ var } ${ ${var } } CACHE ${ type } ${ docstring } FORCE )
endmacro ( )
# Specify default build type if none provided
if ( NOT CMAKE_BUILD_TYPE )
set ( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug or Release)" FORCE )
endif ( )
# Specify default cmake module path if none provided
if ( NOT CMAKE_MODULE_PATH )
set ( CMAKE_MODULE_PATH ${ CMAKE_CURRENT_SOURCE_DIR } /cmake/Modules CACHE STRING "The path to the cmake modules. This path must contain the FindSFML.cmake file." FORCE )
endif ( )
project ( tgui )
# project version
SET ( MAJOR_VERSION 0 )
SET ( MINOR_VERSION 6 )
2013-09-26 03:49:53 -07:00
# include the configuration file
include ( ${ CMAKE_CURRENT_SOURCE_DIR } /cmake/Config.cmake )
2013-09-12 14:44:36 -07:00
# project options
2013-09-18 09:16:03 -07:00
tgui_set_option ( TGUI_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it" )
2013-09-12 14:44:36 -07:00
tgui_set_option ( TGUI_SHARED_LIBS TRUE BOOL "Build shared libraries (Set to OFF to build static libraries)" )
2013-10-16 03:38:47 -07:00
if ( SFML_OS_LINUX )
2013-09-26 03:49:53 -07:00
tgui_set_option ( TGUI_FORM_BUILDER_USE_LOCAL_FILES FALSE BOOL "Use resources from current directory instead of from installed files." )
endif ( )
2013-10-16 03:38:47 -07:00
if ( SFML_OS_WINDOWS )
2013-09-12 14:44:36 -07:00
tgui_set_option ( TGUI_BUILD_FORM_BUILDER FALSE BOOL "Build the TGUI Form Builder" )
else ( )
tgui_set_option ( TGUI_BUILD_FORM_BUILDER TRUE BOOL "Build the TGUI Form Builder" )
endif ( )
# Set some useful compile flags.
2013-10-16 03:38:47 -07:00
if ( SFML_COMPILER_GCC )
2013-10-11 13:55:00 -07:00
2013-09-12 14:44:36 -07:00
if ( NOT CMAKE_CXX_FLAGS )
set ( CMAKE_CXX_FLAGS "-Wall -Wextra -Wshadow -Wno-long-long -pedantic -std=c++0x" CACHE STRING "C++ compiler flags" FORCE )
set ( CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wno-long-long -pedantic" CACHE STRING "C compiler flags" FORCE )
endif ( )
if ( NOT CMAKE_CXX_FLAGS_DEBUG )
set ( CMAKE_CXX_FLAGS_DEBUG "-g -O0 -std=c++0x" CACHE STRING "C++ compiler flags (debug)" FORCE )
set ( CMAKE_C_FLAGS_DEBUG "-g -O0" CACHE STRING "C++ compiler flags (debug)" FORCE )
endif ( )
2013-10-11 13:55:00 -07:00
2013-10-16 03:38:47 -07:00
elseif ( SFML_COMPILER_CLANG )
2013-10-11 13:55:00 -07:00
if ( NOT CMAKE_CXX_FLAGS )
set ( CMAKE_CXX_FLAGS "-Wall -Wextra -Wshadow -Wno-long-long -pedantic -std=c++11 -stdlib=libc++" CACHE STRING "C++ compiler flags" FORCE )
set ( CMAKE_C_FLAGS "-Wall -Wextra -Wshadow -Wno-long-long -pedantic" CACHE STRING "C compiler flags" FORCE )
endif ( )
if ( NOT CMAKE_CXX_FLAGS_DEBUG )
set ( CMAKE_CXX_FLAGS_DEBUG "-g -O0 -std=c++11 -stdlib=libc++" CACHE STRING "C++ compiler flags (debug)" FORCE )
set ( CMAKE_C_FLAGS_DEBUG "-g -O0" CACHE STRING "C++ compiler flags (debug)" FORCE )
endif ( )
2013-09-12 14:44:36 -07:00
endif ( )
# Define an option for choosing between static and dynamic C runtime (VC++ only)
2013-10-16 03:38:47 -07: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 ( )
2013-10-12 02:48:37 -07:00
# Set the correct architecture on mac
2013-10-16 03:38:47 -07:00
if ( SFML_OS_MACOSX )
2013-10-12 02:48:37 -07:00
if ( NOT CMAKE_OSX_ARCHITECTURES )
set ( CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE )
endif ( )
endif ( )
2013-09-12 14:44:36 -07:00
# Link to the static sfml libraries when building tgui statically
if ( NOT TGUI_SHARED_LIBS )
set ( SFML_STATIC_LIBRARIES TRUE )
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 )
2013-09-12 14:44:36 -07:00
find_package ( SFML 2 COMPONENTS main graphics window system )
else ( )
find_package ( SFML 2 COMPONENTS graphics window system )
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" )
# Jump to the CMakeLists.txt file in the source folder
add_subdirectory ( src/TGUI )
2013-09-26 03:49:53 -07:00
# Install the widgets and fonts on linux
2013-10-16 03:38:47 -07:00
if ( SFML_OS_LINUX )
2013-09-26 03:49:53 -07:00
install ( DIRECTORY widgets fonts
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ P R E F I X } / $ { I N S T A L L _ M I S C _ D I R } " )
endif ( )
2013-09-18 09:16:03 -07:00
# Build the documentation when requested
if ( TGUI_BUILD_DOC )
add_subdirectory ( doc )
endif ( )
2013-09-12 14:44:36 -07:00
# install include files
install ( DIRECTORY include DESTINATION . )