Inline
Inline

Reputation: 2843

How to run command before all build?

We have legacy project, which uses proprietary build system. We want to port it to CMake. Before build step we have script, which generates code based on comments inside of source files.

I tried to embed it using add_custom_target,add_custom_command, but it fails, because

  1. Script should run before all build (it shouldn't run parallel with other targets)
  2. We have lots of small libraries, which all depend on this script, but it should be ran only one time.

Currently my setup is as follows.


add_library(${PROJECT_NAME} INTERFACE)
....

target_link_libraries(${PROJECT_NAME} ${MANY_SMALL_LIBRARIES})

I can't add PRE_BUILD step for interface library.

Upvotes: 0

Views: 626

Answers (1)

Inline
Inline

Reputation: 2843

I solved it roughly like this.

add_custom_command(
        OUTPUT a_done
        COMMAND touch a_done
        COMMAND ${CMAKE_SOURCE_DIR}/a.sh
        COMMENT "Doing a.sh"
)

add_custom_command(
        OUTPUT b_done
        COMMAND touch b_done
        COMMAND ${CMAKE_SOURCE_DIR}/b.sh
        COMMENT "Doing b.sh"
)

# Execute our custom scripts in following order (in case of sequential build)
add_custom_target(SCRIPTS ALL DEPENDS 
    a_done 
    b_done 
)

add_dependencies(target_1 SCRIPTS)
...
add_dependencies(target_N SCRIPTS)

Upvotes: 1

Related Questions