2012-05-03 68 views
0

我有一個項目中的一些elisp文件,我想用CMake進行字節編譯和安裝。編譯後,我想有一個目標將.el.elc文件安裝到目錄。我至今是字節與CMake編譯elisp文件

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

您需要創建一個使用您創建的自定義命令的輸出的頂級目標。你可以在這裏找到一些想法: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}) 
+0

完美!謝謝。 –