I want to have the same file produce different output files and have the
same MAIN_DEPENDENCY.

project("My Prog")
cmake_minimum_required(VERSION 2.6)

add_custom_command(OUTPUT file1.obj
  MAIN_DEPENDENCY source.cpp
  COMMAND buildit -o file1.obj source.cpp
  COMMENT "Making file1 from source"
  )

add_custom_command(OUTPUT file2.obj
  MAIN_DEPENDENCY source.cpp
  COMMAND buildit -o file2.obj source.cpp
  COMMENT "Making file2 from source"
  )

set_source_files_properties(file1.obj file2.obj
  PROPERTIES
  EXTERNAL_OBJECT true # This is an object file not to be compiled, but only
be linked.
  GENERATED       true # Not an error if this file doesn't exist at the
start of build.
  )

add_executable(prog1 source.cpp)
add_executable(prog2 source.cpp)


In Visual Studio I see this:

Solution 'My Proj'
+ All Build
- prog1
  - Source Files
      source.cpp   -> Outputs file1.obj
    CMakeLists.txt
- prog2
  - Source Files
      source.cpp   -> Outputs file1.obj instead of file2.obj
    CMakeLists.txt
+ ZERO_CHECK

Is it a limitation with Visual Studio or with CMake?

Note that if I add file1.obj and file2.obj to the project I get this:

Solution 'My Proj'
+ All Build
- prog1
  - Source Files
      source.cpp     -> Outputs file1.obj
    CMakeLists.txt
    file1.obj        -> no custom build step
- prog2
  - CMake Rules
      file2.obj.rule -> Outputs file2.obj
  - Source Files
      source.cpp     -> Outputs file1.obj instead of file2.obj
    CMakeLists.txt
    file2.obj        -> no custom build step
+ ZERO_CHECK

Thanks,
James
_______________________________________________
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://www.cmake.org/mailman/listinfo/cmake

Reply via email to