[CMake] CMake erases targets at regeneration.

Óscar Fuentes ofv at wanadoo.es
Sun Aug 31 22:40:30 EDT 2008


I'm observing something very strange with the "MSYS Makefiles"
generator: after some CMakeLists.txt file is altered, on the next 'make'
cmake is automatically invoked for regenerating the makefiles. Well,
after this is done, some target files are deleted. This is the macro
that creates the targets:

macro(add_partially_linked_object lib)
  if( MSVC )
    add_llvm_library( ${lib} ${ARGN})
  else( MSVC )
    set(pll ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${lib}.o)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib)
    add_library( ${lib}_tmp STATIC ${ARGN})
    add_custom_command(OUTPUT ${pll}
      MESSAGE "Building ${lib}.o..."
      DEPENDS ${lib}_tmp
      WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/temp_lib
      COMMAND echo ${lib}
      COMMAND echo ${pll}
      COMMAND ar x ${CMAKE_STATIC_LIBRARY_PREFIX}${lib}_tmp${CMAKE_STATIC_LIBRARY_SUFFIX}
      COMMAND ld -r *${CMAKE_CXX_OUTPUT_EXTENSION} -o ${pll}
      COMMAND rm -f *${CMAKE_CXX_OUTPUT_EXTENSION}
      )
    add_custom_target(${lib} ALL DEPENDS ${pll})
    set( llvm_libs ${llvm_libs} ${pll} PARENT_SCOPE)
  endif( MSVC )
endmacro(add_partially_linked_object lib)

where `add_llvm_library' is not relevant, as we are working with
MSYS/g++ (anyways, it is just a wrapper for add_library). The macro is
used as:

add_partially_linked_object(LLVMInterpreter
  Execution.cpp
  ExternalFunctions.cpp
  Interpreter.cpp
  )

and creates lib/LLVMInterpreter.o

There are three files that are created with this method. Two are deleted
after the regeneration and one not. This one depends on a custom target.

I can post the sources upon request.

The problem does not happen on Linux ("Unix Makefiles").

-- 
Oscar



More information about the CMake mailing list