Reputation: 664
My problem is when I run $ cmake /path/to/source/
the resulting files and directories are split between the directory I'm calling from and /path/to/source/include.
Here is my CMake project:
File structure:
root:
|-CMakeLists.txt
|-src
| |-CMakeLists.txt
| |-"source files"
|-include # This is where part of the generated files are ending up.
| |-CMakeLists.txt
| |-"include files"
Here are my CMakeLists.txt's:
root/CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(DUCKSIM)
# Add the root directory for the CMakeLists.txt being called. This is necessary for
# out-of-tree builds.
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# Add the directories containing source and header files.
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/include)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY $(pwd)) # This is an attempt to fix my problem
src/CMakeLists.txt:
# set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Set DUCKSIM_SOURCES as all .cpp files
file(GLOB DUCKSIM_SOURCES *.cpp)
# Set the name of the executable as "ducksim" and link it with main.cpp
# and every thing in the DUCKSIM_SOURCES variable.
add_executable(ducksim main.cpp ${DUCKSIM_SOURCES})
include/CMakeLists.txt:
# set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Set DUCKSIM_SOURCES as all .h files
file(GLOB DUCKSIM_SOURCES *.h)
Upvotes: 2
Views: 1467
Reputation: 368
Command add_subdirectory()
will optionally accept a second path as a parameter, but that will indicate the binary directory, as indicated in the documentation. By giving your include
folder as the second parameter, CMake assumes that you want the binaries to go there. That's why you end up with some files at the top level (CMakeCache.txt, etc.) and some files in the include
folder.
For the record, using file(GLOB ...)
is not recommended for collecting source files to compile. If you add a source file, no CMake file will have changed, and the build system won't regenerate.
Finally, you shouldn't need the file(GLOB ...)
for the header files, but you probably need an include_directories()
call for the include
folder.
Upvotes: 1