I am working on a C project which I converted from MATLAB using MATLAB Coder. I made a lot of changes to optimize the C code since it was pretty slow after the translation. In order to further increase the execution speed of the program, I tried to add compiler optimization flag in the CMakeLists, which significantly reduced the execution time, but at the same time making the program crash which was most likely to happen as explained here https://stackoverflow.com/a/7857672/9302627. To make sure what was going on, I ran the optimized code in Clion which I am using for my project, and found out that a lot of variable got their values changed and hence the logic of the program was being affected.
I know that my function "ZCNET_detec_pkt.c" is the one that takes the most amount of time because it contains the main algorithm of my project and I am trying to optimize it. At this moment, I plan to optimize one source file at a time so that it will be easy to debug.
I went through some blogs to learn "How to optimize a single source file in Cmake" but so for nothing is working.
I tried to use #pragma optimize
as mentioned in this blog, https://stackoverflow.com/a/44978687/9302627 but that didn't work.
I tried to add the optimization flag using set_source_files_properties
but that didn't work. It is possible that I might be doing it wrong but I am not experienced with Cmake so I am still learning.
The CMakeLists.txt that I am using was generated by Clion looks something like this at this moment.
cmake_minimum_required(VERSION 3.10)
project(zc_dec C)
set(CMAKE_C_STANDARD 11)
add_executable(zc_dec
abs.c
abs.h
bin2dec.c
bin2dec.h
circshift.c
circshift.h
.
.
.
. )
set_source_files_properties(ZCNET_detec_pkt.c CMAKE_C_FLAGS "-O3")
target_sources(zc_dec PRIVATE
ZCNET_detec_pkt.c
ZCNET_detec_pkt.h)
target_link_libraries(zc_dec m -lfftw3 -lm)
I am trying figure out how to can add compiler optimization flag for one specific source file at a time. Any Help is appreciated. Thank you