Browse Source

Several CMake fixes so that clients can more easily find and import RmlUi. Now it exports required target libraries, definitions, and include directories.

Michael Ragazzon 4 years ago
parent
commit
98271c4398
1 changed files with 22 additions and 23 deletions
  1. 22 23
      CMakeLists.txt

+ 22 - 23
CMakeLists.txt

@@ -196,13 +196,13 @@ if(WIN32 AND BUILD_SHARED_LIBS AND BUILD_TESTING)
 endif()
 endif()
 
 
 if(NOT BUILD_SHARED_LIBS)
 if(NOT BUILD_SHARED_LIBS)
-	add_definitions(-DRMLUI_STATIC_LIB)
+	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.")
 	message("-- Building static libraries. Make sure to #define RMLUI_STATIC_LIB before including RmlUi in your project.")
 endif()
 endif()
 
 
 option(NO_THIRDPARTY_CONTAINERS "Only use standard library containers." OFF)
 option(NO_THIRDPARTY_CONTAINERS "Only use standard library containers." OFF)
 if( NO_THIRDPARTY_CONTAINERS )
 if( NO_THIRDPARTY_CONTAINERS )
-	add_definitions(-DRMLUI_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.")
 	message("-- No third-party containers will be used: Make sure to #define RMLUI_NO_THIRDPARTY_CONTAINERS before including RmlUi in your project.")
 endif()
 endif()
 
 
@@ -210,7 +210,7 @@ option(CUSTOM_CONFIGURATION "Customize RmlUi configuration files for overriding
 
 
 set(CUSTOM_CONFIGURATION_FILE "" CACHE STRING "Custom configuration file to be included in place of <RmlUi/Config/Config.h>.")
 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 )
 if( CUSTOM_CONFIGURATION AND CUSTOM_CONFIGURATION_FILE )
-	add_definitions(-DRMLUI_CUSTOM_CONFIGURATION_FILE="${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>")
 	message("-- Including ${CUSTOM_CONFIGURATION_FILE} instead of <RmlUi/Config/Config.h>")
 endif ()
 endif ()
 
 
@@ -250,7 +250,7 @@ if( ENABLE_TRACY_PROFILING )
 		message("-- Tracy profiling enabled in configuration 'Tracy'.")
 		message("-- Tracy profiling enabled in configuration 'Tracy'.")
 	else()
 	else()
 		message("-- Tracy profiling enabled.")
 		message("-- Tracy profiling enabled.")
-		add_definitions(-DRMLUI_ENABLE_PROFILING)
+		list(APPEND CORE_PUBLIC_DEFS -DRMLUI_ENABLE_PROFILING)
 	endif()
 	endif()
 elseif( CMAKE_CONFIGURATION_TYPES )
 elseif( CMAKE_CONFIGURATION_TYPES )
 	list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES Tracy)
 	list(REMOVE_ITEM CMAKE_CONFIGURATION_TYPES Tracy)
