I am learning c++ and cmake at the moment. I have my source files in the main directory where CMakeLists.txt
is located. I want to store all source files in a /src directory, but i have no idea how to locate them in CMake.
My CMake File
cmake_minimum_required(VERSION 2.8)
project(game)
set(GAME_ALL_SOURCES
main.cpp check.cpp
)
add_executable(game ${GAME_ALL_SOURCES})
target_link_libraries(game sfml-graphics sfml-window sfml-system)
Anyone a suggestion how to handle it?
best regards
cmake is searched first in CMAKE_MODULE_PATH , then in the CMake module directory. There is one exception to this: if the file which calls include() is located itself in the CMake builtin module directory, then first the CMake builtin module directory is searched and CMAKE_MODULE_PATH afterwards.
The source directory is where the source code for the project is located. This is also where the CMakeLists files will be found. The binary directory is sometimes referred to as the build directory and is where CMake will put the resulting object files, libraries, and executables.
The CMakeLists. txt file is at the top directory of the ROOT git repository.
Add a subdirectory to the build. Adds a subdirectory to the build. The source_dir specifies the directory in which the source CMakeLists.
If you want to locate all .cpp
files in the src
directory, you could do
file(GLOB SOURCES src/*.cpp)
and use ${SOURCES}
wherever you need to. For example:
add_executable(game ${SOURCES})
Try
set(GAME_ALL_SOURCES
src/main.cpp src/check.cpp
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With