0

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.

4
  • Why can't you add PRE_BUILD? Commented Sep 22, 2021 at 13:22
  • Have you tried using add_dependencies() to arrive at the build order you want? Commented Sep 22, 2021 at 13:41
  • @AlexeyLarionov CMake tells me, that I can't use PRE_BUILD with interface library Commented Sep 22, 2021 at 13:42
  • @DoritoJohnson I tried using add_dependencies but command was running for every library (instead of once) Commented Sep 22, 2021 at 13:42

1 Answer 1

1

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.