Running a custom shell script using CMake

I have the following directory structure:

/CMakeLists.txt
/component-a/CMakeLists.txt
           /...
/component-b/CMakeLists.txt
           /...
/doc/CMakeLists.txt
    /create-doc.sh

The shell script create-doc.shcreates the documentation file ( doc.pdf). How can I use CMake to execute this shell script during assembly and copy the file doc.pdfto the assembly directory?

I tried this using add_custom_commandin a file CMakeLists.txtinside a directory doc:

add_custom_command ( OUTPUT doc.pdf 
                     COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create-doc.sh 
                     WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/)

Unfortunately, the team never starts.

I also tried execute_process:

execute_process ( COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/create-doc.sh  
                  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ ) 

Now the script is executed during the configuration phase, but not during the build.

+4
source share
1 answer

add_custom_command. CMake, . CMake , - .

, , , :

add_custom_target(
  BuildDocs ALL
  DEPENDS doc.pdf
)

( ) CMake.

, add_custom_target (, ALL, COMMENT), .

+5

Source: https://habr.com/ru/post/1657283/


All Articles