conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Setting CFLAGS RELEASE correctly in profiles

Open maitrey opened this issue 2 years ago • 4 comments

Dear Conan Folks,

I have an issue that I use build_type Release in my profile, However it adds -O3 -DNDEBUG in CMakeCache.txt. Is it possible to set it correctly in profiles so that CMAKE_C_FLAGS_RELEASE doesnot use the default -O3 -DNDEBUG? CMakeCache.txt:CMAKE_C_FLAGS_RELEASE:STRING=-O3 -DNDEBUG Also this doesnot seem to work def generate(self): tc = CMakeToolchain(self) if self.settings.build_type == "Release": tc.preprocessor_definitions["CMAKE_C_FLAGS_RELEASE"] = "-O2"

maitrey avatar Sep 13 '22 11:09 maitrey

This doesn't seem a Conan issue, but a CMake issue, as -O3 is the CMake default for Release. Maybe this should be addressed directly in your CMakeLists.txt, and not injected by Conan, as Conan is not the one defining this flag.

If you still want to try it, the preprocessor_definitions is not the way to go, as those are not CMake variables but directly preprocessor definitions. You could try the cache_variables or variables, but also changing those is risky, because the optimization flag is not the only one, so you might be dropping other necessary variables, so I would still recommend trying a pure CMake solution.

memsharded avatar Sep 13 '22 13:09 memsharded

For the proof of concept with conan , can i Build wih build_type=None , will that work ? As right now we are still in the proof of concept stage

maitrey avatar Sep 13 '22 13:09 maitrey

For the proof of concept with conan , can i Build wih build_type=None , will that work ? As right now we are still in the proof of concept stage

No, most build systems need the build_type defined, definitely the CMake integration needs it.

memsharded avatar Sep 13 '22 13:09 memsharded

Ah ok , then cmake is the only way . Thanks for helping me out. Is it fine to use: set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS}") We still are not at the phase where we know if we could use conan for our use-cases. So for now, i do this in the CMakeLists.txt The other option would be to use Debug build type for all the packages so then we donot have this -O3 coming in.

maitrey avatar Sep 13 '22 13:09 maitrey

We are using debug builds as of now as we do not need -O3.

maitrey avatar Jan 30 '23 09:01 maitrey

This issue can be closed, no longer an issue.

maitrey avatar May 12 '23 11:05 maitrey