I am very new in cmake. I am trying to build a simple test project. This is my directory tree.
testproj
|---CMakeLists.txt
|
|---build (directory)
|
|---bin (directory)
|
|---include
| |---add.h
|
|---lib
| |---add.cxx
|
|---test
| |---main.cxx
After configuring and building, I want the static library *.a and the binary executable to go into bin/ subdirectory. So currently, my CmakeLists.txt looks like this.
CmakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(testproj)
set(CMAKE_CXX_STANDARD 20)
set(EXECUTABLE_OUTPUT_PATH "bin/")
set(LIBRARY_OUTPUT_PATH "bin/")
file(GLOB main_src "test/main.cxx")
file(GLOB lib_src "lib/*.cxx")
add_library(lib STATIC ${lib_src})
add_executable(main ${main_src})
target_link_libraries(main lib)
After building the project, the source directory looks like this.
testproj
|---CMakeCache.txt
|
|---CMakeFiles (directory)
|
|---CMakeLists.txt
|
|---Makefile
|
|---bin
| |---liblib.a
| |---main
|
|---build (directory)
|
|---cmake_install.cmake
|
|---compile_commands.json
|
|---include
| |---add.h
|
|---lib
| |---add.cxx
|
|---test
| |---main.cxx
Library *.a and binary executable main went into the bin/ subdirectory as expected. But, I want the following files and directories to go into the build/ subdirectory everytime I build the project:
CMakeCache.txt, CMakeFiles, Makefile, cmake_install.cmake, compile_commands.json
How can I achieve this in CMakeLists.txt? I don't want to do
cd build
cmake ..
make
EDIT: I configure from the testproj directory. I don't want to cd into the build/ subdirectory.