SFTtech / SFTtech/openage

Make use of more modern CMake features (cmake-compile-features e.g.)

Open
#1,259 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: buildsystem improvement
Dominant language
Python
Stars
14.4k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Compile feature requirements may be specified with the target_compile_features() command. For example, if a target must be compiled with compiler support for the cxx_constexpr feature:

add_library(mylib requires_constexpr.cpp)
target_compile_features(mylib PRIVATE cxx_constexpr)

In processing the requirement for the cxx_constexpr feature, cmake(1) will ensure that the in-use C++ compiler is capable of the feature, and will add any necessary flags such as -std=gnu++11 to the compile lines of C++ files in the mylib target. A FATAL_ERROR is issued if the compiler is not capable of the feature.

The exact compile flags and language standard are deliberately not part of the user interface for this use-case. CMake will compute the appropriate compile flags to use by considering the features specified for each target.

I our case we could use that to replace our buildsystem/CheckCompilerFeatures.cmake that is giving me some headache to get running with MingW ld.gold on Msys2 right now (was chosing lld now though).

I feel these compile features could make it much easier for us to let CMake decide if a compiler is able to compile our stuff if we name the features we need and let it chose the appropriate compile flags. Because this check that we do right now is not only testing if the compiler can compile something but also if the linker has the right flags (implicitly).

Which is good somehow, don't get me wrong. But we should be sure, before we compile that, that we have all the options figured out/have CMake figured it out for us.

https://cmake.org/cmake/help/v3.12/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
https://cmake.org/cmake/help/v3.12/manual/cmake-compile-features.7.html

Same for target_compile_definitions() if needed.

For example:

target_compile_features(libopenage
    PUBLIC
        cxx_variadic_templates
        cxx_nullptr
    PRIVATE
        cxx_lambdas
)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading buildsystem/CheckCompilerFeatures.cmake and the CMake targets that use it. Review CMake compile-feature documentation, then configure and build with the MinGW/MSYS2 setup described in the issue. Done means the required C++ features are expressed through CMake and the build continues to handle compiler and linker capability checks correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.