Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JohelEGP/65cbb2ffdb815c8ebce22ae847ab76b1 to your computer and use it in GitHub Desktop.
Save JohelEGP/65cbb2ffdb815c8ebce22ae847ab76b1 to your computer and use it in GitHub Desktop.
How to portably build, test and install modern CMake projects

How to portably build, test and install modern CMake projects

These portable CMake commands build, test and install a project with a modern CMake buildsystem.

Commands

cmake -S <path-to-source> -B <path-to-build> # Generate the project's buildsystem in `<path-to-build>`.
cmake --build <path-to-build>                # Build the project from the generated buildsystem.
cmake -E chdir <path-to-build> ctest         # Test the built project.
cmake --install <path-to-build>              # Install the built project.

Older CMake versions

  • Before CMake 3.15, the last command has to be replaced with cmake --build <path-to-build> --target install.
  • Before CMake 3.13, the first command has to be replaced with:
    cmake -E make_directory <path-to-build>
    cmake -E chdir <path-to-build> cmake <path-to-source>

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment