I am following the basic tutorial by CMake https://cmake.org/cmake/help/v3.21/guide/tutorial/A%20Basic%20Starting%20Point.html
However, I want to run extra steps: moving the source codes files, output build and external lib into sub folders as below:
root/CMakeLists.txt
root/source/ => main.cpp and other cpp files
root/source/include/ => include header files
root/library => include library files for future use. In addition, I want to include some linux library such as pthread as well.
root/build/ => include output built binary
My CMakeList.txt so far:
cmake_minimum_required (VERSION 3.10)
project (Car VERSION 1.0)
#set build options or set C++ standard
set(CMAKE_CXX_STANDARD 11)
#set project binary folder:
SET(PROJECT_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build/)
#set project source folder:
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}/source/include/
)
#add executable target name (if project is built as executable)
add_executable(${PROJECT_NAME} main.cxx modelX.cxx upgrade.cxx usage.cxx)
#configure header files to pass the version number to the source code (must add target_include_directories to the end of CMakeLists.txt)
configure_file(car.h modelX.h upgrade.h Usage.h)
#set target build
target_include_directories(Car Public "${PROJECT_BINARY_DIR}")
Thank you !
p.s: I found similar questions here: Add Source in a subdirectory to a cmake project.
However, I still can't make use of both suggested answers and the one below it yet.