2

I'm using CMake in a project of mine, and I would like to use a different set of optimization flags for each file. Some files contain code that I would like to optimize for space and others I would like to optimize for performance.

Is there anyway to do this using CMake? The only way I can currently imagine is using this:

set_property(SOURCE ${PROJECT_SOURCE_DIR}/src/bitmap.c APPEND_STRING COMPILE_FLAGS "/Wall /WX /O1") 

I know there's ways to set the optimization flags for specific files, but will building in release or debug mode have an effect on this? I want to make sure I'm doing this in a way that isn't just some hack, otherwise I might just revert back to Make.

1 Answer 1

1

You can use the set_source_file_properties command. Take a look at all the properties available for source files and you will notice a COMPILE_DEFINITIONS and COMPILE_FLAGS property.

Sign up to request clarification or add additional context in comments.

2 Comments

But if you do set a build-type, you can check for that with CMAKE_BUILD_TYPE
This is an important caveat. One should set CMAKE_BUILD_TYPE to the empty string to avoid accidentally having compile options added.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.