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 8079561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:08:42+00:00 2026-06-05T16:08:42+00:00

My project directory contains a CMakeLists.txt file and src and include directories at its

  • 0

My project directory contains a CMakeLists.txt file and src and include directories at its root. src also contains its own CMakeLists.txt, which is linked by the one at the root. Is there a way I can specify to CMake to set a default global build directory so that the syntax in src/CMakeLists.txt is close to the following?

include_directories(include)
add_executable(first main.cpp foo.cpp)
add_executable(second bar.cpp)

I would like this directory tree to be built:

CMakeLists.txt

src/
    CMakeLists.txt
    main.cpp
    foo.cpp
    bar.cpp

include/
    ...

bin/ (or build/)
    first
    second
  • 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-06-05T16:08:43+00:00Added an answer on June 5, 2026 at 4:08 pm

    You could set CMAKE_RUNTIME_OUTPUT_DIRECTORY:

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
    

    However, this won’t create subdirectories inside bin/ for each different target.

    If you want that, you could create a helper function to wrap add_subdirectories:

    function(my_add_executable TargetName)
      set(Files ${ARGV})
      list(REMOVE_AT Files 0)
      add_executable(${TargetName} ${Files})
      set_target_properties(${TargetName} PROPERTIES
                                RUNTIME_OUTPUT_DIRECTORY
                                    "${CMAKE_SOURCE_DIR}/bin/${TargetName}")
    endfunction()
    

    then simply change your calls to:

    my_add_executable(first main.cpp foo.cpp)
    my_add_executable(second bar.cpp)
    

    For further details, run

    cmake --help-variable "CMAKE_RUNTIME_OUTPUT_DIRECTORY"
    cmake --help-property "RUNTIME_OUTPUT_DIRECTORY"
    cmake --help-property "RUNTIME_OUTPUT_DIRECTORY_<CONFIG>"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a source directory structure: projectSource |---src |---include |---CMakeLists.txt and would like an
I have a project directory which has an .acignore file containing: out/* The project
I have the following directory structure. root --src ---tests src contains the source &
Suppose my project directory has 2 sub-directories A and B, A directory contains: A.h
Part of my project directory structure looks like: \projects\project\main.R \projects\project\src where \src contains a
I have a directory /media/fonts in my asp.net mvc project which contains fonts for
I've started a directory project in C#.NET where I'm editing an xml file and
I have a file named common.cs which contains commonly used functions like this public
I want to put path of different directory (which contains jars, presently on d:/ext_jars
I have a directory /sdcard/audio in the project. This directory contains some audio (wav)

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.