mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Modularize CMake build configuration
Build type no longer defaults to Release (!) have separate options for extra warning flags and sanitizers toss DEVELOP macro Fix sanitizers with CMake while I'm at it :|
This commit is contained in:
4
.github/workflows/testing.yml
vendored
4
.github/workflows/testing.yml
vendored
@@ -14,11 +14,11 @@ jobs:
|
|||||||
- os: ubuntu-18.04
|
- os: ubuntu-18.04
|
||||||
cc: gcc
|
cc: gcc
|
||||||
target: develop
|
target: develop
|
||||||
cmakevars: -DDEVELOP=ON
|
cmakevars: -DSANITIZERS=ON -DMORE_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug
|
||||||
- os: ubuntu-20.04
|
- os: ubuntu-20.04
|
||||||
cc: gcc
|
cc: gcc
|
||||||
target: develop
|
target: develop
|
||||||
cmakevars: -DDEVELOP=ON
|
cmakevars: -DSANITIZERS=ON -DMORE_WARNINGS=ON -DCMAKE_BUILD_TYPE=Debug
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
|
|||||||
@@ -12,18 +12,6 @@ cmake_policy(VERSION 3.0)
|
|||||||
project(rgbds
|
project(rgbds
|
||||||
LANGUAGES C)
|
LANGUAGES C)
|
||||||
|
|
||||||
option(DEVELOP "build in development mode" OFF)
|
|
||||||
|
|
||||||
set(DEFAULT_BUILD_TYPE "Release")
|
|
||||||
set(DEVELOP_BUILD_TYPE "Debug")
|
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
|
||||||
if(DEVELOP)
|
|
||||||
set(CMAKE_BUILD_TYPE "${DEVELOP_BUILD_TYPE}")
|
|
||||||
else()
|
|
||||||
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# get real path of source and binary directories
|
# get real path of source and binary directories
|
||||||
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
|
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
|
||||||
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
|
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
|
||||||
@@ -37,16 +25,26 @@ endif()
|
|||||||
|
|
||||||
include_directories("${PROJECT_SOURCE_DIR}/include")
|
include_directories("${PROJECT_SOURCE_DIR}/include")
|
||||||
|
|
||||||
if(DEVELOP)
|
option(SANITIZERS "Build with sanitizers enabled" OFF)
|
||||||
add_definitions(-DDEVELOP)
|
option(MORE_WARNINGS "Turn on more warnings" OFF)
|
||||||
endif()
|
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
add_compile_options(/W1 /MP)
|
add_compile_options(/W1 /MP)
|
||||||
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
|
||||||
else()
|
else()
|
||||||
if(DEVELOP)
|
add_compile_options(-Wall -pedantic)
|
||||||
add_compile_options(-Werror -Wall -Wextra -pedantic -Wno-type-limits
|
if(SANITIZERS)
|
||||||
|
set(SAN_FLAGS -fsanitize=shift -fsanitize=integer-divide-by-zero
|
||||||
|
-fsanitize=unreachable -fsanitize=vla-bound
|
||||||
|
-fsanitize=signed-integer-overflow -fsanitize=bounds
|
||||||
|
-fsanitize=object-size -fsanitize=bool -fsanitize=enum
|
||||||
|
-fsanitize=alignment -fsanitize=null)
|
||||||
|
add_compile_options(${SAN_FLAGS})
|
||||||
|
link_libraries(${SAN_FLAGS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(MORE_WARNINGS)
|
||||||
|
add_compile_options(-Werror -Wextra -Wno-type-limits
|
||||||
-Wno-sign-compare -Wformat -Wformat-security -Wformat-overflow=2
|
-Wno-sign-compare -Wformat -Wformat-security -Wformat-overflow=2
|
||||||
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused
|
-Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused
|
||||||
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5
|
-Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5
|
||||||
@@ -54,14 +52,6 @@ else()
|
|||||||
-Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op
|
-Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op
|
||||||
-Wnested-externs -Wno-aggressive-loop-optimizations -Winline
|
-Wnested-externs -Wno-aggressive-loop-optimizations -Winline
|
||||||
-Wundef -Wstrict-prototypes -Wold-style-definition)
|
-Wundef -Wstrict-prototypes -Wold-style-definition)
|
||||||
|
|
||||||
link_libraries(-fsanitize=shift -fsanitize=integer-divide-by-zero
|
|
||||||
-fsanitize=unreachable -fsanitize=vla-bound
|
|
||||||
-fsanitize=signed-integer-overflow -fsanitize=bounds
|
|
||||||
-fsanitize=object-size -fsanitize=bool -fsanitize=enum
|
|
||||||
-fsanitize=alignment -fsanitize=null)
|
|
||||||
else()
|
|
||||||
add_compile_options(-Wall -pedantic)
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -198,7 +198,7 @@ develop:
|
|||||||
-fsanitize=unreachable -fsanitize=vla-bound \
|
-fsanitize=unreachable -fsanitize=vla-bound \
|
||||||
-fsanitize=signed-integer-overflow -fsanitize=bounds \
|
-fsanitize=signed-integer-overflow -fsanitize=bounds \
|
||||||
-fsanitize=object-size -fsanitize=bool -fsanitize=enum \
|
-fsanitize=object-size -fsanitize=bool -fsanitize=enum \
|
||||||
-fsanitize=alignment -fsanitize=null -DDEVELOP" CFLAGS="-ggdb3 -O0"
|
-fsanitize=alignment -fsanitize=null" CFLAGS="-ggdb3 -O0"
|
||||||
|
|
||||||
# Targets for the project maintainer to easily create Windows exes.
|
# Targets for the project maintainer to easily create Windows exes.
|
||||||
# This is not for Windows users!
|
# This is not for Windows users!
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* This file is part of RGBDS.
|
* This file is part of RGBDS.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2014-2018, RGBDS contributors.
|
* Copyright (c) 2014-2020, RGBDS contributors.
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: MIT
|
* SPDX-License-Identifier: MIT
|
||||||
*/
|
*/
|
||||||
@@ -23,10 +23,6 @@
|
|||||||
#define trap_
|
#define trap_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DEVELOP
|
|
||||||
#define DEVELOP 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Macros for stringification */
|
/* Macros for stringification */
|
||||||
#define STR(x) #x
|
#define STR(x) #x
|
||||||
#define EXPAND_AND_STR(x) STR(x)
|
#define EXPAND_AND_STR(x) STR(x)
|
||||||
|
|||||||
Reference in New Issue
Block a user