[cmake-developers] [CMake 0014404]: custom build rule for files in visual studio project

Mantis Bug Tracker mantis at public.kitware.com
Thu Sep 12 21:13:55 EDT 2013


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=14404 
====================================================================== 
Reported By:                Cedric Perthuis
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   14404
Category:                   CMake
Reproducibility:            always
Severity:                   feature
Priority:                   high
Status:                     new
====================================================================== 
Date Submitted:             2013-09-12 21:13 EDT
Last Modified:              2013-09-12 21:13 EDT
====================================================================== 
Summary:                    custom build rule for files in visual studio project
Description: 
Hi,

I would like a way to define a true custom build rule for files in visual studio
projects.
For example, I would like to add to the project a file called myAsset.def and
defines a custom build rule to compile it which would be to call a python script
called asset_generator.py.

The closest I got with cmake so far is to use a custom_command with myAsset.def
in input and myAsset.h in output and add myAsset.h to the project.

This adds to the project:
1 - CMake_Rules/myAsset.def.rule
2 - myAsset.h 
3 - myAsset.def

1: this file has a custom build rule contains the call to asset_generator.py. I
don't want to see this extra file showing up in my project.
2: this is the output of the custom command, I don't want to see it in the
project either. I had to name it a .h file because else the whole rule is
skipped.
3: this is my source, this is what I want to see in the project. It doesn't have
any custom build rule set to it. But I would like to have the custom build rule
define on it.

So here's what I would suggest:

1) a new property called FILE in add_custom_command:

add_custom_command(
FILE myAsset.def
COMMAND python
ARGS ${abs_script} ${abs_infile} ${abs_outfile}
DEPENDS ${infile} VERBATIM)

2) add_executable / add_library would let me pass "myAsset.def" and it would
show up properly in the project with the build rule set on it.

3) On other platforms, the current behavior is fine, I don't know about xcode,
if it supports custom build rule like visual, it'd be nice to also support it
there.

Note: The input and output files from the custom build rule will be
automatically discovered by Visual studio (2010 and above). So what I describe
above is really all we're missing, we don't need any complicated dependency
system. On other platforms, we will probably use a different mechanism and stick
with the current add_custom_command.

This is somewhat critical for the projects we plan on using cmake for.
GYP supports this, and that might tilt the balance in favor of GYP for us.

Thanks.


Steps to Reproduce: 
macro(add_asset infile)
  get_filename_component(outfile ${infile} NAME_WE)
  set(outfilepath
"${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/asset_${outfile}.h")
  get_filename_component(abs_outfile ${outfilepath} ABSOLUTE)
  get_filename_component(abs_infile ${infile} ABSOLUTE)
  get_filename_component(abs_script ${MAIN_DIR}/build/asset_generator.py
ABSOLUTE)
  add_custom_command(OUTPUT ${outfilepath}
    COMMAND python
    ARGS ${abs_script} ${abs_infile} ${abs_outfile}
    DEPENDS ${infile} VERBATIM)
  set (asset_sources ${asset_sources} ${infile} ${abs_outfile})
endmacro()

add_asset(myAsset.def)
add_executable(myExe main.cpp ${asset_sources})

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2013-09-12 21:13 Cedric PerthuisNew Issue                                    
======================================================================




More information about the cmake-developers mailing list