Ask Your Question
4

How can I turn off or change the optimization setting for a particular function in cmake?

asked 2023-02-27 11:00:00 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-01-01 11:00:00 +0000

plato gravatar image

CMake provides several ways to turn off or change the optimization setting for a particular function:

  1. Using the set_property function: The set_property function can be used to set the COMPILE_OPTIONS property for a particular target or source file. For example, to turn off optimization for a specific source file, you can use the following command:
set_property(SOURCE <source_file> PROPERTY COMPILE_OPTIONS "-O0")

This will set the -O0 option for the specified source file.

  1. Using the targetcompileoptions function: The target_compile_options function can be used to set compile options for a particular target. For example, to turn off optimization for a specific target, you can use the following command:
target_compile_options(<target_name> PRIVATE "-O0")

This will set the -O0 option for the specified target.

  1. Using the cmakeminimumrequired function: You can use the cmake_minimum_required function to set the minimum CMake version required for your project. By setting the minimum required version to a lower value, you can disable certain optimizations that are turned on by default in newer versions. For example, to disable -O2 optimization, you can use:
cmake_minimum_required(VERSION 3.0)

This will set the minimum required CMake version to 3.0, which does not enable the -O2 optimization by default.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-02-27 11:00:00 +0000

Seen: 9 times

Last updated: Jan 01 '22