On Thu, Sep 12, 2013 at 3:28 PM, James Bigler <[email protected]> wrote:
> On Thu, Sep 12, 2013 at 3:07 PM, Brad King <[email protected]> wrote: > >> On 09/12/2013 04:57 PM, James Bigler wrote: >> > This seems kind of confusing when the default for all the other VS >> > generators is to link in the output of the custom command. Does >> > that not seem like a problem? >> >> The goal is to link all .obj files listed in the target exactly once. >> According to Tests/ExternalOBJ/CMakeLists.txt this is tested and >> works everywhere: >> >> ------------------------------------------------------------------------ >> # Test creation of external objects by custom commands. >> set(CUSTOM_OBJECT >> ${CMAKE_CURRENT_BINARY_DIR}/custom_object${CMAKE_C_OUTPUT_EXTENSION}) >> add_custom_command( >> OUTPUT ${CUSTOM_OBJECT} >> COMMAND ${CMAKE_COMMAND} -E copy ${EXTERNAL_OBJECT} ${CUSTOM_OBJECT} >> DEPENDS ${EXTERNAL_OBJECT} >> ) >> >> message("${EXTERNAL_OBJECT}") >> # Build an executable using the external object file. >> add_executable(ExternalOBJ executable.cxx ${CUSTOM_OBJECT}) >> # A bug showed up in VS2010 where an object file that was >> # part of a custom commad output worked, but ones that were >> # not didn't work. So, repeat the executable using the object >> # directly and not from the output of the copy. >> add_executable(ExternalOBJ2 executable.cxx ${EXTERNAL_OBJECT}) >> ------------------------------------------------------------------------ >> >> Special changes were needed to work around VS 10 and 11 behavior of >> automatically linking custom command outputs that are objects. >> I do not think that happens with VS < 10. In VS 10 we let it link >> the custom command output and reference the .obj as <None>. In >> VS 11 we set LinkObjects to false in the custom command and refer >> to the .obj with <Object>. This is all tested as shown above. >> >> I do not see how MAIN_DEPENDENCY can influence this. It only affects >> where the custom command is attached. >> >> -Brad >> > > You are correct. I'm doing more investigation on how to fix this, and I > discovered that MAIN_DEPENDENCY isn't directly the problem, but it is > related. > > I discovered a long time ago that VS would link the output of a custom > command. When I used MAIN_DEPENDENCY it would link the custom command to > the .cu file and I didn't need to add the obj file to the project anymore. > This was great for VS versions that didn't have source groupings. Now I > only had .cu files without a bunch of .obj files laying around. I also set > the EXTERNAL_OBJECT property on the obj files even though they weren't > always added. You could for example not attach the build rules to the .cu > files and the obj files would be added to the project. > > I think this could work a little better if you allowed linking of the > output of a custom command if MAIN_DEPENDENCY is set and the output of that > command is only OBJ files or files that have the EXTERNAL_OBJECT property > set to true. > > What do you think? It would be backward compatible and allow the fix you > already have. > > James > I should also point out that whatever solution comes into being, it should get integrated into 2.8.12 since this affects FindCUDA.cmake. Here's a current work around, though it might need to do something with version numbers. @@ -1398,9 +1398,12 @@ set(cuda_add_generated_file TRUE) if(NOT compile_to_ptx AND CMAKE_GENERATOR MATCHES "Visual Studio" AND CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE) - # Visual Studio 8 crashes when you close the solution when you don't add the object file. - if(NOT CMAKE_GENERATOR MATCHES "Visual Studio 8") + # Visual Studio 8 crashes when you close the solution when you don't add the + # object file. CMake's Visual Studio 11 generator doesn't automatically link in + # the output of custom commands, so you need to add the object file to the project + # in order to get them linked in. + if(NOT CMAKE_GENERATOR MATCHES "Visual Studio 8" AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 11") set(cuda_add_generated_file FALSE) endif() endif()
-- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers
