| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957 |
- #===================================
- # Build script for RmlUi ===========
- #===================================
- cmake_minimum_required(VERSION 3.1)
- if(APPLE)
- # This has to be before most other options so CMake properly handles the
- # compiler variables, it MUST bebefore the project() definition
- if(IOS_PLATFORM)
- set(CMAKE_TOOLCHAIN_FILE CMake/Platform/iOS.cmake)
- endif(IOS_PLATFORM)
- option(BUILD_UNIVERSAL_BINARIES "Build universal binaries for all architectures supported" ON)
- if (NOT CMAKE_OSX_ARCHITECTURES AND BUILD_UNIVERSAL_BINARIES)
- if(IOS)
- # set the architecture for iOS
- if (${IOS_PLATFORM} STREQUAL "OS")
- set (IOS_ARCH armv6 armv7 armv7s arm64)
- set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS")
- else (${IOS_PLATFORM} STREQUAL "OS")
- set (IOS_ARCH x86_64)
- set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS Simulator")
- endif (${IOS_PLATFORM} STREQUAL "OS")
- else(IOS)
- # set the architectures for OS X
- set (OSXI_ARCH x86_64)
- set (CMAKE_OSX_ARCHITECTURES ${OSXI_ARCH} CACHE STRING "Build architecture for OS X universal binaries")
- endif(IOS)
- endif (NOT CMAKE_OSX_ARCHITECTURES AND BUILD_UNIVERSAL_BINARIES)
- endif(APPLE)
- if(COMMAND cmake_policy)
- cmake_policy(SET CMP0015 NEW)
- endif(COMMAND cmake_policy)
- # Enable the use of MACOSX_RPATH by default for CMake v3.0+; this effectively
- # allows plug 'n' play functionality, so to speak -- the resulting shared
- # library files can simply be copied over into the end-user's application
- # bundle or framework bundle. No mucking around with install_name_tool.
- #
- # See also:
- # cmake --help-policy cmp0042
- # http://www.kitware.com/blog/home/post/510
- if(POLICY CMP0042)
- cmake_policy(SET CMP0042 NEW)
- endif(POLICY CMP0042)
- if (POLICY CMP0072)
- cmake_policy (SET CMP0072 NEW)
- endif(POLICY CMP0072)
- if(POLICY CMP0074)
- cmake_policy(SET CMP0074 NEW)
- endif(POLICY CMP0074)
- project(RmlUi LANGUAGES C CXX VERSION 4.4)
- set(RMLUI_VERSION_RELEASE false)
- if(RMLUI_VERSION_RELEASE)
- set(RMLUI_VERSION_SUFFIX "")
- else()
- set(RMLUI_VERSION_SUFFIX "-dev")
- endif()
- set(RMLUI_VERSION_SHORT ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}${RMLUI_VERSION_SUFFIX})
- list(APPEND CORE_PRIVATE_DEFS RMLUI_VERSION="${RMLUI_VERSION_SHORT}")
- if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
- option(BUILD_TESTING "" OFF)
- include(CTest)
-
- if(BUILD_TESTING)
- set(RMLUI_TESTS_ENABLED ON)
- set(VISUAL_TESTS_RML_DIRECTORIES "" CACHE PATH "Specify additional directories containing *.rml test documents for VisualTests. Separate multiple directories by comma.")
- set(VISUAL_TESTS_COMPARE_DIRECTORY "" CACHE PATH "Set the input directory for screenshot comparison performed by VisualTests.")
- set(VISUAL_TESTS_CAPTURE_DIRECTORY "" CACHE PATH "Set the output directory for screenshots generated by VisualTests.")
- endif()
- endif()
- # paths
- include(GNUInstallDirs)
- # Search in the 'cmake' directory for additional CMake modules.
- list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake;${PROJECT_SOURCE_DIR}/CMake/Modules)
- #===================================
- # Environment tests ================
- #===================================
- include(TestForANSIForScope)
- include(TestForANSIStreamHeaders)
- include(TestForSTDNamespace)
- #===================================
- # Provide hints as to where depends=
- # might be found =
- #===================================
- if(NOT DEFINED ENV{FREETYPE_DIR})
- set(ENV{FREETYPE_DIR} "${PROJECT_SOURCE_DIR}/Dependencies")
- endif()
- if(NOT DEFINED ENV{LUA_DIR})
- set(ENV{LUA_DIR} "${PROJECT_SOURCE_DIR}/Dependencies")
- endif()
- if(NOT DEFINED ENV{SDL2DIR})
- set(ENV{SDL2DIR} "${PROJECT_SOURCE_DIR}/Dependencies")
- endif()
- if(NOT DEFINED ENV{SDL2_IMAGE_DIR})
- set(ENV{SDL2_IMAGE_DIR} "${PROJECT_SOURCE_DIR}/Dependencies")
- endif()
- if(NOT DEFINED ENV{SFML_ROOT})
- set(ENV{SFML_ROOT} "${PROJECT_SOURCE_DIR}/Dependencies")
- endif()
- if(NOT DEFINED ENV{TRACY_DIR})
- set(ENV{TRACY_DIR} "${PROJECT_SOURCE_DIR}/Dependencies")
- endif()
- if(NOT DEFINED ENV{RLOTTIE_DIR})
- set(ENV{RLOTTIE_DIR} "${PROJECT_SOURCE_DIR}/Dependencies/rlottie")
- endif()
- if(NOT DEFINED ENV{LUNASVG_DIR})
- set(ENV{LUNASVG_DIR} "${PROJECT_SOURCE_DIR}/Dependencies/lunasvg")
- endif()
- #===================================
- # Plaform specific global hacks ====
- #===================================
- if(APPLE)
- # Disables naked builtins from AssertMacros.h which
- # This prevents naming collisions such as those from the check()
- # function macro with LuaType::check
- add_definitions(-D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=0)
- endif(APPLE)
- #===================================
- # Build options ====================
- #===================================
- if(NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE Release CACHE STRING
- "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
- FORCE)
- endif()
- if(NOT IOS)
- option(BUILD_SHARED_LIBS "Build shared (dynamic) libraries" ON)
- endif(NOT IOS)
- option(BUILD_LUA_BINDINGS "Build Lua bindings" OFF)
- if(APPLE)
- option(BUILD_FRAMEWORK "Build Framework bundle for OSX" OFF)
- endif()
- option(BUILD_SAMPLES "Build samples" OFF)
- option(MATRIX_ROW_MAJOR "Use row-major matrices. Column-major matrices are used by default." OFF)
- if(APPLE)
- if(IOS)
- if(BUILD_SHARED_LIBS)
- message(FATAL_ERROR "BUILD_SHARED_LIBS must be OFF for iOS builds. iOS does not support shared libraries.")
- endif(BUILD_SHARED_LIBS)
- endif(IOS)
- if(BUILD_FRAMEWORK)
- if(NOT "${CMAKE_GENERATOR}" STREQUAL "Xcode")
- message(FATAL_ERROR "You should use Xcode generator with BUILD_FRAMEWORK enabled")
- endif()
- if(NOT BUILD_SHARED_LIBS)
- message(FATAL_ERROR "BUILD_SHARED_LIBS must be ON with BUILD_FRAMEWORK enabled")
- endif()
- endif()
- else(APPLE)
- if(BUILD_FRAMEWORK)
- message(FATAL_ERROR "BUILD_FRAMEWORK is only supported on Mac OS X with the Xcode generator")
- endif()
- endif(APPLE)
- option(NO_FONT_INTERFACE_DEFAULT "Do not include the default font engine in the build. Allows building without the FreeType dependency, but a custom font engine must be created and set." OFF)
- if(NO_FONT_INTERFACE_DEFAULT)
- list(APPEND CORE_PRIVATE_DEFS RMLUI_NO_FONT_INTERFACE_DEFAULT)
- endif()
- if(WIN32 AND BUILD_SHARED_LIBS AND BUILD_TESTING)
- message(FATAL_ERROR "-- The RmlUi testing framework cannot be built when using shared libraries on Windows. Please disable either BUILD_SHARED_LIBS or BUILD_TESTING.")
- endif()
- if(NOT BUILD_SHARED_LIBS)
- list(APPEND CORE_PUBLIC_DEFS -DRMLUI_STATIC_LIB)
- message("-- Building static libraries. Make sure to #define RMLUI_STATIC_LIB before including RmlUi in your project.")
- endif()
- option(NO_THIRDPARTY_CONTAINERS "Only use standard library containers." OFF)
- if( NO_THIRDPARTY_CONTAINERS )
- list(APPEND CORE_PUBLIC_DEFS -DRMLUI_NO_THIRDPARTY_CONTAINERS)
- message("-- No third-party containers will be used: Make sure to #define RMLUI_NO_THIRDPARTY_CONTAINERS before including RmlUi in your project.")
- endif()
- option(CUSTOM_CONFIGURATION "Customize RmlUi configuration files for overriding the default configuration and types." OFF)
- set(CUSTOM_CONFIGURATION_FILE "" CACHE STRING "Custom configuration file to be included in place of <RmlUi/Config/Config.h>.")
- if( CUSTOM_CONFIGURATION AND CUSTOM_CONFIGURATION_FILE )
- list(APPEND CORE_PUBLIC_DEFS -DRMLUI_CUSTOM_CONFIGURATION_FILE="${CUSTOM_CONFIGURATION_FILE}")
- message("-- Including ${CUSTOM_CONFIGURATION_FILE} instead of <RmlUi/Config/Config.h>")
- endif ()
- set(CUSTOM_INCLUDE_DIRS "" CACHE STRING "Extra include directories (use with CUSTOM_CONFIGURATION_FILE).")
- if( CUSTOM_CONFIGURATION AND CUSTOM_INCLUDE_DIRS )
- include_directories(${CUSTOM_INCLUDE_DIRS})
- endif ()
- set(CUSTOM_LINK_LIBRARIES "" CACHE STRING "Extra link libraries (use with CUSTOM_CONFIGURATION_FILE).")
- if( CUSTOM_CONFIGURATION )
- mark_as_advanced( CLEAR CUSTOM_CONFIGURATION_FILE CUSTOM_INCLUDE_DIRS CUSTOM_LINK_LIBRARIES )
- else()
- mark_as_advanced( FORCE CUSTOM_CONFIGURATION_FILE CUSTOM_INCLUDE_DIRS CUSTOM_LINK_LIBRARIES )
-
- if( CUSTOM_CONFIGURATION_FILE OR CUSTOM_INCLUDE_DIRS OR CUSTOM_LINK_LIBRARIES )
- message("-- CUSTOM_CONFIGURATION disabled, but custom configuration variables are set. They will have no effect.")
- endif()
- endif()
- option(ENABLE_TRACY_PROFILING "Enable profiling with Tracy. Source files can be placed in Dependencies/tracy." OFF)
- if( ENABLE_TRACY_PROFILING )
- find_package(Tracy REQUIRED)
- include_directories(${TRACY_INCLUDE_DIR})
- if( CMAKE_CONFIGURATION_TYPES )
- list(APPEND CMAKE_CONFIGURATION_TYPES Tracy)
- list(REMOVE_DUPLICATES CMAKE_CONFIGURATION_TYPES)
- set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
- "Add the configurations that we need"
- FORCE)
- set(CMAKE_C_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE} -DRMLUI_ENABLE_PROFILING")
- set(CMAKE_CXX_FLAGS_TRACY "${CMAKE_CXX_FLAGS_RELEASE} -DRMLUI_ENABLE_PROFILING")
- set(CMAKE_EXE_LINKER_FLAGS_TRACY "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
- set(CMAKE_SHARED_LINKER_FLAGS_TRACY "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
- message("-- Tracy profiling enabled in configuration 'Tracy'.")
- else()
- message("-- Tracy profiling enabled.")
- list(APPEND CORE_PUBLIC_DEFS -DRMLUI_ENABLE_PROFILING)
- endif()
- elseif( CMAKE_CONFIGURATION_TYPES )
- list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES Tracy)
- endif()
- option(ENABLE_LOTTIE_PLUGIN "Enable plugin for Lottie animations. Requires the rlottie library." OFF)
- option(ENABLE_SVG_PLUGIN "Enable plugin for SVG images. Requires the lunasvg library." OFF)
- option(DISABLE_RTTI_AND_EXCEPTIONS "Build with rtti and exceptions disabled." OFF)
- if(DISABLE_RTTI_AND_EXCEPTIONS)
- list(APPEND CORE_PUBLIC_DEFS -DRMLUI_USE_CUSTOM_RTTI)
- message("-- C++ RTTI and exceptions will be disabled: Make sure to #define RMLUI_USE_CUSTOM_RTTI before including RmlUi in your project.")
- endif()
- option(ENABLE_PRECOMPILED_HEADERS "Enable precompiled headers" ON)
- set(PRECOMPILED_HEADERS_ENABLED OFF)
- if (ENABLE_PRECOMPILED_HEADERS AND (CMAKE_VERSION VERSION_LESS 3.16.0))
- message("-- Could not enable precompiled headers. Need CMake version 3.16.0 or greater.")
- elseif (ENABLE_PRECOMPILED_HEADERS)
- set(PRECOMPILED_HEADERS_ENABLED ON)
- endif()
- option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors." OFF)
- mark_as_advanced(WARNINGS_AS_ERRORS)
- macro(add_common_target_options NAME)
- # C++ language version
- if(CMAKE_VERSION VERSION_LESS 3.8.0)
- set_target_properties(${NAME} PROPERTIES
- CXX_STANDARD 14
- CXX_STANDARD_REQUIRED YES
- )
- else()
- target_compile_features(${NAME} PUBLIC cxx_std_14)
- endif()
- set_target_properties(${NAME} PROPERTIES CXX_EXTENSIONS OFF)
-
- # Compiler warnings
- if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
- target_compile_options(${NAME} PRIVATE -Wall -pedantic -Wextra)
-
- if(WARNINGS_AS_ERRORS)
- target_compile_options(${NAME} PRIVATE -Werror)
- endif()
- elseif(MSVC)
- target_compile_options(${NAME} PRIVATE /MP /W4 /w44062 /permissive-)
- target_compile_definitions(${NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
-
- if(WARNINGS_AS_ERRORS)
- target_compile_options(${NAME} PRIVATE /WX)
- endif()
- endif()
- endmacro()
- #===================================
- # Setup paths ======================
- #===================================
- include_directories(
- ${PROJECT_SOURCE_DIR}/Include
- )
- # Include list of source files
- include(FileList)
- #===================================
- # Find dependencies ================
- #===================================
- # FreeType
- if(NOT NO_FONT_INTERFACE_DEFAULT)
- find_package(Freetype REQUIRED)
-
- if(MSVC AND FREETYPE_VERSION_STRING STREQUAL "2.11.0")
- message(WARNING "You are using FreeType version 2.11.0 which introduced an issue that causes a crash on startup on some of the samples. Please avoid this version specifically.")
- endif()
-
- list(APPEND CORE_LINK_LIBS ${FREETYPE_LIBRARIES})
- list(APPEND CORE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
- endif()
- # Lua
- if(BUILD_LUA_BINDINGS)
- find_package(Lua REQUIRED)
- list(APPEND LUA_BINDINGS_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
- list(APPEND LUA_BINDINGS_LINK_LIBS ${LUA_LIBRARIES})
- endif()
- # rlottie
- if( ENABLE_LOTTIE_PLUGIN )
- # Try to find the rlottie library.
- if(NOT DEFINED rlottie_DIR)
- set(rlottie_DIR $ENV{RLOTTIE_DIR})
- endif()
- list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Dependencies/rlottie/build)
- find_package(rlottie CONFIG)
- find_path(rlottie_INCLUDE_DIR rlottie.h HINTS ${rlottie_DIR} $ENV{rlottie_DIR} PATH_SUFFIXES inc rlottie/inc )
-
- if(rlottie_FOUND AND rlottie_INCLUDE_DIR)
- message("-- Can Lottie plugin be added to RmlCore - yes - rlottie library found")
-
- list(APPEND CORE_LINK_LIBS rlottie::rlottie)
- list(APPEND CORE_INCLUDE_DIRS ${rlottie_INCLUDE_DIR})
- list(APPEND CORE_PRIVATE_DEFS RMLUI_ENABLE_LOTTIE_PLUGIN)
-
- list(APPEND Core_HDR_FILES ${Lottie_HDR_FILES})
- list(APPEND Core_PUB_HDR_FILES ${Lottie_PUB_HDR_FILES})
- list(APPEND Core_SRC_FILES ${Lottie_SRC_FILES})
- else()
- if(rlottie_FOUND)
- message(FATAL_ERROR "-- Can Lottie plugin be added to RmlCore - no - rlottie library found - rlottie include directory not found")
- elseif(rlottie_INCLUDE_DIR)
- message(FATAL_ERROR "-- Can Lottie plugin be added to RmlCore - no - rlottie library not found - rlottie include directory found at ${rlottie_INCLUDE_DIR}")
- else()
- message(FATAL_ERROR "-- Can Lottie plugin be added to RmlCore - no - rlottie not found")
- endif()
- endif()
- endif()
- # lunasvg
- if( ENABLE_SVG_PLUGIN )
- if(NOT DEFINED LUNASVG_DIR)
- set(LUNASVG_DIR $ENV{LUNASVG_DIR})
- endif()
-
- message("-- Can SVG plugin be enabled - looking for lunasvg library")
- find_package(lunasvg REQUIRED)
-
- list(APPEND CORE_LINK_LIBS ${LUNASVG_LIBRARIES})
- list(APPEND CORE_INCLUDE_DIRS ${LUNASVG_INCLUDE_DIR})
- list(APPEND CORE_PRIVATE_DEFS RMLUI_ENABLE_SVG_PLUGIN)
-
- list(APPEND Core_HDR_FILES ${SVG_HDR_FILES})
- list(APPEND Core_PUB_HDR_FILES ${SVG_PUB_HDR_FILES})
- list(APPEND Core_SRC_FILES ${SVG_SRC_FILES})
- message("-- Can SVG plugin be enabled - yes - lunasvg library found")
- endif()
- if(NOT BUILD_FRAMEWORK)
- #===================================
- # Build libraries ==================
- #===================================
- set(LIBRARIES Core Debugger)
- foreach(library ${LIBRARIES})
- set(NAME Rml${library})
- add_library(${NAME}
- ${${library}_HDR_FILES}
- ${${library}_PUB_HDR_FILES}
- ${MASTER_${library}_PUB_HDR_FILES}
- ${${library}_SRC_FILES}
- )
- set_target_properties(${NAME} PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION ${PROJECT_VERSION_MAJOR}
- )
-
- add_common_target_options(${NAME})
- install(TARGETS ${NAME}
- EXPORT RmlUiTargets
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- )
- set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${NAME})
- endforeach(library)
- if( CUSTOM_CONFIGURATION )
- foreach(library ${CUSTOM_LINK_LIBRARIES})
- install(TARGETS ${library}
- EXPORT RmlUiTargets
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- )
- set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${library})
- endforeach(library ${CUSTOM_LINK_LIBRARIES})
- endif()
- if( MATRIX_ROW_MAJOR )
- list(APPEND CORE_PUBLIC_DEFS -DRMLUI_MATRIX_ROW_MAJOR)
- endif ()
- if( CUSTOM_CONFIGURATION AND CUSTOM_LINK_LIBRARIES )
- target_link_libraries(RmlCore PUBLIC ${CUSTOM_LINK_LIBRARIES})
- endif ()
- if (PRECOMPILED_HEADERS_ENABLED)
- target_precompile_headers(RmlCore PRIVATE ${PROJECT_SOURCE_DIR}/Source/Core/precompiled.h)
- endif()
- else(NOT BUILD_FRAMEWORK)
- #===================================
- # Build combined Framework =========
- #===================================
- set(NAME RmlUi)
- set(MASTER_PUB_HDR_FILES
- ${MASTER_Core_PUB_HDR_FILES}
- ${MASTER_Debugger_PUB_HDR_FILES}
- )
- add_library(${NAME}
- ${Core_HDR_FILES}
- ${MASTER_Core_PUB_HDR_FILES}
- ${Core_PUB_HDR_FILES}
- ${Core_SRC_FILES}
- ${Debugger_HDR_FILES}
- ${MASTER_Debugger_PUB_HDR_FILES}
- ${Debugger_PUB_HDR_FILES}
- ${Debugger_SRC_FILES}
- )
- set_target_properties(${NAME} PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION ${PROJECT_VERSION_MAJOR}
- )
- set_property(SOURCE ${MASTER_PUB_HDR_FILES}
- PROPERTY MACOSX_PACKAGE_LOCATION Headers
- )
- set_property(SOURCE ${Core_PUB_HDR_FILES}
- PROPERTY MACOSX_PACKAGE_LOCATION Headers/Core
- )
- set_property(SOURCE ${Debugger_PUB_HDR_FILES}
- PROPERTY MACOSX_PACKAGE_LOCATION Headers/Debugger
- )
- set_target_properties(${NAME} PROPERTIES
- FRAMEWORK TRUE
- FRAMEWORK_VERSION ${PROJECT_VERSION}
- MACOSX_FRAMEWORK_IDENTIFIER com.rmlui.${NAME}
- MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${RMLUI_VERSION_SHORT}
- MACOSX_FRAMEWORK_BUNDLE_VERSION ${PROJECT_VERSION}
- XCODE_ATTRIBUTE_INSTALL_PATH "@rpath"
- PUBLIC_HEADER ${MASTER_PUB_HDR_FILES}
- )
- install(TARGETS ${NAME}
- EXPORT RmlUiTargets
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- FRAMEWORK DESTINATION Library/Frameworks
- )
- set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${NAME})
- endif(NOT BUILD_FRAMEWORK)
- # Build Lua bindings
- if(BUILD_LUA_BINDINGS)
- set(NAME RmlLua)
- add_library(${NAME} ${Lua_SRC_FILES}
- ${Lua_HDR_FILES}
- ${Lua_PUB_HDR_FILES}
- )
- set_target_properties(${NAME} PROPERTIES
- VERSION ${PROJECT_VERSION}
- SOVERSION ${PROJECT_VERSION_MAJOR}
- )
-
- add_common_target_options(${NAME})
- install(TARGETS ${NAME}
- EXPORT RmlUiTargets
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- )
-
- set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${NAME})
- endif()
- if(DISABLE_RTTI_AND_EXCEPTIONS)
- if( CMAKE_COMPILER_IS_GNUCXX )
- add_definitions( -fno-rtti -fno-exceptions )
- elseif( MSVC )
- add_definitions( -D_HAS_EXCEPTIONS=0 /GR- )
- if(CMAKE_CXX_FLAGS MATCHES "/EHsc ")
- string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- message(STATUS "CMAKE_CXX_FLAGS matches /EHsc before end of string replaced...")
- endif()
- if(CMAKE_CXX_FLAGS MATCHES "/EHsc$")
- string(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- message(STATUS "CMAKE_CXX_FLAGS matches /EHsc at end of string replaced...")
- endif()
- else()
- message(STATUS "Could not create build configuration without rtti and exceptions...")
- endif()
- endif()
- #===================================
- # Link libraries ===================
- #===================================
- if(NOT BUILD_FRAMEWORK)
- target_include_directories(RmlCore PRIVATE ${CORE_INCLUDE_DIRS})
- target_include_directories(RmlCore INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Include> $<INSTALL_INTERFACE:include>)
- target_link_libraries(RmlCore PRIVATE ${CORE_LINK_LIBS})
- target_link_libraries(RmlDebugger RmlCore)
- target_compile_definitions(RmlCore PRIVATE ${CORE_PRIVATE_DEFS})
- target_compile_definitions(RmlCore PUBLIC ${CORE_PUBLIC_DEFS})
- else()
- target_include_directories(RmlUi PRIVATE ${CORE_INCLUDE_DIRS})
- target_link_libraries(RmlUi PRIVATE ${CORE_LINK_LIBS})
- target_compile_definitions(RmlUi PRIVATE ${CORE_PRIVATE_DEFS})
- target_compile_definitions(RmlUi PUBLIC ${CORE_PUBLIC_DEFS})
- endif()
- if(BUILD_LUA_BINDINGS)
- if(NOT BUILD_FRAMEWORK)
- target_link_libraries(RmlLua RmlCore ${LUA_BINDINGS_LINK_LIBS})
- target_include_directories(RmlLua PUBLIC ${LUA_BINDINGS_INCLUDE_DIRS})
- else()
- target_link_libraries(RmlUi ${LUA_BINDINGS_LINK_LIBS})
- target_include_directories(RmlUi PUBLIC ${LUA_BINDINGS_INCLUDE_DIRS})
- endif()
- endif()
- #===================================
- # Build samples ====================
- #===================================
- # Build and link the samples
- macro(bl_sample NAME)
- if (WIN32)
- add_executable(${NAME} WIN32 ${${NAME}_SRC_FILES} ${${NAME}_HDR_FILES} )
- elseif(APPLE)
- add_executable(${NAME} MACOSX_BUNDLE ${${NAME}_SRC_FILES} ${${NAME}_HDR_FILES} )
- # The first rpath is to the proper location where the framework/library SHOULD be, the second is to the location actually seen
- # in the build environment
- if(BUILD_FRAMEWORK)
- set_target_properties(${NAME} PROPERTIES LINK_FLAGS "-rpath @executable_path/../Frameworks")
- else()
- set_target_properties(${NAME} PROPERTIES LINK_FLAGS "-rpath @executable_path/../lib")
- endif()
- else()
- add_executable(${NAME} ${${NAME}_SRC_FILES} ${${NAME}_HDR_FILES} )
- endif()
-
- add_common_target_options(${NAME})
- target_link_libraries(${NAME} ${ARGN})
- endmacro()
- # Build shell
- if(BUILD_SAMPLES OR BUILD_TESTING)
- include(SampleFileList)
-
- if(NOT BUILD_FRAMEWORK)
- set(sample_LIBRARIES
- shell
- RmlCore
- RmlDebugger
- )
- else()
- set(sample_LIBRARIES
- shell
- RmlUi
- )
- endif()
- # Find OpenGL
- find_package(OpenGL REQUIRED)
-
- if(OPENGL_FOUND)
- include_directories(${OPENGL_INCLUDE_DIR})
- list(APPEND sample_LIBRARIES ${OPENGL_LIBRARIES})
- endif()
-
- # Set up required system libraries
- if(APPLE)
- include(FindCarbon)
- find_package(Carbon REQUIRED)
-
- if (Carbon_FOUND)
- include_directories(${Carbon_INCLUDE_DIR})
- list(APPEND sample_LIBRARIES ${Carbon_LIBRARIES})
- endif()
- else()
- find_package(X11 REQUIRED)
- if (X11_FOUND)
- list(APPEND sample_LIBRARIES ${X11_LIBRARIES})
- # shell/src/x11/InputX11.cpp:InitialiseX11Keymap uses Xkb if
- # possible instead of XGetKeyboardMapping for performance
- if(X11_Xkb_FOUND)
- FIND_PACKAGE_MESSAGE(X11 "Found X11 KBlib: ${X11_X11_LIB}" "[${X11_X11_LIB}][${X11_XkbINCLUDE_DIR}]")
- add_definitions(-DHAS_X11XKBLIB)
- endif()
- endif()
- endif()
-
- set(SAMPLES_DIR opt/RmlUi/Samples CACHE PATH "path to samples dir")
-
- if(WIN32)
- mark_as_advanced(SAMPLES_DIR)
- endif()
- # The samples and tutorials use the shell library
- include_directories(${PROJECT_SOURCE_DIR}/Samples/shell/include)
- # Build and install sample shell library
- add_library(shell STATIC ${shell_SRC_FILES} ${shell_HDR_FILES})
-
- if (PRECOMPILED_HEADERS_ENABLED)
- target_precompile_headers(shell PRIVATE ${PROJECT_SOURCE_DIR}/Samples/shell/src/precompiled.h)
- endif()
- if (WIN32)
- target_link_libraries(shell PUBLIC shlwapi)
- endif()
-
- target_link_libraries(shell PUBLIC RmlCore)
-
- add_common_target_options(shell)
- endif()
- if(BUILD_SAMPLES)
- set(samples treeview customlog drag loaddocument transform bitmapfont animation benchmark demo databinding)
- set(tutorials template datagrid datagrid_tree drag)
- # Build and install the basic samples
- foreach(sample ${samples})
- bl_sample(${sample} ${sample_LIBRARIES})
- # The samples always set this as their current working directory
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/${sample})
- install(TARGETS ${sample}
- RUNTIME DESTINATION ${SAMPLES_DIR}/${sample}
- BUNDLE DESTINATION ${SAMPLES_DIR})
- endforeach()
-
- message("-- Can SDL2 samples be built")
- find_package(SDL2)
- if(SDL2_FOUND)
- find_package(SDL2_image)
- if(SDL2_IMAGE_FOUND)
- find_package(GLEW)
- if(GLEW_FOUND)
- message("-- Can SDL2 sample w/OpenGL renderer be built - yes")
- include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
- bl_sample(sdl2 ${sample_LIBRARIES} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${GLEW_LIBRARIES})
-
- # The samples always set this as their current working directory
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/sdl2)
- install(TARGETS sdl2
- RUNTIME DESTINATION ${SAMPLES_DIR}/sdl2
- BUNDLE DESTINATION ${SAMPLES_DIR})
- else()
- message("-- Can SDL2 sample w/OpenGL renderer be built - no - GLEW not found")
- endif()
-
- if("${SDL2_VERSION}" VERSION_GREATER_EQUAL "2.0.20")
- message("-- Can SDL2 sample w/SDL-renderer be built - yes")
- include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR})
- bl_sample(sdl2_sdlrenderer ${sample_LIBRARIES} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY})
-
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/sdl2_sdlrenderer)
- install(TARGETS sdl2_sdlrenderer
- RUNTIME DESTINATION ${SAMPLES_DIR}/sdl2_sdlrenderer
- BUNDLE DESTINATION ${SAMPLES_DIR})
- else()
- message("-- Can SDL2 sample w/SDL-renderer be built - no - requires SDL 2.0.20 (found ${SDL2_VERSION})")
- endif()
- else()
- message("-- Can SDL2 samples be built - SDL2_image not found")
- endif()
- else()
- message("-- Can SDL2 samples be built - SDL2 not found")
- endif()
- message("-- Can SFML 2.x sample be built")
- if (WIN32)
- find_package(SFML 2 COMPONENTS graphics window system main)
- else()
- find_package(SFML 2 COMPONENTS graphics window system)
- endif()
- if(NOT SFML_FOUND)
- message("-- Can SFML 2.x sample be built - no")
- else()
- find_package(GLEW)
- if(GLEW_FOUND)
- message("-- Can SFML 2.x sample be built - yes: with GLEW")
- include_directories(${SFML_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
- add_definitions( -DENABLE_GLEW )
- bl_sample(sfml2 ${sample_LIBRARIES} ${SFML_LIBRARIES} ${GLEW_LIBRARIES})
- else()
- message("-- Can SFML 2.x sample be built - yes: without GLEW")
- include_directories(${SFML_INCLUDE_DIR})
- bl_sample(sfml2 ${sample_LIBRARIES} ${SFML_LIBRARIES})
- endif()
-
- # The samples always set this as their current working directory
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/sfml2)
- install(TARGETS sfml2
- RUNTIME DESTINATION ${SAMPLES_DIR}/sfml2
- BUNDLE DESTINATION ${SAMPLES_DIR})
- endif()
-
- if( ENABLE_LOTTIE_PLUGIN )
- bl_sample(lottie ${sample_LIBRARIES})
-
- # The samples always set this as their current working directory
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/lottie)
- install(TARGETS lottie
- RUNTIME DESTINATION ${SAMPLES_DIR}/lottie
- BUNDLE DESTINATION ${SAMPLES_DIR}
- )
- endif()
-
- if( ENABLE_SVG_PLUGIN )
- bl_sample(svg ${sample_LIBRARIES})
-
- # The samples always set this as their current working directory
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/svg)
- install(TARGETS svg
- RUNTIME DESTINATION ${SAMPLES_DIR}/svg
- BUNDLE DESTINATION ${SAMPLES_DIR}
- )
- endif()
- # Build and install the tutorials
- foreach(tutorial ${tutorials})
- set(tutorial_fullname tutorial_${tutorial})
- bl_sample(${tutorial_fullname} ${sample_LIBRARIES})
-
- # The tutorials always set this as their current working directory
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/tutorial/${tutorial})
- install(TARGETS ${tutorial_fullname}
- RUNTIME DESTINATION ${SAMPLES_DIR}/${tutorial}
- BUNDLE DESTINATION ${SAMPLES_DIR})
- endforeach()
- # Build and install invaders sample
- bl_sample(invaders ${sample_LIBRARIES})
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/invaders)
- install(TARGETS invaders
- RUNTIME DESTINATION ${SAMPLES_DIR}/invaders
- BUNDLE DESTINATION ${SAMPLES_DIR})
- if(BUILD_LUA_BINDINGS)
- bl_sample(luainvaders RmlLua ${sample_LIBRARIES} ${LUA_BINDINGS_LINK_LIBS})
- install(DIRECTORY DESTINATION ${SAMPLES_DIR}/luainvaders)
- install(TARGETS luainvaders
- RUNTIME DESTINATION ${SAMPLES_DIR}/luainvaders
- BUNDLE DESTINATION ${SAMPLES_DIR})
- endif()
- endif()
- #===================================
- # Add tests ========================
- #===================================
- if(RMLUI_TESTS_ENABLED)
- add_subdirectory(Tests)
- endif()
- #===================================
- # Installation =====================
- #===================================
- if(BUILD_LUA_BINDINGS)
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Include/RmlUi
- DESTINATION include
- )
- else()
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Include/RmlUi
- DESTINATION include
- PATTERN "Lua" EXCLUDE
- )
- endif()
- if(BUILD_SAMPLES)
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/assets
- DESTINATION ${SAMPLES_DIR}
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/tutorial/template/data
- DESTINATION ${SAMPLES_DIR}/tutorial/template
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid/data
- DESTINATION ${SAMPLES_DIR}/tutorial/datagrid
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/tutorial/datagrid_tree/data
- DESTINATION ${SAMPLES_DIR}/tutorial/datagrid_tree
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/tutorial/drag/data
- DESTINATION ${SAMPLES_DIR}/tutorial/drag
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/animation/data
- DESTINATION ${SAMPLES_DIR}/basic/animation
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/benchmark/data
- DESTINATION ${SAMPLES_DIR}/basic/benchmark
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/bitmapfont/data
- DESTINATION ${SAMPLES_DIR}/basic/bitmapfont
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/databinding/data
- DESTINATION ${SAMPLES_DIR}/basic/databinding
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/demo/data
- DESTINATION ${SAMPLES_DIR}/basic/demo
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/transform/data
- DESTINATION ${SAMPLES_DIR}/basic/transform
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/treeview/data
- DESTINATION ${SAMPLES_DIR}/basic/treeview
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/drag/data
- DESTINATION ${SAMPLES_DIR}/basic/drag
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/invaders/data
- DESTINATION ${SAMPLES_DIR}/invaders
- )
-
- if(TARGET lottie)
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/lottie/data
- DESTINATION ${SAMPLES_DIR}/basic/lottie
- )
- endif()
- if(TARGET svg)
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/basic/svg/data
- DESTINATION ${SAMPLES_DIR}/basic/svg
- )
- endif()
- if(BUILD_LUA_BINDINGS)
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/luainvaders/data
- DESTINATION ${SAMPLES_DIR}/luainvaders
- )
- install(DIRECTORY ${PROJECT_SOURCE_DIR}/Samples/luainvaders/lua
- DESTINATION ${SAMPLES_DIR}/luainvaders
- )
- endif()
- endif()
- #===================================
- # Generate Config.cmake files ======
- #===================================
- # Try to include helper module
- include(CMakePackageConfigHelpers OPTIONAL RESULT_VARIABLE PkgHelpers_AVAILABLE)
- # guard against older versions of cmake which do not provide it
- if(PkgHelpers_AVAILABLE)
- set (INCLUDE_INSTALL_DIR "include")
- set (LIB_INSTALL_DIR "lib")
- set (INCLUDE_DIR "${PROJECT_SOURCE_DIR}/Include")
- # generate configuration for install tree
- configure_package_config_file(${PROJECT_SOURCE_DIR}/CMake/RmlUiConfig.cmake.install.in
- ${CMAKE_CURRENT_BINARY_DIR}/install/RmlUiConfig.cmake
- INSTALL_DESTINATION ${LIB_INSTALL_DIR}/RmlUi/cmake
- PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR)
- write_basic_package_version_file(
- ${CMAKE_CURRENT_BINARY_DIR}/install/RmlUiConfigVersion.cmake
- VERSION ${PROJECT_VERSION}
- COMPATIBILITY SameMajorVersion )
- install(FILES ${CMAKE_CURRENT_BINARY_DIR}/install/RmlUiConfig.cmake
- ${CMAKE_CURRENT_BINARY_DIR}/install/RmlUiConfigVersion.cmake
- DESTINATION ${LIB_INSTALL_DIR}/RmlUi/cmake )
- install(EXPORT RmlUiTargets
- DESTINATION ${LIB_INSTALL_DIR}/RmlUi/cmake)
- # generate configuration for build tree
- configure_package_config_file(${PROJECT_SOURCE_DIR}/CMake/RmlUiConfig.cmake.build.in
- ${CMAKE_CURRENT_BINARY_DIR}/RmlUiConfig.cmake
- INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
- PATH_VARS INCLUDE_DIR CMAKE_CURRENT_BINARY_DIR)
- export(TARGETS ${RMLUI_EXPORTED_TARGETS}
- FILE "${CMAKE_CURRENT_BINARY_DIR}/RmlUiTargets.cmake")
- write_basic_package_version_file(
- ${CMAKE_CURRENT_BINARY_DIR}/RmlUiConfigVersion.cmake
- VERSION ${PROJECT_VERSION}
- COMPATIBILITY SameMajorVersion )
- set(RmlUi_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE PATH "The directory containing a CMake configuration file for RmlUi.")
- else()
- message("If you wish to use find_package(RmlUi) in your own project to find RmlUi library"
- " please update cmake to version which provides CMakePackageConfighelpers module"
- " or write generators for RmlUiConfig.cmake by yourself.")
- endif()
|