Skip to content

Commit

Permalink
Add OPTIMIZE option
Browse files Browse the repository at this point in the history
- By default, build with -O3
- If user specifies -DOPTIMIZE=<N>, build with -O<N>
- If user specifies -DOPTIMIZE=DEFAULT, don't touch -O
  • Loading branch information
gavv committed Nov 27, 2022
1 parent 8efeda2 commit 65bd0cb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,14 @@ message(STATUS "Debug mode ON" )
else(DEBUG STREQUAL "ON")
# Release mode
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_C_FLAGS "-O4")
set(OPTIMIZE "3" CACHE STRING "Set optimization level (0-3 or DEFAULT)")
if (NOT OPTIMIZE STREQUAL "DEFAULT")
string(REGEX REPLACE "(-O[A-Za-z0-9]+)" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "(-O[A-Za-z0-9]+)" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O${OPTIMIZE}")
endif()
message(STATUS "Debug mode OFF")
message(STATUS "Optimization level ${OPTIMIZE}")

endif (DEBUG STREQUAL "ON")

Expand Down

0 comments on commit 65bd0cb

Please sign in to comment.