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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:12:26+00:00 2026-06-16T16:12:26+00:00

I use CMake to create build scripts (Makefiles + VS solutions) for my projects.

  • 0

I use CMake to create build scripts (Makefiles + VS solutions) for my projects. As best practice I create the build scripts in a separate folder (out of source). I build the projects in the same folder.

This works fine for compiled programs but I can’t find an adequate solution for my Python scripts as these have no build step that would copy (build) them to the build folder.

Looking for creative solutions….

Requirements:

  • All executables should be available in the build folder post build (I consider *.py files to be executable
  • Python scripts should be easily managed using an IDE (spyder, eclipse, etc)
  • Source folder with python scripts is in Git repository. Build folder is not.
  • C++ compiled python modules should reside next to relevant python scripts

So far I considered two options:

  • Copy scripts to build folder when running CMake – Need to run CMake for every change in python files (IDE unfriendly). Can cause confusion: which copy of the sources to edit?
  • Create links to source folder in build folder – Multi platform mess. Problem deploying compiled c++ python modules next to the scripts without polluting source folder.

I hope this is clear enough.

  • 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-16T16:12:27+00:00Added an answer on June 16, 2026 at 4:12 pm

    Eventually I found a solution which involves creating symbolic links to the python sources and other related files that are not compiled but are necessary in the build environment. To allow mixing built modules with the symbolic links I used real folders instead of symbolic links.

    This way:

    • There is one copy of the python scripts
    • It can be run/edited seamlessly from the binary folder

    Utility function:

    function (create_symlinks)
        # Do nothing if building in-source
        if (${CMAKE_CURRENT_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
            return()
        endif()
    
        foreach (path_file ${ARGN})
            get_filename_component(folder ${path_file} PATH)
    
            # Create REAL folder
            file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${folder}")
    
            # Delete symlink if it exists
            file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/${path_file}")
    
            # Get OS dependent path to use in `execute_process`
            file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}/${path_file}" link)
            file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${path_file}" target)
    
            if (UNIX)
                set(command ln -s ${target} ${link})
            else()
                set(command cmd.exe /c mklink ${link} ${target})
            endif()
    
            execute_process(COMMAND ${command} 
                            RESULT_VARIABLE result
                            ERROR_VARIABLE output)
    
            if (NOT ${result} EQUAL 0)
                message(FATAL_ERROR "Could not create symbolic link for: ${target} --> ${output}")
            endif()
    
        endforeach(path_file)
    endfunction(create_symlinks)
    

    Usage for a python module (inside CMakeLists.txt):

    # Do not omit !!!RELATIVE!!!
    file(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py *.dat *.xml)
    create_symlinks(${files})
    

    Usage:

    cd src_dir
    mkdir build_dir
    cd build_dir
    cmake ..
    

    IMPORTANT:

    • When adding new files don’t forget to run cmake
    • On Windows mklink support only some Windows versions
    • On Windows mklink can be run as Administrator only. A workaround can be found here.
    • Use relative paths when calling create_symlinks as this is how the directory structure is reconstructed in the binary folder.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: Can CMake generate build scripts that do not, in any way, use CMake?
I use CMake to create my projects. In the project I use mainly Qt
I'm trying to use CMake to build a program relying on blas, I'm detecting
I'm quite new to CMake and I'm trying to use it to build a
Currently I use something like this to create project make files: cmake -DCMAKE_INSTALL_PREFIX=./install-dir -DBUILD_WITH_STATIC_CRT=ON
I'm just found cmake and I want to use it to create make files
Introduction: I am trying to use CMake to obtain cross platform compilation scripts (for
When I use CMake with FIND_PACKAGE( OpenCV REQUIRED ) , all components of OpenCV
I use a cmake generated makefile to compile a c++ file that depends on
Over the years my projects use more and more external libraries, and the way

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.