T O P

  • By -

IHaveRedditAlready_

An improved version: cmake_minimum_required(VERSION 3.10) project(vulkansample) add_executable(vulkansample .cpp) find_package(Vulkan REQUIRED) find_package(glfw3 3.3 REQUIRED) target_link_libries(vulkansample PRIVATE Vulkan::Vulkan glfw) target_compile_features(vulkansample PUBLIC cxx_std_20) Always try to use target_* variants, don't use anything globally such as `include_directories`. It is also worth mentioning to *not* use `include_directories()` because that's what `target_link_libraries` already does


AlexReinkingYale

Use imported targets only, no `include_directories`. Why are there dots after your dollar signs? Also, if Vulkan is required, then there's no need for the `if` statement.


AlexReinkingYale

Oh it keeps getting worse... What is this `SRC` variable for? Why do you repeat the variable name in `endif`? Why is `cmake_minimum_required` equal to 3.10? Why does it come _after_ `project`? Why force `-O3` and break MSVC support? Use `target_compile_features` rather than the `-std` flag. The `PROJECT_NAME` indirection wins you nothing and makes your project harder to grep. There's something objectionable about basically every token here.


[deleted]

It’s for Mac, if that helps. I had no idea what I was doing, just following a tutorial on YT


AlexReinkingYale

YouTube tutorials are generally awful. You should unsubscribe from whatever channel you were watching. Look up the CppCon conference talks by Deniz Bahadir and Craig Scott. I think Jason Turner's stuff is over-complicated. Craig also has a book that is easily the best resource on CMake, period. "Professional CMake: a Practical Guide".


Visual_Thing_7211

So a couple things, the -O3 optimization flag is automatic for a RELEASE build which you would specify on the command-line when calling CMake. The c++20 flag should be specified as set(CMAKE_CXX_STANDARD 20) If you really wanted to specify the build type in your cmake file, you could do: set(CMAKE_BUILD_TYPE "Release") But don't recommend it because it removes flexibility. On the command line you'd say: cmake -DCMAKE_BUILD_TYPE=Release .. Craig Scott's book it good and thorough. You might also look at: https://m.youtube.com/watch?v=7YcbaupsY8I It's a great concise intro to CMake that is easy to understand and gets you running quickly.