1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 02:12:45 +01:00

cmake: use rwengine::interface + no more add_definitions & include_directories

This commit is contained in:
Anonymous Maarten 2017-10-26 00:44:45 +02:00 committed by Daniel Evans
parent e5a8395d5c
commit 1926795d63
7 changed files with 110 additions and 91 deletions

View File

@ -6,11 +6,6 @@ project(OpenRW)
# Options
#
# Global Build Configuration
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DRW_DEBUG=1")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -pthread -Wextra -Wpedantic -Wdouble-promotion")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
option(RW_VERBOSE_DEBUG_MESSAGES "Print verbose debugging messages" ON)
# Optional components
@ -32,59 +27,77 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug Release" FORCE)
endif()
add_library(rw_interface INTERFACE)
add_library(openrw::interface ALIAS rw_interface)
# target_compile_features(rw_interface INTERFACE cxx_std_14) is not supported by CMake 3.2
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
target_compile_options(rw_interface
INTERFACE
"-Wall"
"-Wextra"
"-Wdouble-promotion"
"-Wpedantic"
"-pthread"
)
target_compile_definitions(rw_interface
INTERFACE
"$<$<CONFIG:Debug>:RW_DEBUG=1>"
"GLM_FORCE_RADIANS"
"RW_VERBOSE_DEBUG_MESSAGES=$<BOOL:${RW_VERBOSE_DEBUG_MESSAGES}>"
)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules")
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_definitions(-DRW_LINUX)
elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions(-DRW_OSX)
target_compile_definitions(rw_interface INTERFACE "RW_LINUX")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
target_compile_definitions(rw_interface INTERFACE "RW_OSX")
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
add_definitions(-DRW_FREEBSD)
target_compile_definitions(rw_interface INTERFACE "RW_FREEBSD")
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
add_definitions(-DRW_NETBSD)
target_compile_definitions(rw_interface INTERFACE "RW_NETBSD")
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
add_definitions(-DRW_OPENBSD)
target_compile_definitions(rw_interface INTERFACE "RW_OPENBSD")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_definitions(-DRW_WINDOWS)
target_compile_definitions(rw_interface INTERFACE "RW_WINDOWS")
else ()
message(FATAL_ERROR "Unknown platform \"${CMAKE_SYSTEM_NAME}\". please update CMakeLists.txt.")
message(FATAL_ERROR "Unknown platform \"${CMAKE_SYSTEM_NAME}\". please update CMakeLists.txt.")
endif ()
if (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-array-member-paren-init")
target_compile_options(rw_interface INTERFACE "-Wno-gnu-array-member-paren-init")
endif()
if(MINGW)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive")
target_compile_options(rw_interface INTERFACE "-fpermissive")
endif()
# Make GLM use radians
add_definitions(-DGLM_FORCE_RADIANS)
target_compile_definitions(rw_interface
INTERFACE
"RENDER_PROFILER=0"
"RW_PROFILER=$<BOOL:${ENABLE_PROFILING}>"
)
IF(${ENABLE_PROFILING})
add_definitions(-DRENDER_PROFILER=0 -DRW_PROFILER=1)
else()
add_definitions(-DRENDER_PROFILER=0 -DRW_PROFILER=0)
ENDIF()
IF(${ENABLE_SCRIPT_DEBUG})
add_definitions(-DRW_SCRIPT_DEBUG)
IF(ENABLE_SCRIPT_DEBUG)
target_compile_definitions(rw_interface
INTERFACE
"RW_SCRIPT_DEBUG"
)
ENDIF()
if(FAILED_CHECK_ACTION STREQUAL "IGNORE")
add_definitions(-DRW_FAILED_CHECK_ACTION=0)
target_compile_definitions(rw_interface INTERFACE "RW_FAILED_CHECK_ACTION=0")
elseif(FAILED_CHECK_ACTION STREQUAL "ABORT")
add_definitions(-DRW_FAILED_CHECK_ACTION=1)
target_compile_definitions(rw_interface INTERFACE "RW_FAILED_CHECK_ACTION=1")
elseif(FAILED_CHECK_ACTION STREQUAL "BREAKPOINT")
add_definitions(-DRW_FAILED_CHECK_ACTION=2)
target_compile_definitions(rw_interface INTERFACE "RW_FAILED_CHECK_ACTION=2")
else()
message(FATAL_ERROR "Illegal FAILED_CHECK_ACTION option.")
endif()
if(${RW_VERBOSE_DEBUG_MESSAGES})
add_definitions(-DRW_VERBOSE_DEBUG_MESSAGES=1)
else()
add_definitions(-DRW_VERBOSE_DEBUG_MESSAGES=0)
endif()
if(NOT DEFINED BIN_DIR)
set(BIN_DIR "bin" CACHE PATH "BIN_DIR")
endif()
@ -101,14 +114,6 @@ find_package(GLM REQUIRED)
find_package(FFmpeg REQUIRED)
find_package(SDL2 REQUIRED)
include_directories(
${SDL2_INCLUDE_DIR}
${GLM_INCLUDE_DIRS}
${OPENGL_INCLUDE_DIR}
${BULLET_INCLUDE_DIRS}
${OPENAL_INCLUDE_DIR}
)
# External-internal dependencies
add_subdirectory(cmake/external)

View File

@ -134,24 +134,23 @@ add_library(rwengine
${RWENGINE_SOURCES}
)
if(MINGW)
target_link_libraries(rwengine)
endif()
target_link_libraries(rwengine
PUBLIC
rwlib
PRIVATE
${FFMPEG_LIBRARIES}
${OPENAL_LIBRARY}
${OPENRW_PLATFORM_LIBS}
${SDL2_LIBRARY})
)
include_directories(SYSTEM
${BULLET_INCLUDE_DIR}
${FFMPEG_INCLUDE_DIR}
${OPENAL_INCLUDE_DIR}
)
target_include_directories(rwengine
SYSTEM
PUBLIC
${BULLET_INCLUDE_DIR}
${FFMPEG_INCLUDE_DIR}
${OPENAL_INCLUDE_DIR}
)
target_include_directories(
rwengine
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
)
target_include_directories(rwengine
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/src"
)

