cmake-conan icon indicating copy to clipboard operation
cmake-conan copied to clipboard

what is the equivalent of `add_compile_options` in cmake

Open maidamai0 opened this issue 3 years ago • 4 comments
trafficstars

I want to set some compile flags when building a package and it can be done with add_compile_options in CMake. How should I do in conanfile.py. I've searched for a while but didn't get an answer. CONAN_CXX_FLAGS didn't work

maidamai0 avatar Dec 17 '21 01:12 maidamai0

The flag I want to add is /Zc:__cplusplus on MSVC

maidamai0 avatar Dec 17 '21 01:12 maidamai0

CUrrently I use self._cmake.definitions["CMAKE_CXX_FLAGS"] = "/EHsc /Zc:__cplusplus" but I don't know if this is a good idea.

maidamai0 avatar Dec 17 '21 01:12 maidamai0

Hi @maidamai0, Can you provide more information about your use case? Are you using cmake-conan to create a package or just for consuming other packages. If you are using cmake-conan as a consumer you should add those in the CMakeLists.txt directly using add_compile_options. In the case you re you creating a package and you want to use those flags when building, yes, you could add those flags to definitions using the self._cmake.definitions.

czoido avatar Dec 29 '21 16:12 czoido

Thank you @czoido I'm creating a package with conan. I'm concering if self._cmake.definitions["CMAKE_CXX_FLAGS"] = "/EHsc /Zc:__cplusplus" overrides the flags set before

maidamai0 avatar Dec 30 '21 05:12 maidamai0