[CMake] byte-compiling emacs lisp sources

Michael Wild themiwi at gmail.com
Sat Feb 13 08:26:58 EST 2010


On 13. Feb, 2010, at 13:05 , Tim Blechmann wrote:

> hi all,
> 
> i've got some troubles to byte-compile emacs lisp files with cmake.
> 
> basically, i need to do the following
> - copy source file to the build directory
> - compile the elc file with: "emacs -batch -f batch-byte-compile 
> /path/to/source.el"
> - add an install rule to install the generated elc file to 
> "share/emacs/site-lisp"
> 
> 
> 
> currently, i am using this snippet:
> configure_file(${el}
>               ${CMAKE_CURRENT_BINARY_DIR}/${el})
> 
> add_custom_command(TARGET ${el}c
>                  COMMAND emacs -batch -f batch-byte-compile 
> ${CMAKE_CURRENT_BINARY_DIR}/${el}
>                  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${el})
> 
> install(TARGETS ${el}c
>        DESTINATION "share/emacs/site-lisp")
> 
> however, neither the byte-code target is generated, nor the does the install 
> statement want to install the target (since it is not an executable, library 
> or module)
> 
> what am i doing wrong? or is there a module for building emacs byte-code 
> files?
> 
> thanks in advance, tim

You should use

# find emacs and complain if not found
find_program(EMACS_EXECUTABLE emacs)
if(NOT EMACS_EXECUTABLE)
  message(SEND_ERROR "Emacs could not be found")
endif()

# copy source to binary tree
configure_file(${el} ${CMAKE_CURRENT_BINARY_DIR}/${el})
# add rule (i.e. command) how to generate the byte-compiled file
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${el}c
  COMMAND ${EMACS_EXECUTABLE} -batch -f batch-byte-compile
    ${CMAKE_CURRENT_BINARY_DIR}/${el}
  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${el}
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  COMMENT "Creating byte-compiled Emacs lisp ${CMAKE_CURRENT_BINARY_DIR}/${el}c")

# add a top-level target to byte-compile all emacs-lisp sources
add_custom_target(emacs_byte_compile ALL
  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${el}c)

# install the byte-compiled emacs-lisp sources
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${el}c
  DESTINATION share/emacs/site-lisp)


HTH

Michael


More information about the CMake mailing list