View File

@ -37,30 +37,33 @@ set(RWGAME_SOURCES
states/DebugState.cpp
states/BenchmarkState.hpp
states/BenchmarkState.cpp
DrawUI.cpp
)
add_executable(rwgame
${RWGAME_SOURCES})
include_directories(SYSTEM
${BULLET_INCLUDE_DIR}
${OPENAL_INCLUDE_DIR}
)
include_directories(
"${CMAKE_SOURCE_DIR}/rwgame"
)
target_include_directories(rwgame
SYSTEM
PRIVATE
${BULLET_INCLUDE_DIR}
${OPENAL_INCLUDE_DIR}
${SDL2_INCLUDE_DIR}
)
target_include_directories(rwgame
PUBLIC
"${CMAKE_SOURCE_DIR}/rwgame"
)
target_link_libraries(rwgame
PRIVATE
rwengine
${Boost_LIBRARIES}
${OPENGL_LIBRARIES}
${BULLET_LIBRARIES}
${SDL2_LIBRARY}
)
if(MINGW)
target_link_libraries(rwgame)
endif()
)
install(TARGETS rwgame RUNTIME DESTINATION "${BIN_DIR}")

View File

@ -3,7 +3,7 @@
#include <glm/vec2.hpp>
#include <string>
#include "SDL.h"
#include <SDL.h>
#include <render/GameRenderer.hpp>

View File

@ -44,14 +44,21 @@ add_library(rwlib
${RWLIB_SOURCES}
)
include_directories(
target_include_directories(rwlib
PUBLIC
"${CMAKE_CURRENT_SOURCE_DIR}/source"
"${Boost_INCLUDE_DIRS}")
)
target_include_directories(rwlib
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/source")
SYSTEM
PUBLIC
"${Boost_INCLUDE_DIRS}"
)
target_link_libraries(rwlib
${OPENGL_LIBRARIES}
${OPENRW_PLATFORM_LIBS}
${Boost_LIBRARIES})
PUBLIC
openrw::interface
PRIVATE
${OPENGL_LIBRARIES}
${Boost_LIBRARIES}
)

View File

@ -23,7 +23,9 @@ add_executable(rwviewer
AnimationListModel.cpp
AnimationListWidget.cpp)
include_directories(SYSTEM
target_include_directories(rwviewer
SYSTEM
PRIVATE
${BULLET_INCLUDE_DIR})
target_link_libraries(rwviewer

View File

@ -2,12 +2,6 @@
# Unit Tests
##############################################################################
if(${TESTS_NODATA})
add_definitions(-DRW_TEST_WITH_DATA=0)
else()
add_definitions(-DRW_TEST_WITH_DATA=1)
endif()
find_package(Boost COMPONENTS filesystem unit_test_framework REQUIRED)
set(TEST_SOURCES
@ -54,17 +48,26 @@ set(TEST_SOURCES
"${CMAKE_SOURCE_DIR}/rwgame/GameInput.cpp"
)
ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
add_executable(run_tests ${TEST_SOURCES})
include_directories(
include
"${CMAKE_SOURCE_DIR}/tests"
"${CMAKE_SOURCE_DIR}/rwgame")
target_compile_definitions(run_tests
PRIVATE
"RW_TEST_WITH_DATA=$<NOT:$<BOOL:${TESTS_NODATA}>>"
"BOOST_TEST_DYN_LINK"
)
include_directories(SYSTEM
${BULLET_INCLUDE_DIR})
target_include_directories(run_tests
SYSTEM
PRIVATE
${BULLET_INCLUDE_DIR}
${SDL2_INCLUDE_DIR}
)
target_include_directories(run_tests
PRIVATE
"${CMAKE_SOURCE_DIR}/tests"
"${CMAKE_SOURCE_DIR}/rwgame"
)
target_link_libraries(run_tests
rwengine