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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:45:24+00:00 2026-06-09T18:45:24+00:00

There is some CMake magic I don’t understand. How should a CMakeLists.txt file look

  • 0

There is some CMake magic I don’t understand. How should a CMakeLists.txt file look like for a small C++ project with directories like this:

.
├── bin
└── src
    ├── src
    └── test

bin      — directory for built program
src/src  — directory for source
src/test — directory for tests

The tests will need to include files from src/src.
I’d like to manage all the operations from cmake, however at this moment I even can’t cause cmake to compile file in src/c.cpp.

Any help, links are welcome.

  • 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-09T18:45:25+00:00Added an answer on June 9, 2026 at 6:45 pm

    Your CMake files should reside in the main source directory and its sub-directories. The easiest approach is to have one CMakeLists.txt in the src directory, which includes all files from src/src and src/test. A very minimalistic example could look like the following:

    # CMakeLists.txt in src
    project(myExample)
    set(myExample_SOURCES
            src/file1.cpp
            src/main.cpp)
    add_executable(myExecutable ${myExample_SOURCES})
    
    set(myExample_test_SOURCES
            src/file1.cpp
            test/test_file2.cpp
            test/test_main.cpp)
    add_executable(myTestSuite ${myExample_test_SOURCES})
    

    The output directory is normally not specified, because you can have different active
    builds in parallel with
    different options, e.g. you can have one build in debug mode -O0 -g, another one in release mode with -O2 -g flags and a third one in release mode with heavy optimization flags -O3. Every build resides in its own directory (e.g. build-debug, build-rel,
    build-opt).

    You should create the output directory (bin in your case) manually and call the cmake command inside this directory. As an argument you have to supply the path to the main CMakeLists.txt. In other words, just execute

    cmake ../src
    

    when you are inside bin. This will take all files from the src directory and put the output to the bin directory.
    You can easily create a second output directory, say bin2, where you specify different build flags. The ccmake provides a very minimalistic GUI for that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there some crucial difference in writing the registry class in MVC with magic
I use some libraries that I don't want built as part of every project
There are some build systems that are able to generate platform specific project files
I have a c++ project in a unix environment, that has a CMakeLists.txt. I
I'm using CMake to generate a project file for Xcode 4.2 on OSX Lion,
I do have a simple cmake project (on linux) that loads some libraries from
I try to transfer into some CMake program and there is a function generating
Are there some good resources tutorials or anyone has tried to implement a Capcha
Is there some way to define an abstract type as a parameter in an
Is there some kind of software that I can feed uploaded images to and

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.