Executing custom command behavior.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Executing custom command behavior.

Albrecht Fritzsche
Hi,

what exactly is the difference between the following both variants of adding an executable and sources to a project? I probably should add that for both versions the build happens via a custom command added via
      add_custom_command( TARGET ${cmake_target} POST_BUILD ... )
Hence I set all source files to header files only such that you cannot rebuild source files accidentally.

While the following variant gives me for Visual Studio 2017 a properly working project
      # working properly
      add_executable(${cmake_target} ${sources})
      set_source_files_properties(${sources} PROPERTIES HEADER_FILE_ONLY TRUE)

this version fails to rebuild the project when something has changed
      # fails to build again when something changed!
      add_executable(${cmake_target})
      if(sources)
          target_sources(${cmake_target} PRIVATE ${sources})
          set_source_files_properties(${sources} PROPERTIES HEADER_FILE_ONLY TRUE)
      endif()

When comparing the generated files for both variants I somehow fail to see any difference which could cause this difference in behavior.

In the documentation for add_custom_command(TARGET .) I see the mentioning
    "If the target is already built, the command will not execute."
Which might explain the behavior of the second variant. But why is the rebuilding working as expected in the first variant?

Thanks for any insights,
Ali
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
--

Powered by kitware.com/cmake

Kitware offers various services to support the CMake community. For more information on each offering, please visit https://cmake.org/services

Visit other Kitware open-source projects at https://www.kitware.com/platforms

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake

This mailing list is deprecated in favor of https://discourse.cmake.org