i am working on a project and created a build system using cmake. I want to use optimization on the selected code c files. Could you please let me know how to achieve that . Please send an example how to achieve -Osize compile flag on my project c files.
If you’re using a single configuration generator, such as Unix Makefiles (which is the default on Linux and macOS) or Ninja, then you can pass -DCMAKE_BUILD_TYPE=MinSizeRel to cmake when configuring.
If you’re using a multi configuration generator, such as Visual Studio (which is the default on Windows) or Xcode, then you can select the MinSizeRel configuration at build time. For instance, you can pass --config MinSizeRel to cmake --build.
Sorry, I missed the part about applying this optimization flag only on certain files. To achieve that, you can use the function set_source_files_properties to set the COMPILE_OPTIONS property on given files.