Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7526305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:47:35+00:00 2026-05-30T03:47:35+00:00

I have a very simple directory structure: Project Project/src Project/build Source files are in

  • 0

I have a very simple directory structure:

Project
Project/src
Project/build

Source files are in Project/src, and I do the out-of-src build in Project/build. After running cmake ../ ; make, I can run the executable thusly: Project/build$ src/Executable – that is, the Executable is created in the build/src directory.

How do I set the location of the executable in the CMakeLists.txt file? I’ve attempted to follow some of the examples found at cmake.org, but the links that work don’t seem to show this behaviour.

My Project/src/CMakeLists.txt file is listed here.


include_directories(${SBSProject_SOURCE_DIR}/src)
link_directories(${SBSProject_BINARY_DIR}/src)

set ( SBSProject_SOURCES
    main.cpp
    )

add_executable( TIOBlobs ${SBSProject_SOURCES})

And the top-level Project/CMakeLists.txt:


cmake_minimum_required (VERSION 2.6)
project (SBSProject)

set (CMAKE_CXX_FLAGS "-g3 -Wall -O0") 

add_subdirectory(src)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T03:47:36+00:00Added an answer on May 30, 2026 at 3:47 am

    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})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory of very large XML files with a structure as this:
I'm trying to do something which is probably very simple, I have a directory
I have a very simple perl script that moves files (don't ask why i
I have a very simple setup project: <Product Id=* UpgradeCode=$(var.UpgradeCode) Name=$(var.ProductLongName) Language=1033 Version=$(var.ProductVersion) Manufacturer=$(var.Manufacturer)>
If I have a very simple http directory: default.html info.html contact.html etc... Should default.html
i have very simple problem. I need to create model, that represent element of
I have very simple select like this: SELECT * FROM table WHERE column1 IN
I have very simple window where I have 2 buttons - one for cancel,
I have a very simple problem which requires a very quick and simple solution
I have a very simple WPF application in which I am using data binding

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.