# Technical help required

**URL:** https://discourse.cmake.org/t/technical-help-required/2865
**Category:** Code
**Created:** [March 2, 2021, 6:49am UTC](https://discourse.cmake.org/t/technical-help-required/2865 "2021-03-02T06:49:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![SURAJ\_PATEL](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@SURAJ\_PATEL](https://discourse.cmake.org/u/SURAJ_PATEL)
#### Post date: [March 2, 2021, 6:49am UTC](https://discourse.cmake.org/t/technical-help-required/2865/1 "2021-03-02T06:49:56Z")

</div>

Hi Team,

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.

Regards  
Suraj patel

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [March 2, 2021, 7:07am UTC](https://discourse.cmake.org/t/technical-help-required/2865/2 "2021-03-02T07:07:53Z")

</div>

Hi,

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`.

I hope this helps!

---

<div class="post-metadata">

### Author: ![SURAJ\_PATEL](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@SURAJ\_PATEL](https://discourse.cmake.org/u/SURAJ_PATEL)
#### Post date: [March 2, 2021, 7:19am UTC](https://discourse.cmake.org/t/technical-help-required/2865/3 "2021-03-02T07:19:16Z")

</div>

Hi,

There are group of .c files in which i need to apply -Ogeneral or some other optimization. I am unable to figure it out how to do so.

Regards,  
Suraj

---

<div class="post-metadata">

### Author: ![McMartin](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mcmartin/32/150_2.png) [@McMartin](https://discourse.cmake.org/u/McMartin)
#### Post date: [March 2, 2021, 7:48am UTC](https://discourse.cmake.org/t/technical-help-required/2865/4 "2021-03-02T07:48:43Z")

</div>

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`](https://cmake.org/cmake/help/latest/command/set_source_files_properties.html) to set the [`COMPILE_OPTIONS` property](https://cmake.org/cmake/help/latest/prop_sf/COMPILE_OPTIONS.html) on given files.

---

<div class="post-metadata">

### Author: ![SURAJ\_PATEL](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/76d3ee/32.png) [@SURAJ\_PATEL](https://discourse.cmake.org/u/SURAJ_PATEL)
#### Post date: [March 2, 2021, 8:18am UTC](https://discourse.cmake.org/t/technical-help-required/2865/5 "2021-03-02T08:18:07Z")

</div>

I am getting an error

The example is as follows

Dir1\>  
Hello.c  
Hi.c  
Dir2\>  
Test1.c  
Test2.c

Now i want to apply optimization on hello.c and test1.c

The code snippet is as follows:

Set(c\_sources  
${cmake\_current\_source\_dir}/Dir1/hello.c  
${cmake\_current\_source\_dir}/Dir2/Test1.c

)

set\_source\_files(${c\_sources} PROPERTIES COMPILE\_OPTIONS -Ogeneral)

Could you please suggest why i am getting an error

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [March 2, 2021, 10:11am UTC](https://discourse.cmake.org/t/technical-help-required/2865/6 "2021-03-02T10:11:24Z")

</div>

> [@SURAJ\_PATEL](#):
>
> Could you please suggest why i am getting an error

And the error is…?

But if you’ve posted your code verbatim, then the error is here:

> [@SURAJ\_PATEL](#):
>
> ```
> set_source_files(${c_sources} PROPERTIES COMPILE_OPTIONS -Ogeneral)
> 
> ```

As Alain wrote above, the command is called `set_source_files_properties()`, not `set_source_files()`.

Side note: the variable `CMAKE_CURRENT_SOURCE_DIR` is spelled in all uppercase. CMake variable names are case-sensitive.
