With GCC or Clang, add the following to your CMakeLists.txt:

target_compile_options(<executable_name> PRIVATE -Wall -Wextra -Wpedantic)

For non-CMake projects, add the following to your Makefile:

CXXFLAGS += -Wall -Wextra -Wpedantic

These options enable warnings; they do not turn warnings into errors. Add -Werror if that is the policy you want for your build.