2

I am extremely new to CMake, and having trouble setting up an install rule. I want to run the following command in make install:

update-rc.d solshare_stats_runscript defaults

But I only want to run this command if:

CMAKE_INSTALL_PREFIX="/"

How can I do this?

4

1 回答 1

5

You can probably do this using install(SCRIPT ...) and provide a wee CMake script to be invoked.

So add this to your CMakeLists.txt:

install(SCRIPT InstallScript.cmake)

Then in the InstallScript.cmake:

if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/")
  execute_process(COMMAND update-rc.d solshare_stats_runscript defaults
                  RESULT_VARIABLE Result
                  OUTPUT_VARIABLE Output
                  ERROR_VARIABLE Error)
  if(Result EQUAL 0)
    message(STATUS "Ran update-rc.d as CMAKE_INSTALL_PREFIX == \"/\"")
  else()
    message(FATAL_ERROR "Result - ${Result}\nOutput - ${Output}\nError - Error")
  endif()
else()
  message(STATUS "Not running update-rc.d as CMAKE_INSTALL_PREFIX != \"/\"")
endif()

You may need to provide more arguments to the execute_process call in the script (e.g. WORKING_DIRECTORY).

于 2013-06-30T12:01:48.450 回答