If you really need to use a file (GLOB ...), this CMakeLists.txt should work:
cmake_minimum_required(VERSION 3.3)
project(bmi)
add_definitions("-Wall" "-g")
include_directories(${PROJECT_SOURCE_DIR})
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
add_executable(bmi ${SRC_FILES})
In this case, you should run cmake from the build directory every time you add or remove the source file:
cmake <your_source_dir> -G <your_build_generator>
As Phil recalls, the CMake documentation does not recommend the use of GLOB. But there are some exceptions. You will receive more information about this message.
, , GLOB:
set(SRC_FILES ${PROJECT_SOURCE_DIR}/main.cpp
${PROJECT_SOURCE_DIR}/bmi.cpp
… )
NB: #include .h .cpp , add_executable, include directory with include_directories.