1

我在一个项目中有一些 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(or ccmake) 配置然后运行make时,它不会编译.el文件。然而,它确实说它完成了目标的构建emacs_byte_compile。所以我假设我对依赖项的工作方式有一些误解。

4

1 回答 1

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})
于 2012-05-03T17:14:44.173 回答