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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:18:41+00:00 2026-05-27T07:18:41+00:00

I am new to CMake and am having a problem with how the files

  • 0

I am new to CMake and am having a problem with how the files created by CMake are being organized.

First I will detail the file tree. I am trying to build a simple library with an example program from two source directories (Grid and examples) and a build directory. So, I have three CmakeLists.txt file. So, the top directory looks like this: CMakeLists.txt, /Grid, /examples, and /build.

This CMakeLists.txt contains:

project(talyfem)
cmake_minimum_required(VERSION 2.8.4)
set(CMAKE_CXX_FLAGS "-g")
add_subdirectory(examples Grid) 

Within the Grid folder CmakeLists.txt is:

add_library(${PROJECT_NAME} FEMElm.cpp Grid.cpp GridField.cpp SuperGrid.cpp SuperGrid3D.cpp)

Within the examples folder CmakeLists.txt is:

set(EXAMPLES example1)
foreach(example ${EXAMPLES})
   add_executable(${example} ${example}.cpp)
  target_link_libraries(${example} ${PROJECT_NAME})
endforeach(example)

I run CMake from the build directory as: Cmake ../
When I do this it creates a strange file structure that I can’t figure out and doesn’t seem correct. First, it creates a ../build/CMakeFiles folder, which is what I would expect. But, then it creates a ../build/Grid folder and within this folder is another CMakeFiles folder that then contains an example1.dir folder. If I switch the order of the sub-directories, which Grid first and examples second the opposite occurs with Grid.dir being inside a examples sub-directory.

This doesn’t seem correct and I would appreciate any assistance in fixing this problem.

I would expect that ../build/CMakeFiles should contain a Grid.dir and an examples.dir folder.

  • 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-27T07:18:42+00:00Added an answer on May 27, 2026 at 7:18 am

    The error is in the way you use add_subdirectory. From CMake Docs:

    add_subdirectory(source_dir [binary_dir]
    [EXCLUDE_FROM_ALL])

    So when you give add_subdirectory two arguments the first is interpreted as a source directory, and the second as the directory where this source should be built.

    What you want is to call add_subdirectory twice:

    add_subdirectory(examples)
    add_subdirectory(Grid)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to cmake and I'm trying to install .hpp files while preserving directory
I want to try CMake to manage a new C++ project. However, some files
When I invoke: File input = new File(cmake.tar.gz); TFile sourceFile = new TFile(input); TFile
I'm very new to CMake but have experience with general build environments like Make.
I'm new to cmake and have just started playing around with it. My problem
Totally new to Kubuntu and KDevelop. I created a new No GUI(CMake) Simple CMake-based
I quite new with CMake, but I have a problem with porting an existing
The problem I am having is a little hard to explain, but I will
I'm trying to build one of my CMake-based projects from a couple of years
How would one add support for a new IDE/build system to CMake? Does it

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.