According to this MSDN blog entry it is recommended to compile .fx effect files with fxc as part of your build process. Given a list of fx files, how do I tell cmake to add some to my project files (VS2010)?
Asked
Active
Viewed 1,567 times
1 Answers
4
Use find_program
to find fxc
and add_custom_command
to build:
find_program(FXC fxc DOC "fx compiler")
if(NOT FXC)
message(SEND_ERROR "Cannot find fxc.")
endif(NOT FXC)
add_custom_target(fx ALL)
foreach(FILE foo.fx bar.fx baz.fx)
get_filename_component(FILE_WE ${FILE} NAME_WE)
add_custom_command(OUTPUT ${FILE_WE}.obj
COMMAND ${FXC} /Fo ${FILE_WE}.obj ${FILE}
MAIN_DEPENDENCY ${FILE}
COMMENT "Effect-compile ${FILE}"
VERBATIM)
add_dependencies(fx ${FILE_WE}.obj)
endforeach(FILE)
Not being a Windows user, I'm not sure if that's exactly the right way to invoke fxc
, but you can tinker with it. Note also that this doesn't link the object files into wherever they need to go. This mailing list post might help you.

Jack Kelly
- 18,264
- 2
- 56
- 81
-
They don't need to be linked at all - they are loaded by the executable later. How can I add them to the target so they are built when their sources change? – ltjax Aug 13 '12 at 10:14
-
@ltjax: Edited. Note the `add_custom_target` and the `add_dependencies` calls. Does the fx compiler output `.obj` files? – Jack Kelly Aug 13 '12 at 11:05
-
Works like a charm. Any way I can add the source files to that target so they show up in the VS solution explorer? – ltjax Aug 15 '12 at 13:30
-
@ltjax: I never used the visual studio generators, so I don't know. Sorry. Perhaps the `source_group` command might do what you want. – Jack Kelly Aug 15 '12 at 20:30