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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:38:42+00:00 2026-05-13T16:38:42+00:00

I have 3 small dependent tools: main-tool/ tool1/ tool2/ * —– main-tool —– *

  • 0

I have 3 small dependent tools:

main-tool/
    tool1/
    tool2/ 

       * ----- main-tool ----- *
       |                       |
      tool1   ---------- >    tool2

The main-tool depends on tool1 & tool2.
The tool1 depends on tool2.
The CMakeFiles look like that:

main-tool/CMakeLists.txt
   SUBDIRS{"tool1"}
   SUBDIRS{"tool2"}

main-tool/tool1/CMakeLists.txt
   SUBDIRS("../tool2"}

I can compile tool1 smoothly. However whenever I want to compile main-tool the tool2 is included twice and produces error. How can I avoid this?

Thanks.

  • 1 1 Answer
  • 1 View
  • 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-13T16:38:43+00:00Added an answer on May 13, 2026 at 4:38 pm

    First off, you should use add_subdirectory() instead of subdirs(), which is deprecated. You get more precise control of the order of processing that way.

    Second, because everything depends on tool2, you should build tool2 first.

    main-tool/CMakeLists.txt:
       add_subdirectory{"tool2"}
       add_subdirectory{"tool1"}
    

    Don’t add another add_subdirectory command in the tool1 directory. There are two approaches you can use to access tool2 from the tool1 build.

    1. First, you could define some cmake variables in the top level main CMakeLists.txt related to tool2, then populate those variables in the tool2 build. You might need to use the PARENT_SCOPE directive to set those variables from the tool2 subdirectory. Then use those variables to access tool2 from the tool1 subdirectory.
    2. Alternatively, you could build all three tools (tool2, tool1, and main tool, in that order) from the top level CMakeLists file. The build file can get long, but it saves headaches trying to manage the scope of cmake variables. This is the approach I usually take and I recommend it.

    To summarize, my recommendation is “one big CMakeLists.txt file”. Unless it gets really, really big.

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.