@@ -261,7 +261,7 @@ option(ENABLE_SVG_PLUGIN "Enable plugin for SVG images. Requires the lunasvg lib
 
 
 option(DISABLE_RTTI_AND_EXCEPTIONS "Build with rtti and exceptions disabled." OFF)
 option(DISABLE_RTTI_AND_EXCEPTIONS "Build with rtti and exceptions disabled." OFF)
 if(DISABLE_RTTI_AND_EXCEPTIONS)
 if(DISABLE_RTTI_AND_EXCEPTIONS)
-	add_definitions(-DRMLUI_USE_CUSTOM_RTTI)
+	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.")
 	message("-- C++ RTTI and exceptions will be disabled: Make sure to #define RMLUI_USE_CUSTOM_RTTI before including RmlUi in your project.")
 endif()
 endif()
 
 
@@ -297,6 +297,7 @@ macro(add_common_target_options NAME)
 		endif()
 		endif()
 	elseif(MSVC)
 	elseif(MSVC)
 		target_compile_options(${NAME} PRIVATE /MP /W4 /w44062 /permissive-)
 		target_compile_options(${NAME} PRIVATE /MP /W4 /w44062 /permissive-)
+		target_compile_definitions(${NAME} PRIVATE _CRT_SECURE_NO_WARNINGS)
 		
 		
 		if(WARNINGS_AS_ERRORS)
 		if(WARNINGS_AS_ERRORS)
 			target_compile_options(${NAME} PRIVATE /WX)
 			target_compile_options(${NAME} PRIVATE /WX)
@@ -321,22 +322,16 @@ include(FileList)
 
 
 # FreeType
 # FreeType
 if(NOT NO_FONT_INTERFACE_DEFAULT)
 if(NOT NO_FONT_INTERFACE_DEFAULT)
-	find_package(Freetype REQUIRED)	
-
-	if(FREETYPE_FOUND)
-		include_directories(${FREETYPE_INCLUDE_DIRS})
-		link_directories(${FREETYPE_LINK_DIRS})
-		list(APPEND CORE_LINK_LIBS ${FREETYPE_LIBRARY})
-	endif()
+	find_package(Freetype REQUIRED)
+	list(APPEND CORE_LINK_LIBS ${FREETYPE_LIBRARIES})
+	list(APPEND CORE_INCLUDE_DIRS ${FREETYPE_INCLUDE_DIRS})
 endif()
 endif()
 
 
 # Lua
 # Lua
 if(BUILD_LUA_BINDINGS)
 if(BUILD_LUA_BINDINGS)
 	find_package(Lua REQUIRED)
 	find_package(Lua REQUIRED)
-	if(LUA_FOUND)
-		include_directories(${LUA_INCLUDE_DIR})
-		list(APPEND LUA_BINDINGS_LINK_LIBS ${LUA_LIBRARIES})
-	endif()
+	list(APPEND LUA_BINDINGS_INCLUDE_DIRS ${LUA_INCLUDE_DIR})
+	list(APPEND LUA_BINDINGS_LINK_LIBS ${LUA_LIBRARIES})
 endif()
 endif()
 
 
 # rlottie
 # rlottie
@@ -439,11 +434,8 @@ if( CUSTOM_CONFIGURATION )
 	endforeach(library ${CUSTOM_LINK_LIBRARIES})
 	endforeach(library ${CUSTOM_LINK_LIBRARIES})
 endif()
 endif()
 
 
-
-target_compile_definitions(RmlCore PRIVATE ${CORE_PRIVATE_DEFS})
-
 if( MATRIX_ROW_MAJOR )
 if( MATRIX_ROW_MAJOR )
-	target_compile_definitions(RmlCore PUBLIC -DRMLUI_MATRIX_ROW_MAJOR)
+	list(APPEND CORE_PUBLIC_DEFS -DRMLUI_MATRIX_ROW_MAJOR)
 endif ()
 endif ()
 if( CUSTOM_CONFIGURATION AND CUSTOM_LINK_LIBRARIES )
 if( CUSTOM_CONFIGURATION AND CUSTOM_LINK_LIBRARIES )
 	target_link_libraries(RmlCore PUBLIC ${CUSTOM_LINK_LIBRARIES})
 	target_link_libraries(RmlCore PUBLIC ${CUSTOM_LINK_LIBRARIES})
@@ -512,8 +504,6 @@ else(NOT BUILD_FRAMEWORK)
 	set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${NAME})
 	set(RMLUI_EXPORTED_TARGETS ${RMLUI_EXPORTED_TARGETS} ${NAME})
 endif(NOT BUILD_FRAMEWORK)
 endif(NOT BUILD_FRAMEWORK)
 
 
-# Add additional Core include directories
-target_include_directories(RmlCore PRIVATE ${CORE_INCLUDE_DIRS})
 
 
 # Build Lua bindings
 # Build Lua bindings
 if(BUILD_LUA_BINDINGS)
 if(BUILD_LUA_BINDINGS)
@@ -566,17 +556,26 @@ endif()
 #===================================
 #===================================
 
 
 if(NOT BUILD_FRAMEWORK)
 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 ${CORE_LINK_LIBS})
 	target_link_libraries(RmlCore ${CORE_LINK_LIBS})
 	target_link_libraries(RmlDebugger RmlCore)
 	target_link_libraries(RmlDebugger RmlCore)
+	target_compile_definitions(RmlCore PRIVATE ${CORE_PRIVATE_DEFS})
+	target_compile_definitions(RmlCore PUBLIC ${CORE_PUBLIC_DEFS})
 else()
 else()
+	target_include_directories(RmlUi PRIVATE ${CORE_INCLUDE_DIRS})
 	target_link_libraries(RmlUi ${CORE_LINK_LIBS})
 	target_link_libraries(RmlUi ${CORE_LINK_LIBS})
+	target_compile_definitions(RmlUi PRIVATE ${CORE_PRIVATE_DEFS})
+	target_compile_definitions(RmlUi PUBLIC ${CORE_PUBLIC_DEFS})
 endif()
 endif()
 
 
 if(BUILD_LUA_BINDINGS)
 if(BUILD_LUA_BINDINGS)
 	if(NOT BUILD_FRAMEWORK)
 	if(NOT BUILD_FRAMEWORK)
 		target_link_libraries(RmlLua RmlCore ${LUA_BINDINGS_LINK_LIBS})
 		target_link_libraries(RmlLua RmlCore ${LUA_BINDINGS_LINK_LIBS})
+		target_include_directories(RmlLua PRIVATE ${LUA_BINDINGS_INCLUDE_DIRS})
 	else()
 	else()
-		target_link_libraries(RmlLua RmlUi ${LUA_BINDINGS_LINK_LIBS})
+		target_link_libraries(RmlUi ${LUA_BINDINGS_LINK_LIBS})
+		target_include_directories(RmlUi PRIVATE ${LUA_BINDINGS_INCLUDE_DIRS})
 	endif()
 	endif()
 endif()
 endif()