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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:44:12+00:00 2026-06-01T10:44:12+00:00

CMake generates something like the following for the install rule: # Special rule for

  • 0

CMake generates something like the following for the install rule:

# Special rule for the target install
install: preinstall
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
        /usr/local/bin/cmake -P cmake_install.cmake
.PHONY : install

What I want to do is have some custom commands executed after cmake_install.cmake is invoked so it looks something like:

# Special rule for the target install
install: preinstall
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
        /usr/local/bin/cmake -P cmake_install.cmake
        post_install_command_1
        ...
        post_install_command_n
.PHONY : install

I can do what I want using add_custom_command(TARGET ... POST_BUILD ...) for things that we have written (6 – 10 macros to update). However, there are a bunch of third-party things that get installed and I really don’t want to add POST_BUILD custom commands for all of them (currently 19 projects with more to come and it can be tough to identify what needs to be processed after building instead of after installing). I think it would be much easier to maintain if the custom commands are only used in one place (i.e. as last part of install handling) and where I know they will do everything that is necessary.

Is it possible to get CMake to add commands to the top-level Makefile’s install rule?

  • 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-01T10:44:13+00:00Added an answer on June 1, 2026 at 10:44 am

    You can use the SCRIPT or CODE variant of the install command. If you put the required commands in a script PostInstall.cmake in the project root directory, add the following call to your outermost CMakeLists.txt:

    install (SCRIPT "${CMAKE_SOURCE_DIR}/PostInstall.cmake")
    

    install commands are added to the cmake_install.cmake script in order, thus the call should be added to the end of the CMakeLists.txt to have it run after all other installations have completed.

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

Sidebar

Related Questions

Do the following build systems: cmake, jam and bjam also generate makefiles like qmake
I require the syntax of a CMAKE macro that generates .cc and .h files
CMake offers several ways to specify the source files for a target. One is
I am using CMake to build my project and I have the following line:
I have a CMake project that generates a library. I have written a CMake
If we deploy cakephp not on root domain, but under something like http://domain.com/folder/app-name as
Upon generating a Vistual Studio project from a CMake build file, CMake generates a
I'd like some help with the following problem: I have a debian package built
I have a project that generates a shell script at CMake time (with file(WRITE
I'm following the instructions in the CMake FAQ entry "How can I build my

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.