[ad_1]
The earlier weblog posts on this sequence have been about 1) a simplistic use of vcpkg from cmake and a couple of) somewhat extra subtle use of vcpkg with cmake. The examples work for each Linux and Home windows environments.
Recap
The next is a barebones C++ cmake mission hunter_test
hunter_test ├── CMakeLists.txt ├── embody │ └── driver.h ├── src │ └── driver.cpp └── take a look at └── driver_test.cpp 3 directories, 4 recordsdata
The driver.cpp
and driver_test.cpp
recordsdata have only a fundamental perform that does nothing. driver.h
is empty. The CMakeLists.txt
seems as follows.
cmake_minimum_required (VERSION 3.12) mission (vcpkg_test CXX) set(CMAKE_CXX_STANDARD 17) add_executable(driver src/driver.cpp) target_include_directories(driver PUBLIC ${PROJECT_SOURCE_DIR}/embody) target_link_libraries(driver ${Boost_LIBRARIES}) enable_testing() embody(CTest) add_executable(driver_test ${PROJECT_SOURCE_DIR}/take a look at/driver_test.cpp) add_test(NAME driver COMMAND driver_test)
The CMakeLists.txt
to date is impartial of any package deal managers. Now, we’ll begin utilizing Hunter.
Including Hunter Bundle Supervisor to Your Cmake Challenge
This step is ridiculously easy. Hunter documentation supplies step-by-step directions. I actually admire that.
embody("cmake/HunterGate.cmake") HunterGate(URL "https://github.com/ruslo/hunter/archive/v0.23.165.tar.gz" SHA1 "5a73f91df5f6109c0bb1104d0c0ee423f7bece79") mission (hunter_test CXX) hunter_add_package(Increase COMPONENTS filesystem) find_package(Increase 1.67 CONFIG REQUIRED COMPONENTS filesystem)
Be aware that a further cmake file HunterGate.cmake
is added to the mission. It lives below the cmake
listing. It is the entry-point for Hunter. Together with that file in our CMakeLists.txt
permits us to name
HunterGate
with a tar-ball for downloading the Hunter launch. Yow will discover the most recent launch URL and
SHA1 below ruslo/Hunter github releases.
That is all that is wanted to jumpstart the mission in Linux surroundings. Invoking cmake -B construct
triggers Hunter in motion. It downloads the required dependency sources and compiles them for you below $HOME/.hunter
. So long as the code’s embody directives are following the most effective practices, the code will construct easily. Particularly, I am speaking in regards to the following two strains. Be aware the enhance prefix.
#embody "enhance/core/demangle.hpp" #embody "enhance/filesystem.hpp"
Hunter in Visible Studio 2019
There are two methods you should use Visible Studio with Hunter.
First, open the CMakeLists.txt
in hunter_test in VS by way of File–>Open–>CMake…–>Choose CMakeList.txt. This works however there is a caveat. The output of cmake is just not redirected to the VS Construct Output window instantly. The truth is, it might take a number of minutes (and even hours). Clearly, it seems like VS is caught. Within the hunter_test mission above with boost-core, boost-optional, and boost-filesystem dependencies, took about 21 minutes on my VM to complete the cmake era step. This subject is tracked on the VS Developer Group.
Recall that Hunter downloads dependency sources and builds them below the listing pointed by $HUNTER_ROOT
. In my take a look at runs, no output for this course of was captured by Visible Studio. If Hunter fails to obtain and compile the sources for some dependencies, you may see some output.
I realized later that verbose cmake output might be enabled in Visible Studio. I discovered the output to be additional verbose resulting from %VSCMD_DEBUG% == 5.
Traditional Visible Studio Answer Generator
A substitute for Visible Studio’s built-in cmake assist is to make use of the traditional resolution file generator in cmake: cmake -B construct
. The generated resolution file has the traditional format of assorted targets together with ALL_BUILD, RUN_TESTS, ZERO_CHECK, and the principle targets driver and driver_test. It builds effective. The checks run file. This is the output of producing the construct recordsdata.
Conclusion
Visible Studio CMake integration works for Hunter-based initiatives. It has a couple of tough edges although. For now, you might be higher off utilizing cmake’s native mission era for now quite than Visible Studio’s “Open CMake Challenge” characteristic. You possibly can nonetheless use the characteristic however keep in mind that if one in all your colleagues updates the HunterGate URL and SHA1 and in case you open the mission utilizing the “Open CMake Challenge” characteristic, you may need to attend minutes to hours relying upon the variety of dependencies rebuilt.
[ad_2]