0

Followup question to this question: cmake project build only one specific executable (and its dependencies)

I have a custom target written so it will run every time i compile something in my project. Now that I call an explicit target as asked in the question above, this custom command does not get executed anymore. Code:

add_custom_target(
    custom_command
    ALL
    DEPENDS hash.h
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "[INFO] CMake generating special *.h file from custom command magic."
)

I already tried removing the ALL directive but it did not change anything.

Forgot to add: I am using cmake/3.13.4 compiled from source.

HFinch
  • 534
  • 1
  • 7
  • 20
  • So, you run `cmake --build --target custom_command`? – arrowd Aug 12 '19 at 10:12
  • And the dependency is fulfilled? And what COMMAND needs to be executed? – Th. Thielemann Aug 12 '19 at 10:18
  • @arrowd no I am running `cmake --build . --target my_target` but inside `my_target` this command needs to be executed because I have to generate a `*.h` file that gets included by one of the project source files – HFinch Aug 12 '19 at 10:53
  • 2
    Did not get it. I expected something like `add_custom_target( Generate_hash_h ALL COMMAND myhashgenerator.script hash.h DEPENDS hash.h WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMENT "[INFO] CMake generating special *.h file from custom command magic." )` within your code. – Th. Thielemann Aug 12 '19 at 11:25
  • 1
    Yes, if you post more of your code, it may be easier to understand. Where is the script that generates the header? I don't see it in your `add_custom_target` command... – Kevin Aug 12 '19 at 19:10

1 Answers1

0

Sorry for the later answer but work was crazy. So after i read the comments by @Th.Thielemann and @squareskittles I reread the cmake documentation and found my solution. The following code was written under cmake/3.0.0 quite a while ago:

add_custom_command( 
    OUTPUT some_header.h
    COMMAND cat ${BISON_HEADER} other_header.h | awk -f some_wak_file.awk > some_header.h
    DEPENDS ${BISON_HEADER}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

add_custom_target(
    custom_command
    ALL
    DEPENDS some_header.h
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "[INFO] CMake generating special *.h file from custom command magic."
)

After reading up again on the documentation for cmake/3.13 it became quite obvious that it could be written in an easier form:

add_custom_target(
    timex_utilities_hash 
    ALL
    COMMAND cat ${BISON_HEADER} other_header.h | awk -f some_wak_file.awk > some_header.h
    DEPENDS ${BISON_HEADER}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

Thank you again @Th. Thielemann and @squareskittles for the patients and the inut to check again!

HFinch
  • 534
  • 1
  • 7
  • 20