From 46d4e11e8907dafef2aba8c26da68da01d722793 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 26 Mar 2021 22:02:33 -0500 Subject: [PATCH] [nostalgia,buildcore] Move a lot of generic CMake stuff to BuildCore --- CMakeLists.txt | 96 ++++--------------- deps/buildcore/base.cmake | 60 ++++++++++++ .../buildcore/cmake}/modules/Mingw.cmake | 0 .../cmake}/modules/address_sanitizer.cmake | 0 jenkins/shared/env.gy | 2 +- 5 files changed, 80 insertions(+), 78 deletions(-) create mode 100644 deps/buildcore/base.cmake rename {cmake => deps/buildcore/cmake}/modules/Mingw.cmake (100%) rename {cmake => deps/buildcore/cmake}/modules/address_sanitizer.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index af275c57..f6d2bfae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,9 @@ set(CMAKE_POLICY_DEFAULT_CMP0110 NEW) # requires CMake 3.19 project(nostalgia) -set(QTDIR "" CACHE PATH "Path to Qt Libraries") +include(deps/buildcore/base.cmake) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) -set(BUILDCORE_TARGET "Native" CACHE STRING "The type of build to produce(Native/GBA)") set(NOSTALGIA_BUILD_PLAYER ON CACHE BOOL "Build Player") set(NOSTALGIA_BUILD_STUDIO ON CACHE BOOL "Build Studio") set(OX_ENABLE_TRACEHOOK OFF CACHE BOOL "Generate OxTraceHook shared library for uprobes") @@ -17,86 +17,30 @@ else() endif() if(NOSTALGIA_BUILD_TYPE STREQUAL "GBA") - set(NOSTALGIA_BUILD_STUDIO OFF) set(OX_BARE_METAL ON) +endif() + +if(OX_BARE_METAL) + set(NOSTALGIA_BUILD_STUDIO OFF) set(OX_USE_STDLIB OFF) else() - set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QTDIR}) - set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) -endif() - - -list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) -include(GenerateExportHeader) -include(address_sanitizer) - -set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/dist/${BUILDCORE_BUILD_CONFIG}") -set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) -if(NOT OX_BARE_METAL) add_definitions(-DOX_USE_STDLIB) set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${QTDIR}) endif() -# enable ccache -if(NOT DEFINED ENV{NOSTALGIA_SUPPRESS_CCACHE}) - find_program(CCACHE_PROGRAM ccache) - if(CCACHE_PROGRAM) - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") - endif() -endif() - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DDEBUG) -else() - add_definitions(-DNDEBUG) -endif() - -if(NOT MSVC) - # forces colored output when using ninja - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") - - # enable warnings - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnull-dereference") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare") - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable") - - # disable warnings - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments") - - if(NOSTALGIA_BUILD_TYPE STREQUAL "GBA") - include(GBA) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-unwind-tables") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb-interwork") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=arm7tdmi") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=arm7tdmi") - endif() - - if (CMAKE_BUILD_TYPE STREQUAL "Release") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") - endif() +if(NOSTALGIA_BUILD_TYPE STREQUAL "GBA") + include(GBA) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-unwind-tables") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb-interwork") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthumb") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcpu=arm7tdmi") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=arm7tdmi") endif() if(APPLE) @@ -119,8 +63,6 @@ else() set(NOSTALGIA_DIST_RESOURCES share) endif() -enable_testing() - add_subdirectory(deps/ox) include_directories(SYSTEM deps/ox/src) diff --git a/deps/buildcore/base.cmake b/deps/buildcore/base.cmake new file mode 100644 index 00000000..625fa8c9 --- /dev/null +++ b/deps/buildcore/base.cmake @@ -0,0 +1,60 @@ + +set(QTDIR "" CACHE PATH "Path to Qt Libraries") + +set(BUILDCORE_TARGET "Native" CACHE STRING "The type of build to produce(Native/GBA)") + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake/modules) +include(GenerateExportHeader) +include(address_sanitizer) + +set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/dist/${BUILDCORE_BUILD_CONFIG}") +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) +# enable ccache +if(NOT DEFINED ENV{BUILDCORE_SUPPRESS_CCACHE}) + find_program(CCACHE_PROGRAM ccache) + if(CCACHE_PROGRAM) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") + endif() +endif() + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + add_definitions(-DDEBUG) +else() + add_definitions(-DNDEBUG) +endif() + +if(NOT MSVC) + # forces colored output when using ninja + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color") + # enable warnings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wcast-align") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat=2") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wmissing-field-initializers") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnull-dereference") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-compare") + #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wsign-conversion") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wunused-variable") + # disable warnings + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments") + # release build options + if (CMAKE_BUILD_TYPE STREQUAL "Release") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") + endif() +endif() + +enable_testing() + diff --git a/cmake/modules/Mingw.cmake b/deps/buildcore/cmake/modules/Mingw.cmake similarity index 100% rename from cmake/modules/Mingw.cmake rename to deps/buildcore/cmake/modules/Mingw.cmake diff --git a/cmake/modules/address_sanitizer.cmake b/deps/buildcore/cmake/modules/address_sanitizer.cmake similarity index 100% rename from cmake/modules/address_sanitizer.cmake rename to deps/buildcore/cmake/modules/address_sanitizer.cmake diff --git a/jenkins/shared/env.gy b/jenkins/shared/env.gy index 6fc89d9d..f5cde3b4 100644 --- a/jenkins/shared/env.gy +++ b/jenkins/shared/env.gy @@ -1,2 +1,2 @@ env.OX_NODEBUG = 1 -env.NOSTALGIA_SUPPRESS_CCACHE = 1 +env.BUILDCORE_SUPPRESS_CCACHE = 1