playground/devtools/kdevelop4-extra-plugins/python/parser

Alexander Neundorf neundorf at kde.org
Wed Jul 11 04:01:30 CEST 2007


On Tuesday 10 July 2007 16:08, Andreas Pakulat wrote:
...
> I think the macro I came up with causes a full rebuild of the project
> using it when touching any of the CMakeLists.txt.
>
> An example is playground/devtools/kdevelop4-extra-plugins/ruby
>
> if I touch tests/CMakeLists.txt the whole project is rebuilt, the
> generated and non-generated files are all recompiled.
>
> The macro I use looks like this:
> macro(GET_GENERATED_SRCS _srcsList)
>     if(KDEVPG_FOUND AND FLEX_FOUND)
>         include_directories(${KDEVPG_INCLUDE_DIR})
>         kdevpg_generate(_kdevpgList ruby DEBUG_VISITOR
>   	      "${CMAKE_SOURCE_DIR}/parser/ruby.g"
>   	      "${CMAKE_SOURCE_DIR}/parser/ruby_lexer.h")
>
>         # Copy ruby_lexer.ll to the builddir, so that flex doesn't write
> out # absolute paths in the generated file when we pass them as arguments.
> # In short, I don't want stuff like
>         # '#line 2 "/home/kde/build/.../ruby_lexer.cpp" in SVN.
>         add_custom_command(
>             OUTPUT  "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.ll"
>             MAIN_DEPENDENCY "${CMAKE_SOURCE_DIR}/parser/ruby_lexer.ll"
>             COMMAND ${CMAKE_COMMAND}  ARGS -E copy_if_different
>                     "${CMAKE_SOURCE_DIR}/parser/ruby_lexer.ll"
>                     "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.ll"
>         )
>         # Add command to generate the lexer.
>         add_custom_command(
>             OUTPUT  "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.cpp"
>             MAIN_DEPENDENCY "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.ll"
>             DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ruby_parser.h"
>                     "${CMAKE_SOURCE_DIR}/parser/ruby_lexer.h"
>             COMMAND ${FLEX_EXECUTABLE}
>             ARGS    -o"ruby_lexer.cpp"
>                     "ruby_lexer.ll"
>             WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
>         )
>         set(${_srcsList} ${_kdevpgList}
> "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.cpp") else(KDEVPG_FOUND AND
> FLEX_FOUND)
>         include_directories(${CMAKE_SOURCE_DIR}/parser/generated)
>         message(STATUS "Assuming existence of generated parser files")
>         message( STATUS "Assuming existence of generated lexer files")
> 	set(${_srcsList}
>             ${CMAKE_SOURCE_DIR}/parser/generated/ruby_parser.cpp
>             ${CMAKE_SOURCE_DIR}/parser/generated/ruby_visitor.cpp
>             ${CMAKE_SOURCE_DIR}/parser/generated/ruby_default_visitor.cpp
>             ${CMAKE_SOURCE_DIR}/parser/generated/ruby_lexer.cpp )
>
>     endif(KDEVPG_FOUND AND FLEX_FOUND)
> endmacro(GET_GENERATED_SRCS)

Ok, not sure what is causing this.
You should be able to merge the two add_custom_command()s into one as below:

macro(GET_GENERATED_SRCS _srcsList)
    if(KDEVPG_FOUND AND FLEX_FOUND)
        include_directories(${KDEVPG_INCLUDE_DIR})
        kdevpg_generate(_kdevpgList ruby DEBUG_VISITOR
              "${CMAKE_SOURCE_DIR}/parser/ruby.g" 
              "${CMAKE_SOURCE_DIR}/parser/ruby_lexer.h")

        # Add command to generate the lexer.
        add_custom_command(
            OUTPUT  "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.cpp"
            MAIN_DEPENDENCY "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.ll"
            DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/ruby_parser.h"
                           "${CMAKE_SOURCE_DIR}/parser/ruby_lexer.h"

            COMMAND ${CMAKE_COMMAND} -E copy_if_different 
                          "${CMAKE_SOURCE_DIR}/parser/ruby_lexer.ll"
                          "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.ll"

            COMMAND ${FLEX_EXECUTABLE} -o "ruby_lexer.cpp" "ruby_lexer.ll"
            WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        )
        set(${_srcsList}
             ${_kdevpgList} "${CMAKE_CURRENT_BINARY_DIR}/ruby_lexer.cpp")

   else(KDEVPG_FOUND AND FLEX_FOUND)
        include_directories(${CMAKE_SOURCE_DIR}/parser/generated)
        message(STATUS "Assuming existence of generated parser files")
        message( STATUS "Assuming existence of generated lexer files")
        set(${_srcsList} 
            ${CMAKE_SOURCE_DIR}/parser/generated/ruby_parser.cpp
            ${CMAKE_SOURCE_DIR}/parser/generated/ruby_visitor.cpp
            ${CMAKE_SOURCE_DIR}/parser/generated/ruby_default_visitor.cpp
            ${CMAKE_SOURCE_DIR}/parser/generated/ruby_lexer.cpp )

    endif(KDEVPG_FOUND AND FLEX_FOUND)
endmacro(GET_GENERATED_SRCS)

This probably doesn't change it.

One way to debug this would be the following.
Build the buildtree.
Run cmake on it, you can simply run "cmake <build_dir>"
Then copy this buildtree to some other location so you can test against it 
later.
Run cmake again on the original buildtree.
Find out the differences between the buildtree and the previous buildtree.

Then we'll see what has changed.

Alex


More information about the Kde-buildsystem mailing list