I want to have the same file produce different output files and have the same MAIN_DEPENDENCY.<br><br><span style="font-family: courier new,monospace;">project("My Prog")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">cmake_minimum_required(VERSION 2.6)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">add_custom_command(OUTPUT file1.obj</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> MAIN_DEPENDENCY source.cpp</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> COMMAND buildit -o file1.obj source.cpp</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> COMMENT "Making file1 from source"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">add_custom_command(OUTPUT file2.obj</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> MAIN_DEPENDENCY source.cpp</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> COMMAND buildit -o file2.obj source.cpp</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> COMMENT "Making file2 from source"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">set_source_files_properties(file1.obj file2.obj</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> PROPERTIES</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked.</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> GENERATED true # Not an error if this file doesn't exist at the start of build.</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> )</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">add_executable(prog1 source.cpp)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">add_executable(prog2 source.cpp)</span><br style="font-family: courier new,monospace;">
<br><br>In Visual Studio I see this:<br><br><span style="font-family: courier new,monospace;">Solution 'My Proj'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ All Build</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- prog1</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> - Source Files</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> source.cpp -> Outputs file1.obj</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> CMakeLists.txt</span><br style="font-family: courier new,monospace;">
<font style="font-family: courier new,monospace;" face="courier new,monospace">- prog2<br>
- Source Files<br>
source.cpp -> Outputs file1.obj instead of file2.obj<br>
CMakeLists.txt<br>
</font><span style="font-family: courier new,monospace;">+ ZERO_CHECK </span><br style="font-family: courier new,monospace;">
<br>Is it a limitation with Visual Studio or with CMake?<br><br>Note that if I add file1.obj and file2.obj to the project I get this:<br><br><span style="font-family: courier new,monospace;">Solution 'My Proj'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">+ All Build</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">- prog1</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> - Source Files</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> source.cpp -> Outputs file1.obj</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> CMakeLists.txt</span><br><font face="courier new,monospace"> file1.obj -> no custom build step</font><br style="font-family: courier new,monospace;">
<font style="font-family: courier new,monospace;" face="courier new,monospace">- prog2<br> - CMake Rules<br> file2.obj.rule -> Outputs file2.obj<br>
- Source Files<br>
source.cpp -> Outputs file1.obj instead of file2.obj<br>
CMakeLists.txt<br> file2.obj -> no custom build step<br>
</font><span style="font-family: courier new,monospace;">+ ZERO_CHECK </span><br style="font-family: courier new,monospace;">
<br>Thanks,<br>James<br>