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

Feature/add cmake workflow presets #20

Merged
merged 3 commits into from
Apr 4, 2024

Conversation

ClausKlein
Copy link
Contributor

@ClausKlein ClausKlein commented Feb 5, 2023

This simplifies building the project with CMake:

bash-3.2$ pwd
/Users/clausklein/Workspace/cpp/cpp_vcpkg_project
bash-3.2$ cmake --workflow --preset default
Executing workflow step 1 of 4: configure preset "default"

Preset CMake variables:

  BUILD_SHARED_LIBS="NO"
  CMAKE_BUILD_TYPE="Release"
  CMAKE_CXX_STANDARD="20"
  CMAKE_INSTALL_PREFIX:PATH="/Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install"
  CMAKE_PREFIX_PATH:STRING="/Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install"
  CMAKE_SKIP_INSTALL_RULES="NO"
  FEATURE_DOCS="NO"
  FEATURE_TESTS="NO"

Preset environment variables:

  CPM_SOURCE_CACHE="/Users/clausklein/.cache/CPM"
  CPM_USE_LOCAL_PACKAGES="YES"
  PATH="/Users/clausklein/.local/bin:/usr/local/opt/net-snmp/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/libexec/bin:/usr/local/opt/curl/bin:/usr/local/opt/libxml2/bin:/usr/local/opt/libxslt/bin:/usr/local/opt/expat/bin:/usr/local/opt/llvm/bin:/Users/clausklein/Library/Python/3.9/bin:/usr/local/opt/python/libexec/bin:/usr/local/opt/sqlite/bin:/usr/local/bin:/usr/local/sbin:/Users/clausklein/scripts:/Users/clausklein/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/usr/local/MacGPG2/bin:/opt/X11/bin:/Library/Apple/usr/bin"

-- vcpkg is already installed at /Users/clausklein/vcpkg.
-- Running vcpkg install
Detecting compiler hash for triplet x64-osx...
All requested packages are currently installed.
Restored 0 packages from /Users/clausklein/.cache/vcpkg/archives in 1.507 us. Use --debug to see more details.

Total elapsed time: 2.404 s

The package fmt provides CMake targets:

    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt)

    # Or use the header-only version
    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt-header-only)

-- Running vcpkg install - done
-- The default CMAKE_C_STANDARD used by external targets and tools is not set yet. Using the latest supported C standard that is 17
-- /usr/local/bin/ccache found and enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/build/user

Executing workflow step 2 of 4: build preset "default"

ninja: no work to do.

Executing workflow step 3 of 4: build preset "install"

[0/1] Install the project...
-- Install configuration: "Release"
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/.//include
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/.//include/my_lib
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/.//include/my_lib/lib.hpp
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/.//include
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/.//include/my_header_lib
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/.//include/my_header_lib/lib.hpp
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/bin/my_exe
-- Installing: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/lib/libmy_lib.a
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/share/cpp_vcpkg_project/cpp_vcpkg_projectConfigVersion.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/share/cpp_vcpkg_project/cpp_vcpkg_projectConfig.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/share/cpp_vcpkg_project/cpp_vcpkg_projectTargets.cmake
-- Up-to-date: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/share/cpp_vcpkg_project/cpp_vcpkg_projectTargets-release.cmake
-- Installing: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/install/share/cpp_vcpkg_project/usage
-- # The package cpp_vcpkg_project provides the following CMake targets:

    find_package(cpp_vcpkg_project CONFIG REQUIRED)
    target_link_libraries(main PRIVATE  cpp_vcpkg_project::my_exe cpp_vcpkg_project::my_lib cpp_vcpkg_project::my_header_lib cpp_vcpkg_project::project_options cpp_vcpkg_project::project_warnings)
  

Executing workflow step 4 of 4: package preset "default"

CPack: Create package using TGZ
CPack: Install projects
CPack: - Install project: cpp_vcpkg_project []
CPack: Create package
CPack: - package: /Users/clausklein/Workspace/cpp/cpp_vcpkg_project/build/user/cpp_vcpkg_project-0.0.1--Darwin-Release-AppleClang-14.0.0.14000029.tar.gz generated.
bash-3.2$ cmake --workflow --list-presets       
Available workflow presets:

  "default"
  "developer"
bash-3.2$ 

@ClausKlein ClausKlein force-pushed the feature/add-cmake-workflow-presets branch from d833d53 to 9f4961f Compare February 5, 2023 10:33
@ClausKlein ClausKlein force-pushed the feature/add-cmake-workflow-presets branch from dfe61b1 to d5a8ac3 Compare August 4, 2023 09:54
@ClausKlein ClausKlein marked this pull request as draft August 4, 2023 10:04
@ClausKlein ClausKlein marked this pull request as ready for review February 14, 2024 20:32
@ClausKlein ClausKlein force-pushed the feature/add-cmake-workflow-presets branch from 5cd794d to a8cfcdb Compare April 2, 2024 19:11
CMakeLists.txt Outdated Show resolved Hide resolved
my_exe/test/CMakeLists.txt Outdated Show resolved Hide resolved
.clang-tidy Outdated Show resolved Hide resolved
@aminya
Copy link
Owner

aminya commented Apr 2, 2024

The rest looks good to me. Thank you

Prevent use of CTest.cmake module

Update building documentation

If the project is used as subproject installation should be optional.

Split CMake Presets to host specific versions

clang-format cmake preset files too
@ClausKlein ClausKlein force-pushed the feature/add-cmake-workflow-presets branch from a8cfcdb to 5f81fc2 Compare April 3, 2024 17:36
@ClausKlein ClausKlein requested a review from aminya April 3, 2024 17:37
aminya
aminya previously approved these changes Apr 3, 2024
Copy link
Owner

@aminya aminya left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution. I'll test it some time this week on Windows to make sure it works there too

@ClausKlein
Copy link
Contributor Author

Thanks for your contribution. I'll test it some time this week on Windows to make sure it works there too

Note: It does NOT works with current release cmake version 3.29
see too https://discourse.cmake.org/t/error-4-9-invalid-include-field-in-cmake-preset/10554

@aminya
Copy link
Owner

aminya commented Apr 3, 2024

Thanks for your contribution. I'll test it some time this week on Windows to make sure it works there too

Note: It does NOT works with current release cmake version 3.29 see too discourse.cmake.org/t/error-4-9-invalid-include-field-in-cmake-preset/10554

Is there a workaround for this?

@ClausKlein
Copy link
Contributor Author

for current cmake version 3.28…3.29 see https://gitlab.kitware.com/cmake/cmake/-/issues/25654

@ClausKlein
Copy link
Contributor Author

Is there a workaround for this?

If you, want, I may change to include all presets files at ones for now?

@aminya
Copy link
Owner

aminya commented Apr 4, 2024

Perfect. Thanks for the fix

@aminya aminya merged commit 4c347c1 into aminya:main Apr 4, 2024
10 checks passed
This was referenced Apr 4, 2024
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.

2 participants