Skip to content

Commit

Permalink
cmake: Use same default optimization level as Makefiles.
Browse files Browse the repository at this point in the history
Support overriding optimization level in COMMON_OPT, CCOMMON_OPT, and FCOMMON_OPT.
  • Loading branch information
mmuetzel committed Aug 30, 2022
1 parent 0053452 commit 7db2983
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,36 @@ if(MSVC AND MSVC_STATIC_CRT)
endforeach()
endif()

# Set default optimization level
if (NOT MSVC)
# Filter out cmake's default optimization level from release and debug flags.
# They would override any optimization level set in COMMON_OPTs
set(CompilerLangs
CXX
C
Fortran
ASM
)
foreach(CompilerLang ${CompilerLangs})
string(REGEX REPLACE "-O[0-9]|-Ofast|-Og|-Os"
"" CMAKE_${CompilerLang}_FLAGS_RELEASE
"${CMAKE_${CompilerLang}_FLAGS_RELEASE}")
string(REGEX REPLACE "-O[0-9]|-Ofast|-Og|-Os"
"" CMAKE_${CompilerLang}_FLAGS_DEDUG
"${CMAKE_${CompilerLang}_FLAGS_DEDUG}")
endforeach()
# Prepend default optimization level to COMMON_OPTs
if (CMAKE_BUILD_TYPE EQUAL "DEBUG")
set(COMMON_OPT "-Og ${COMMON_OPT}")
set(CCOMMON_OPT "-Og ${CCOMMON_OPT}")
set(FCOMMON_OPT "-Og ${FCOMMON_OPT}")
else ()
set(COMMON_OPT "-O2 ${COMMON_OPT}")
set(CCOMMON_OPT "-O2 ${CCOMMON_OPT}")
set(FCOMMON_OPT "-O2 ${FCOMMON_OPT}")
endif ()
endif ()

message(WARNING "CMake support is experimental. It does not yet support all build options and may not produce the same Makefiles that OpenBLAS ships with.")

include("${PROJECT_SOURCE_DIR}/cmake/utils.cmake")
Expand Down

0 comments on commit 7db2983

Please sign in to comment.