Say you have a simple cpp file:

cat > test.cpp
int main() { return 0; }

Then you have this as your CMakeLists.txt file:

set(input_file test.cpp)
set(generated_file
${CMAKE_CURRENT_BINARY_DIR}/${input_file}.blah${CMAKE_CXX_OUTPUT_EXTENSION})
add_custom_command(
  OUTPUT ${generated_file}
  COMMAND c++ -c ${CMAKE_CURRENT_SOURCE_DIR}/${input_file} -o
${generated_file}
  MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${input_file}
  #DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${input_file}
  COMMENT "Building ${generated_file} using custom command."
  )
add_executable(test_b ${generated_file} ${input_file})
#add_executable(test_b ${generated_file} )
set_target_properties(test_b PROPERTIES LINKER_LANGUAGE CXX)

add_executable(test_cxx test.cpp)

If I put test.cpp as the MAIN_DEPENDENCY then add_executable(test_cxx
test.cpp) fails to compile an object file to link in.

If I change MAIN_DEPENDENCY to DEPENDS, then the add_executable(test_b
${generated_file} ${input_file}) will end up compiling test.cpp into an
object file twice (when it only did it once before).

Can anyone explain why this is so?  It seems like weird behavior.

Thanks,
James
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to