字节用CMake编译elisp文件

时间:2012-05-03 16:52:19

标签: cmake elisp

我在项目中有一些elisp文件,我想用CMake进行字节编译和安装。编译之后,我希望有一个目标来将.el.elc文件安装到目录中。到目前为止我所拥有的是

set(ELISP_SOURCES
  a.el.in
  b.el
  )

# Top level target to compile the elisp sources
add_custom_target(emacs_byte_compile ALL)

foreach(el ${ELISP_SOURCES})

  # Configure and copy the files
  get_filename_component(EL_NAME ${el} NAME_WE)
  configure_file(${el} ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.el)

  # Add command to compile the files
  add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.elc
    COMMAND ${EMACS} ARGS -batch -f batch-byte-compile ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.el
    DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.el
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    )

  # Create the dependencies
  add_dependencies(emacs_byte_compile
    ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.el ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.elc
    )

  # Installation target
  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.el ${CMAKE_CURRENT_BINARY_DIR}/${EL_NAME}.elc
    RUNTIME DESTINATION ${ELISP_DIR}
    )

endforeach(el)

当我使用cmake(或ccmake)配置然后运行make时,它不会编译.el个文件。但它确实说它完成了目标emacs_byte_compile的构建。所以我假设我对依赖关系如何工作有一些误解。

1 个答案:

答案 0 :(得分:2)

您需要创建一个顶级目标,该目标使用您创建的自定义命令的输出。您可以在此处找到一些想法:http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_generate_a_source_file_during_the_build.3F

add_dependencies命令仅对连接顶级cmake目标很有用,因此该行没有做任何事情。

这样的事情:

foreach(el ..)
  # collect output files into a list
  # create a custom command to run emacs to create the elc, 
  #input is .el output is .elc
endforeach()
add_custom_target(emacs_byte_compile DEPENDS ${ELC_LIST})