diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f214f2..5de3a5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,12 @@ set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix) message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}") message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") -set(CMAKE_EXE_LINKER_FLAGS "-static") +option(BUILD_STATIC "build output executable using static library") +if(BUILD_STATIC) + message(STATUS "Build with static library") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") + set(CMAKE_EXE_LINKER_FLAGS "-static") +endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -17,8 +20,23 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # project name project(dino LANGUAGES CXX C) -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE) +if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") + message(STATUS "Maximum optimization for speed") + add_compile_options(-Ofast) +elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo") + message(STATUS "Maximum optimization for speed, debug info included") + add_compile_options(-Ofast -g) +elseif("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel") + message(STATUS "Maximum optimization for size") + add_compile_options(-s -Os -ffunction-sections -fdata-sections -Wl,--gc-section) + add_compile_options(-fsanitize-address-outline-instrumentation) +else() + message(STATUS "Minimal optimization, debug info included") + add_compile_options( + -Wall # print warning info + -Wextra # print extra warning info + ) + add_compile_options(-Og -g) endif() add_definitions(-DLGFX_SDL) @@ -43,8 +61,7 @@ target_include_directories( ${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/simulator - ${CMAKE_CURRENT_SOURCE_DIR}/library/LovyanGFX/src - ) + ${CMAKE_CURRENT_SOURCE_DIR}/library/LovyanGFX/src) set(SDL2_LIB_PATH "$ENV{HOME}/SDL2-2.28.5/x86_64-w64-mingw32/lib") target_include_directories(${PROJECT_NAME} PUBLIC "$ENV{HOME}/SDL2-2.28.5/x86_64-w64-mingw32/include" library/mingw_stdthreads)