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

  • Home
  • SEARCH
  • 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 8047205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:01:43+00:00 2026-06-05T06:01:43+00:00

The CMake documentation explicitly states that file(GLOB …) is not recommended to collect source

  • 0

The CMake documentation explicitly states that file(GLOB ...) is not
recommended to collect source files for a build, but it doesn’t
mention what the recommended method actually is.

Specifying every source file manually sounds a little bit too manually
to me. So, what is the right method to collect source files, if not
file(GLOB ...)?

  • 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-05T06:01:46+00:00Added an answer on June 5, 2026 at 6:01 am

    Manual is indeed the recommended method. By recommending against using GLOB, the documentation is simply warning against a build system that depends on files present. For example, you want to add a test executable, so you create mytest.cpp. Oops. Now your library compilation breaks. The documentation for AUX_SOURCE_DIRECTORY (similar purpose as globbing for for source files) gives the following warning:

    It is tempting to use this command to avoid writing the list of source
    files for a library or executable target. While this seems to work,
    there is no way for CMake to generate a build system that knows when a
    new source file has been added. Normally the generated build system
    knows when it needs to rerun CMake because the CMakeLists.txt file is
    modified to add a new source. When the source is just added to the
    directory without modifying this file, one would have to manually
    rerun CMake to generate a build system incorporating the new file.

    If you’re certain that you want all the contents of a directory, and don’t plan on adding new ones, then by all means use a GLOB.

    Also, don’t forget listing files manually doesn’t have to involve typing all the filenames. You could do, for example, ls *.cpp >> CMakeLists.txt, then use your editor to move the list of files to the correct place in the file.

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

Sidebar

Related Questions

CMake offers several ways to specify the source files for a target. One is
I use a cmake generated makefile to compile a c++ file that depends on
I am using cmake-gui trying to build opencv but get this error: CMake Error
I call CMake 2.8 from an empty bin directory to do an out-of-source build:
I have an AI template that was designed for this page but not sure
In CMake, I'm trying to build a project that includes libraries for multiple different
I want to try CMake to manage a new C++ project. However, some files
Possible Duplicate: cmake is not working in opencv c++ project I have a huge
I am using CMake to build my project and I have the following line:
I'm trying to add the item <key>UIStatusBarHidden</key><true/> to my plist that's auto-generated by CMake.

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.