Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Allow specifying optimization level in COMMON_OPT #3748

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,41 @@ if(MSVC AND MSVC_STATIC_CRT)
endforeach()
endif()

# Set default optimization level
if (NOT MSVC)
# Check if user specified optimization level in COMMON_OPT flags.
string(REGEX MATCH "-O[0-9]|-Ofast|-Og|-Os" OPENBLAS_COMMON_OPT_OFLAGS
"${COMMON_OPT} ${CCOMMON_OPT} ${FCOMMON_OPT}")

string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE)
if (NOT "${OPENBLAS_COMMON_OPT_OFLAGS}" STREQUAL "")
# Filter out optimization level from cmake's default flags.
# They would override the optimization level set in COMMON_OPTs.
set(CompilerLangs
C
CXX
Fortran
ASM
)
foreach(CompilerLang ${CompilerLangs})
string(REGEX REPLACE "-O[0-9]|-Ofast|-Og|-Os" ""
CMAKE_${CompilerLang}_FLAGS_${CMAKE_BUILD_TYPE}
"${CMAKE_${CompilerLang}_FLAGS_${CMAKE_BUILD_TYPE}}")
endforeach()
endif ()
# Prepend default optimization level to COMMON_OPTs.
# These flags might be overridden by cmake's default flags.
if ("${CMAKE_BUILD_TYPE}" STREQUAL "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