shithub: rgbds

Download patch

ref: df27af6d1cce346c279e13a6a5995fb172e2e823
parent: fcfecc6e820e70c7fac0f7d2f786f294697f9715
parent: c85b48f23eba745ee961f96f4bbef16b40c58db3
author: Eldred Habert <eldredhabert0@gmail.com>
date: Sun Aug 16 18:12:47 EDT 2020

Merge pull request #553 from JL2210/cmake-develop

Add DEVELOP option to CMake

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,36 +6,24 @@
 # SPDX-License-Identifier: MIT
 #
 
-cmake_minimum_required(VERSION 2.8.8)
+cmake_minimum_required(VERSION 3.0)
+cmake_policy(VERSION 3.0)
 
-cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
+project(rgbds
+        LANGUAGES C)
 
-set(RGBDS_VER 0.4.1)
-set(RGBDS_DESC "Rednex Game Boy Development System")
+option(DEVELOP "build in development mode" OFF)
 
-if(CMAKE_VERSION VERSION_LESS 3.0)
-  project(rgbds C)
-  set(PROJECT_VERSION "${RGBDS_VER}")
-else()
-  if(CMAKE_VERSION VERSION_LESS 3.9)
-    project(rgbds VERSION "${RGBDS_VER}"
-                  LANGUAGES C)
+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()
-    project(rgbds VERSION "${RGBDS_VER}"
-                  DESCRIPTION "${RGBDS_DESC}"
-                  LANGUAGES C)
+    set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
   endif()
 endif()
 
-if(CMAKE_VERSION VERSION_LESS 3.9)
-  set(PROJECT_DESCRIPTION "${RGBDS_DESC}")
-endif()
-
-set(DEFAULT_BUILD_TYPE "Release")
-if(NOT CMAKE_BUILD_TYPE)
-  set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
-endif()
-
 # get real path of source and binary directories
 get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
 get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH)
@@ -53,10 +41,32 @@
 
 include_directories("${PROJECT_SOURCE_DIR}/include")
 
+if(DEVELOP)
+  add_definitions(-DDEVELOP)
+endif()
+
 if(MSVC)
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W1 /MP -D_CRT_SECURE_NO_WARNINGS")
+  add_compile_options(/W1 /MP)
+  add_definitions(/D_CRT_SECURE_NO_WARNINGS)
 else()
-  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic")
+  if(DEVELOP)
+    add_compile_options(-Werror -Wall -Wextra -pedantic
+                        -Wno-sign-compare -Wformat -Wformat-security -Wformat-overflow=2
+                        -Wformat-truncation=1 -Wformat-y2k -Wswitch-enum -Wunused
+                        -Wuninitialized -Wunknown-pragmas -Wstrict-overflow=5
+                        -Wstringop-overflow=4 -Walloc-zero -Wduplicated-cond
+                        -Wfloat-equal -Wshadow -Wcast-qual -Wcast-align -Wlogical-op
+                        -Wnested-externs -Wno-aggressive-loop-optimizations -Winline
+                        -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()
 
 # Use versioning consistent with Makefile
@@ -67,11 +77,7 @@
                 ERROR_QUIET)
 string(STRIP "${GIT_REV}" GIT_REV)
 
-if(CMAKE_VERSION VERSION_LESS 3.12)
-  add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}")
-else()
-  add_compile_definitions(BUILD_VERSION_STRING="${GIT_REV}")
-endif()
+add_definitions(-DBUILD_VERSION_STRING="${GIT_REV}")
 
 set(CMAKE_C_STANDARD 11)
 set(CMAKE_C_STANDARD_REQUIRED True)
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,23 +17,12 @@
              DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/asmy.h"
              )
 
-# Lexer is not present yet
-if(False) # FLEX_FOUND
-  FLEX_TARGET(Lexer "asm/lexer.l"
-              "${PROJECT_SOURCE_DIR}/src/asm/lexer.c"
-              )
-  ADD_FLEX_BISON_DEPENDENCY(Lexer ASMy)
-  set(Lexer_SOURCE "${FLEX_Lexer_OUTPUTS}")
-else()
-  set(Lexer_SOURCE "asm/lexer.c")
-endif()
-
 set(rgbasm_src
     "${BISON_ASMy_OUTPUT_SOURCE}"
-    "${Lexer_SOURCE}"
     "asm/charmap.c"
     "asm/fstack.c"
     "asm/globlex.c"
+    "asm/lexer.c"
     "asm/macro.c"
     "asm/main.c"
     "asm/math.c"
@@ -79,22 +68,12 @@
   install(TARGETS rgb${PROG} RUNTIME DESTINATION bin)
 endforeach()
 
-if(CMAKE_VERSION VERSION_LESS 2.8.12)
-  add_definitions(${PNG_DEFINITIONS})
-  include_directories(${PNG_INCLUDE_DIRS})
-  target_link_libraries(rgbgfx ${PNG_LIBRARIES})
-else()
-  target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS})
-  target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS})
-  target_link_libraries(rgbgfx PRIVATE ${PNG_LIBRARIES})
-endif()
+target_compile_definitions(rgbgfx PRIVATE ${PNG_DEFINITIONS})
+target_include_directories(rgbgfx PRIVATE ${PNG_INCLUDE_DIRS})
+target_link_libraries(rgbgfx PRIVATE ${PNG_LIBRARIES})
 
 include(CheckLibraryExists)
 check_library_exists("m" "sin" "" HAS_LIBM)
 if(HAS_LIBM)
-  if(CMAKE_VERSION VERSION_LESS 2.8.12)
-    target_link_libraries(rgbasm LINK_PRIVATE "m")
-  else()
-    target_link_libraries(rgbasm PRIVATE "m")
-  endif()
+  target_link_libraries(rgbasm PRIVATE "m")
 endif()