2017-10-27 06:19:01 +02:00
|
|
|
add_library(rw_interface INTERFACE)
|
|
|
|
add_library(openrw::interface ALIAS rw_interface)
|
|
|
|
|
2018-08-23 15:23:43 +02:00
|
|
|
add_library(rw_checks INTERFACE)
|
|
|
|
add_library(openrw::checks ALIAS rw_checks)
|
|
|
|
target_link_libraries(rw_interface INTERFACE rw_checks)
|
|
|
|
|
2017-10-27 06:19:01 +02:00
|
|
|
# target_compile_features(rw_interface INTERFACE cxx_std_14) is not supported by CMake 3.2
|
2018-08-23 13:13:39 +02:00
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
2018-10-13 23:17:24 +02:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2017-10-27 06:19:01 +02:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
|
2018-02-10 02:07:35 +01:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
2017-11-03 19:59:17 +01:00
|
|
|
target_compile_options(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
"-Wall"
|
|
|
|
"-Wextra"
|
|
|
|
"-Wdouble-promotion"
|
|
|
|
"-Wpedantic"
|
2018-09-01 04:09:03 +02:00
|
|
|
"-Wmissing-braces"
|
2018-07-29 16:34:26 +02:00
|
|
|
"$<IF:$<COMPILE_LANGUAGE:CXX>,-Wold-style-cast,>"
|
2017-11-03 19:59:17 +01:00
|
|
|
)
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
2018-08-23 15:23:43 +02:00
|
|
|
target_compile_definitions(rw_checks
|
2017-11-03 19:59:17 +01:00
|
|
|
INTERFACE
|
|
|
|
"_SCL_SECURE_NO_WARNINGS"
|
|
|
|
"_CRT_SECURE_NO_WARNINGS"
|
|
|
|
)
|
2018-08-29 15:51:09 +02:00
|
|
|
target_compile_options(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
"/MP"
|
|
|
|
)
|
2017-11-03 19:59:17 +01:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unknown compiler ID: '${CMAKE_CXX_COMPILER_ID}'")
|
|
|
|
endif()
|
|
|
|
|
2018-02-10 02:07:35 +01:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL Clang OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
2017-11-03 19:59:17 +01:00
|
|
|
target_compile_options(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
"-Wno-gnu-array-member-paren-init"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(MINGW)
|
|
|
|
target_compile_options(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
"-fpermissive"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2018-08-27 18:58:06 +02:00
|
|
|
if(WIN32)
|
|
|
|
# Required minimum version of Windows = Vista
|
|
|
|
set(RW_NTDDI_VISTA 0x06000000)
|
|
|
|
set(RW_WINVER 0x0600)
|
|
|
|
target_compile_definitions(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
"NTDDI_VERSION=${RW_NTDDI_VISTA}"
|
|
|
|
"WINVER=${RW_WINVER}"
|
|
|
|
"_WIN32_WINNT=${RW_WINVER}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2017-10-27 06:19:01 +02:00
|
|
|
target_compile_definitions(rw_interface
|
|
|
|
INTERFACE
|
2018-07-13 00:28:01 +02:00
|
|
|
"$<$<CONFIG:Debug>:RW_DEBUG>"
|
2018-09-16 00:49:10 +02:00
|
|
|
"GLM_FORCE_PURE"
|
2017-10-27 06:19:01 +02:00
|
|
|
"GLM_FORCE_RADIANS"
|
2018-02-10 16:31:28 +01:00
|
|
|
"GLM_ENABLE_EXPERIMENTAL"
|
2018-07-13 00:28:01 +02:00
|
|
|
"$<$<BOOL:${RW_VERBOSE_DEBUG_MESSAGES}>:RW_VERBOSE_DEBUG_MESSAGES>"
|
2018-07-13 00:13:45 +02:00
|
|
|
"$<$<BOOL:${ENABLE_PROFILING}>:RW_PROFILER>"
|
2017-10-27 06:19:01 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
|
|
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")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_FREEBSD")
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_NETBSD")
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_OPENBSD")
|
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_WINDOWS")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unknown platform \"${CMAKE_SYSTEM_NAME}\". please update CMakeLists.txt.")
|
|
|
|
endif()
|
|
|
|
|
2018-07-06 02:25:48 +02:00
|
|
|
target_compile_definitions(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
BOOST_ALL_NO_LIB
|
|
|
|
)
|
|
|
|
|
|
|
|
if(NOT BOOST_STATIC)
|
|
|
|
target_compile_definitions(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
BOOST_ALL_DYN_LINK
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2018-06-07 02:19:53 +02:00
|
|
|
if(USE_CONAN)
|
|
|
|
if(CONAN_SETTINGS_COMPILER_LIBCXX STREQUAL "libstdc++11")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE _GLIBCXX_USE_CXX11_ABI=1)
|
|
|
|
elseif(CONAN_SETTINGS_COMPILER_LIBCXX STREQUAL "libstdc++")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE _GLIBCXX_USE_CXX11_ABI=0)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-10-29 23:50:59 +01:00
|
|
|
if(FILESYSTEM_LIBRARY STREQUAL "CXX17")
|
2018-06-26 14:16:10 +02:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2017-10-29 23:50:59 +01:00
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_FS_LIBRARY=0")
|
2018-06-26 14:16:10 +02:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
|
|
|
target_link_libraries(rw_interface INTERFACE "stdc++fs")
|
|
|
|
endif()
|
2017-10-29 23:50:59 +01:00
|
|
|
elseif(FILESYSTEM_LIBRARY STREQUAL "CXXTS")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_FS_LIBRARY=1")
|
2018-06-26 14:16:10 +02:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
2017-10-29 23:50:59 +01:00
|
|
|
target_link_libraries(rw_interface INTERFACE "stdc++fs")
|
|
|
|
endif()
|
|
|
|
elseif(FILESYSTEM_LIBRARY STREQUAL "BOOST")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_FS_LIBRARY=2")
|
|
|
|
target_link_libraries(rw_interface INTERFACE
|
2018-06-24 00:43:06 +02:00
|
|
|
Boost::filesystem
|
2017-10-29 23:50:59 +01:00
|
|
|
)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Illegal FILESYSTEM_LIBRARY option. (was '${FILESYSTEM_LIBRARY}')")
|
|
|
|
endif()
|
|
|
|
|
2017-10-27 06:19:01 +02:00
|
|
|
if(ENABLE_SCRIPT_DEBUG)
|
|
|
|
target_compile_definitions(rw_interface
|
|
|
|
INTERFACE
|
|
|
|
"RW_SCRIPT_DEBUG"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(FAILED_CHECK_ACTION STREQUAL "IGNORE")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_FAILED_CHECK_ACTION=0")
|
|
|
|
elseif(FAILED_CHECK_ACTION STREQUAL "ABORT")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_FAILED_CHECK_ACTION=1")
|
|
|
|
elseif(FAILED_CHECK_ACTION STREQUAL "BREAKPOINT")
|
|
|
|
target_compile_definitions(rw_interface INTERFACE "RW_FAILED_CHECK_ACTION=2")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Illegal FAILED_CHECK_ACTION option. (was '${FAILED_CHECK_ACTION}')")
|
|
|
|
endif()
|
2017-10-28 08:15:34 +02:00
|
|
|
|
|
|
|
if(TEST_COVERAGE)
|
|
|
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
2017-04-24 17:39:58 +02:00
|
|
|
message("TEST_COVERAGE enabled. Setting CMAKE_BUILD_TYPE to Debug.")
|
2017-10-28 08:15:34 +02:00
|
|
|
set(CMAKE_BUILD_TYPE "Debug")
|
|
|
|
endif()
|
|
|
|
if(NOT BUILD_TESTS)
|
2017-04-24 17:39:58 +02:00
|
|
|
message("TEST_COVERAGE enabled. Enabling BUILD_TESTS.")
|
2017-10-28 08:15:34 +02:00
|
|
|
set(BUILD_TESTS "ON")
|
|
|
|
endif()
|
2018-08-23 15:23:43 +02:00
|
|
|
target_compile_options(rw_checks
|
2017-10-28 08:15:34 +02:00
|
|
|
INTERFACE
|
|
|
|
"-O0"
|
|
|
|
"-fprofile-arcs"
|
|
|
|
"-ftest-coverage"
|
|
|
|
)
|
2018-08-23 15:23:43 +02:00
|
|
|
target_link_libraries(rw_checks
|
2017-11-04 00:10:33 +01:00
|
|
|
INTERFACE
|
|
|
|
gcov
|
|
|
|
)
|
2017-10-28 08:15:34 +02:00
|
|
|
endif()
|
2017-10-29 07:37:18 +01:00
|
|
|
|
2018-02-14 00:42:39 +01:00
|
|
|
foreach(SAN ${ENABLE_SANITIZERS})
|
2018-06-08 10:18:05 +02:00
|
|
|
if(SAN STREQUAL "address")
|
2018-02-14 00:42:39 +01:00
|
|
|
message(STATUS "Address sanitizer enabled.")
|
2018-08-23 15:23:43 +02:00
|
|
|
target_compile_options(rw_checks INTERFACE "-fsanitize=address")
|
|
|
|
target_link_libraries(rw_checks INTERFACE "-fsanitize=address")
|
2018-06-08 10:18:05 +02:00
|
|
|
elseif(SAN STREQUAL "leak")
|
2018-02-14 00:42:39 +01:00
|
|
|
message(STATUS "Leak sanitizer enabled.")
|
2018-08-23 15:23:43 +02:00
|
|
|
target_compile_options(rw_checks INTERFACE "-fsanitize=leak")
|
|
|
|
target_link_libraries(rw_checks INTERFACE "-fsanitize=leak")
|
2018-06-08 10:18:05 +02:00
|
|
|
elseif(SAN STREQUAL "thread")
|
2018-02-14 00:42:39 +01:00
|
|
|
message(STATUS "Thread sanitizer enabled.")
|
2018-08-23 15:23:43 +02:00
|
|
|
target_compile_options(rw_checks INTERFACE "-fsanitize=thread")
|
|
|
|
target_link_libraries(rw_checks INTERFACE "-fsanitize=thread")
|
2018-06-08 10:18:05 +02:00
|
|
|
elseif(SAN STREQUAL "undefined")
|
2018-02-14 00:42:39 +01:00
|
|
|
message(STATUS "Undefined behaviour sanitizer enabled.")
|
2018-08-23 15:23:43 +02:00
|
|
|
target_compile_options(rw_checks INTERFACE "-fsanitize=undefined")
|
|
|
|
target_link_libraries(rw_checks INTERFACE "-fsanitize=undefined")
|
2018-06-08 10:18:05 +02:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Illegal sanitizer: ${SAN}")
|
2018-02-14 00:42:39 +01:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2017-10-29 07:37:18 +01:00
|
|
|
function(openrw_target_apply_options)
|
2017-10-30 23:44:40 +01:00
|
|
|
set(IWYU_MAPPING "${PROJECT_SOURCE_DIR}/openrw_iwyu.imp")
|
2018-09-01 18:23:10 +02:00
|
|
|
cmake_parse_arguments("ORW" "INSTALL;INSTALL_PDB" "TARGET" "" ${ARGN})
|
2018-03-06 00:49:11 +01:00
|
|
|
if(CHECK_IWYU)
|
2018-09-01 18:23:10 +02:00
|
|
|
iwyu_check(TARGET "${ORW_TARGET}"
|
2017-10-29 07:37:18 +01:00
|
|
|
EXTRA_OPTS
|
2017-10-30 23:44:40 +01:00
|
|
|
"--mapping_file=${IWYU_MAPPING}"
|
2017-10-29 07:37:18 +01:00
|
|
|
)
|
|
|
|
endif()
|
2018-03-06 00:49:11 +01:00
|
|
|
|
|
|
|
if(CHECK_CLANGTIDY)
|
2018-04-16 22:23:42 +02:00
|
|
|
clang_tidy_check_target(
|
2018-09-01 18:23:10 +02:00
|
|
|
TARGET "${ORW_TARGET}"
|
2018-04-16 22:23:42 +02:00
|
|
|
FORMAT_STYLE "file"
|
|
|
|
FIX "${CHECK_CLANGTIDY_FIX}"
|
|
|
|
CHECK_ALL
|
2018-03-06 00:49:11 +01:00
|
|
|
)
|
|
|
|
endif()
|
2018-09-01 05:15:58 +02:00
|
|
|
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
|
|
|
|
set_property(
|
2018-09-01 18:23:10 +02:00
|
|
|
TARGET "${ORW_TARGET}"
|
2018-09-01 05:15:58 +02:00
|
|
|
APPEND
|
|
|
|
PROPERTY STATIC_LIBRARY_FLAGS "-no_warning_for_no_symbols"
|
|
|
|
)
|
2018-09-01 16:59:21 +02:00
|
|
|
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
set_property(
|
2018-09-01 18:23:10 +02:00
|
|
|
TARGET "${ORW_TARGET}"
|
2018-09-01 16:59:21 +02:00
|
|
|
APPEND
|
|
|
|
PROPERTY LINK_FLAGS "/ignore:4099"
|
|
|
|
)
|
2018-09-01 05:15:58 +02:00
|
|
|
endif()
|
2018-09-01 18:23:10 +02:00
|
|
|
|
|
|
|
if(ORW_INSTALL)
|
|
|
|
install(
|
|
|
|
TARGETS "${ORW_TARGET}"
|
|
|
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
|
|
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
|
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
if(ORW_INSTALL_PDB)
|
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
|
|
|
install(FILES "$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:RELWITHDEBINFO>>:$<TARGET_PDB_FILE:${ORW_TARGET}>>"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2017-10-29 07:37:18 +01:00
|
|
|
endfunction()
|