CMake executable location

You have a couple of choices.

To change the default location of executables, set CMAKE_RUNTIME_OUTPUT_DIRECTORY to the desired location. For example, if you add

set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

to your Project/CMakeLists.txt before the add_subdirectory command, your executable will end up in Project/build for Unix builds or build/<config type> for Win32 builds. For further details, run:

cmake --help-property RUNTIME_OUTPUT_DIRECTORY

Another option for a project of this size is to have just one CMakeLists.txt. You could more or less replace add_subdirectory(src) with the contents of Project/src/CMakeLists.txt to achieve the same output paths.

However, there are a couple of further issues.

You probably want to avoid using link_directories generally. For an explanation, run

cmake --help-command link_directories

Even if you do use link_directories, it's unlikely that any libraries will be found in ${SBSProject_BINARY_DIR}/src

Another issue is that the CMAKE_CXX_FLAGS apply to Unix builds, so should probably be wrapped in an if (UNIX) ... endif() block. Of course, if you're not planning on building on anything other than Unix, this is a non-issue.

Finally, I'd recommend requiring CMake 2.8 as a minimum unless you have to use 2.6 - CMake is an actively-developed project and the current version has many significant improvements over 2.6

So a single replacement for Project/CMakeLists.txt could look like:

cmake_minimum_required (VERSION 2.8)
project (SBSProject)

if (UNIX)
  set (CMAKE_CXX_FLAGS "-g3 -Wall -O0")
endif ()

include_directories (${SBSProject_SOURCE_DIR}/src)

set (SBSProject_SOURCES
    ${SBSProject_SOURCE_DIR}/src/main.cpp
    )

add_executable (TIOBlobs ${SBSProject_SOURCES})

Another way of relocating the executable file location is via set(EXECUTABLE_OUTPUT_PATH Dir_where_executable_program_is_located)


build/'config type' for Win32 builds.

For MSVC, to avoid the default "/Debug" created folder

set_target_properties(my_target
PROPERTIES 
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR})

Tags:

Cmake