aminya / cpp_vcpkg_project

A production-ready C++ project made with vcpkg
https://github.com/aminya/project_options
The Unlicense
26 stars 5 forks source link

Feature/add cmake workflow presets #20

Closed ClausKlein closed 7 months ago

ClausKlein commented 1 year ago

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$ 
aminya commented 7 months ago

The rest looks good to me. Thank you

ClausKlein commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

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

ClausKlein commented 7 months ago

Is there a workaround for this?

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

aminya commented 7 months ago

Perfect. Thanks for the fix