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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:36:03+00:00 2026-06-07T16:36:03+00:00

I use an out-of-tree builds with CMake. I have a CMake custom command that

  • 0

I use an out-of-tree builds with CMake.
I have a CMake custom command that generates *_pb2.py files from proto-files.
Since proto-files may reside in an unknown number of subdirectories (package namespace), like $SRC/package1/package2/file.proto, then the build directory will contain something like $BLD/package1/package2/file_pb2.py.

I want to implicitly make packages from auto-generated *_pb2.py files and, thus, I want to automagically generate __init__.py files in all subfolders ($BLD/package1, $BLD/package1/package2, etc.) and then install them.

How can I do that?

P.S. I’ve tried macro from CMake : How to get the name of all subdirectories of a directory? (changed GLOB to GLOB_RECURSE) but it returns only subdirs that contain files. I can’t get package1 subdir from example above.

  • 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-07T16:36:06+00:00Added an answer on June 7, 2026 at 4:36 pm

    The following should give you a list of directories as required in the variable AllPaths:

    # Get paths to all .py files (relative to build dir)
    file(GLOB_RECURSE SubDirs RELATIVE ${CMAKE_BINARY_DIR} "${CMAKE_BINARY_DIR}/*.py")
    # Clear the variable AllPaths ready to take the list of results
    set(AllPaths)
    foreach(SubDir ${SubDirs})
      # Strip the filename from the path
      get_filename_component(SubDir ${SubDir} PATH)
      # Change the path to a semi-colon separated list
      string(REPLACE "/" ";" PathParts ${SubDir})
      # Incrementally rebuild path, appending each partial path to list of results
      set(RebuiltPath ${CMAKE_BINARY_DIR})
      foreach(PathPart ${PathParts})
        set(RebuiltPath "${RebuiltPath}/${PathPart}")
        set(AllPaths ${AllPaths} ${RebuiltPath})
      endforeach()
    endforeach()
    # Remove duplicates
    list(REMOVE_DUPLICATES AllPaths)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use the out-of-fold predictions from a caret model to train a
I have started to try out to use the new Search API, the demo
Is there a ready-to-use C# interpreter out there, that is does not rely on
At the moment I'm trying to figure out how use default and custom settings
i use netbeans to check out projects from svn repo, then i edit the
I found out that I can use a different theme in an C# WPF
Is is possible to use MSBuild to make out-of-source builds: a build outside source
I have a master project that's using a fairly standard source tree approach +
I'm trying to use JavaCC to build a simple command line calculator that can
I have a javascript array of objects that I would like to use to

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.