I am having a very frustrating time trying to develop in C++ on the Apple laptop I got from work. If anyone can rescue me, I would be very grateful.
First, clang is present:
C02DF21YMD6T:~ xxx$ clang -v
Apple clang version 12.0.0 (clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Second: make is present:
C02DF21YMD6T:~ xxx$ make -v
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for i386-apple-darwin11.3.0
Third: cmake is present:
C02DF21YMD6T:~ xxx$ cmake --version
cmake version 3.19.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
So I downloaded and installed visual studio code, the C++ extension and the CMake Tools extension. I also installed vcpkg and sfml. All this worked without any problems. I installed vcpkg in the most obvious place: ~/vcpkg.
If I follow the instructions in the documentation of CMake Tools, I can build and run the simple hello world program that only uses the standard library. The example with sqlite3 also works. That is because sqlite3 doesn't have any dependencies itself. But if I try to use sfml, it fails because it doesn't link sfml's dependencies.
So if I followed this blog (https://ifexception.wordpress.com/2018/06/14/modern-cmake-file-for-sfml-with-vcpkg/):
I get this CMakeLists.txt
project (test_project)
find_package (SFML 2.5 COMPONENTS system, window, graphics REQUIRED)
find_program (CMAKE_MAKE_PROGRAM NAMES make make HINTS /usr/bin/make)
add_executable(test_project test.cpp)
target_compile_features (test_project PRIVATE cxx_std_20)
target_link_libraries(test_project PRIVATE sfml-graphics)
and this CMakeSettings.json
{
"configurations": [
{
"name": "x64-Debug",
"configurationType": "Debug",
"buildRoot": "${projectDir}/build/${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -v:minimal",
"variables": [
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "/Users/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
]
},
{
"name": "x64-Release",
"configurationType": "Release",
"buildRoot": "${projectDir}/build/${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "-m -v:minimal",
"variables": [
{
"name": "CMAKE_TOOLCHAIN_FILE",
"value": "/Users/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake"
}
]
}
]
}
Since cmake --help says that "Unix Makefiles" is the default generator on the platform, I leave it out. I assume that "Unix Makefiles" calls make to build the project.
If I do that, it still doesn't work. If I do CMake: Configure, it says:
[main] Configuring folder: test
[proc] Executing command: /usr/local/bin/cmake --no-warn-unused-cli "-DCMAKE_TOOLCHAIN_FILE:STRING=[vcpkg root]/scripts/buildsystems/vcpkg.cmake" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -H/Users/xxx/cppprojects/test -B/Users/xxx/cppprojects/test/build -G "Unix Makefiles"
[cmake] Not searching for unused variables given on the command line.
[cmake] CMake Error at /Applications/CMake.app/Contents/share/cmake-3.19/Modules/CMakeDetermineSystem.cmake:129 (message):
[cmake] Could not find toolchain file: [vcpkg
[cmake] root]/scripts/buildsystems/vcpkg.cmake
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:2 (project)
[cmake]
[cmake]
[cmake] CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
[cmake] -- Configuring incomplete, errors occurred!`
So, for some reason it can't find the toolchains file, even though it is spelled out where it is in the json file, and it can't find make even though it is on the path. Or it tries to call some other make tool but can't find it. It doesn't bother to report explicitly which tool it tries to call so it's difficult to be sure.
I tried to add set (ENV{VCPKG_ROOT} /Users/xxx/vcpkg) to the CMakeLists.txt (also without ENV) so that the var is defined but that doesn't make a difference.
Of course the toolchain file is actually where it should be:
C02DF21YMD6T:~ xxx$ ls /Users/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake
/Users/xxx/vcpkg/scripts/buildsystems/vcpkg.cmake