Skip to content

Commit

Permalink
Add check whether compiler supports -fdata-sections/-ffunction-sections
Browse files Browse the repository at this point in the history
  • Loading branch information
th-otto authored and OmniBlade committed Jun 12, 2024
1 parent ecf1f36 commit 1a69a73
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.10)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
include(FeatureSummary)
include(CheckCXXCompilerFlag)

if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)
Expand Down Expand Up @@ -82,6 +83,24 @@ if(NOT MSVC)
set(CMAKE_FIND_FRAMEWORK "LAST")
endif()

message(STATUS "Checking whether compiler supports -fdata-sections")
check_cxx_compiler_flag("-Werror -fdata-sections" HAVE_DATA_SECTIONS)
if(HAVE_DATA_SECTIONS)
message(STATUS "yes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdata-sections")
else()
message(STATUS "no")
endif()

message(STATUS "Checking whether compiler supports -ffunction-sections")
check_cxx_compiler_flag("-Werror -ffunction-sections" HAVE_FUNCTION_SECTIONS)
if(HAVE_FUNCTION_SECTIONS)
message(STATUS "yes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections")
else()
message(STATUS "no")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -Wwrite-strings -Werror=write-strings -fcheck-new -fsigned-char -fdata-sections -ffunction-sections -DNOMINMAX")
else()
set(CMAKE_CXX_FLAGS "/Zc:strictStrings")
Expand Down

0 comments on commit 1a69a73

Please sign in to comment.