Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set cmake compile options based on language #7600

Merged
merged 14 commits into from Sep 1, 2020

Conversation

danimtb
Copy link
Member

@danimtb danimtb commented Aug 26, 2020

Changelog: Fix: Set CMake targets compile options based on language
Docs: omit

#tags: slow

  • Refer to the issue that supports this Pull Request: closes [bug] Cmake targets glue C and CXX flags #7499
  • If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
  • I've read the Contributing guide.
  • I've followed the PEP8 style guides for Python code.
  • I've opened another PR in the Conan docs repo to the develop branch, documenting this one.

Note: By default this PR will skip the slower tests and will use a limited set of python versions. Check here how to increase the testing level by writing some tags in the current PR body text.

@danimtb danimtb added this to the 1.29 milestone Aug 26, 2020
@danimtb danimtb self-assigned this Aug 26, 2020
Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Some tests that check generated CMake code are broken as expected.

@@ -96,7 +97,8 @@ class CMakeFindPackageGenerator(Generator):
set({{ pkg_name }}_{{ comp_name }}_RES_DIRS {{ comp.res_paths }})
set({{ pkg_name }}_{{ comp_name }}_DEFINITIONS {{ comp.defines }})
set({{ pkg_name }}_{{ comp_name }}_COMPILE_DEFINITIONS {{ comp.compile_definitions }})
set({{ pkg_name }}_{{ comp_name }}_COMPILE_OPTIONS_LIST "{{ comp.cxxflags_list }}" "{{ comp.cflags_list }}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this variable when using components, as this feature is marked as experimental

@@ -15,6 +15,8 @@
)
set({name}_COMPILE_DEFINITIONS{build_type_suffix} {deps.compile_definitions})
set({name}_COMPILE_OPTIONS{build_type_suffix}_LIST "{deps.cxxflags_list}" "{deps.cflags_list}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I kept the variable (although it is not used in targets) to avoid breaking

@@ -119,7 +127,8 @@ class CMakeFindPackageMultiGenerator(CMakeFindPackageGenerator):
set({{ pkg_name }}_{{ comp_name }}_RES_DIRS_{{ build_type }} {{ comp.res_paths }})
set({{ pkg_name }}_{{ comp_name }}_DEFINITIONS_{{ build_type }} {{ comp.defines }})
set({{ pkg_name }}_{{ comp_name }}_COMPILE_DEFINITIONS_{{ build_type }} {{ comp.compile_definitions }})
set({{ pkg_name }}_{{ comp_name }}_COMPILE_OPTIONS_LIST_{{ build_type }} "{{ comp.cxxflags_list }}" "{{ comp.cflags_list }}")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed variable in the components flavour

@@ -486,14 +487,6 @@ def build(self):
client.out)

def cpp_info_filename_test(self):
def add_to_conan_file(after, add_lines, spaces_to_indent):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed code not used

@danimtb
Copy link
Member Author

danimtb commented Aug 27, 2020

I see the following errors in Windows:

Error evaluating generator expression:

    $<COMPILE_LANGUAGE:C>

  $<COMPILE_LANGUAGE:...> may not be used with Visual Studio generators.

I think we cannot implement it this way 😞


See https://gitlab.kitware.com/cmake/cmake/-/issues/18582

@danimtb
Copy link
Member Author

danimtb commented Aug 28, 2020

After trying to continue with this using the project language as described here https://stackoverflow.com/questions/32389273/detect-project-language-in-cmake, implementing this feels hacky to me.

First, we would need to extract the information of the language to a new variable with get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) from the global scope.

Then, using a generator expression with IN_LIST requires CMake 3.3 as the minimum required version, while targets can be used since 3.1.2 version. However, I think you need to run CMake 3.12 at least to use it in generator expressions https://cmake.org/cmake/help/v3.12/manual/cmake-generator-expressions.7.html

To conclude, I am not sure if we should support this flag differentiation while creating the targets as CMake does not provide a feature supported in the main compilers. We can, however, expose the flags in variables without mixing them and let the consumers use that information in the way they want.

@danimtb danimtb marked this pull request as ready for review August 31, 2020 17:00
@danimtb danimtb assigned memsharded and unassigned danimtb Aug 31, 2020
@memsharded memsharded merged commit 372a66f into conan-io:develop Sep 1, 2020
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Cmake targets glue C and CXX flags
2 participants