2018-10-15 17:01:57 +08:00
|
|
|
# Lisp C++ Preprocessing
|
|
|
|
|
2018-10-25 22:36:05 +08:00
|
|
|
# Don't forget to repeat this list below in `define_add_lcp`.
|
2018-10-15 17:01:57 +08:00
|
|
|
set(lcp_src_files
|
2021-10-15 00:58:42 +08:00
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/lcp.asd
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/compile-lcp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/package.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/names.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/types.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/clone.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/code-gen.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/slk.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/lcp.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/debug.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/test.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/util.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/tools/lcp)
|
2018-10-15 17:01:57 +08:00
|
|
|
|
2019-05-24 20:16:42 +08:00
|
|
|
# Make `lcp_src_files` a persistent (cache) variable so that
|
|
|
|
# tests/unit/CMakeLists.txt can see it.
|
|
|
|
set(lcp_src_files "${lcp_src_files}" CACHE INTERNAL "")
|
|
|
|
|
2018-10-15 17:01:57 +08:00
|
|
|
add_custom_target(lcp
|
|
|
|
DEPENDS ${lcp_src_files}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
2019-05-24 20:16:42 +08:00
|
|
|
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compile-lcp)
|
2018-10-15 17:01:57 +08:00
|
|
|
|
|
|
|
# Define `add_lcp` function named `name` for registering a lcp file for generation.
|
|
|
|
#
|
|
|
|
# The `define_add_lcp` expects 3 arguments:
|
|
|
|
# * name -- name for the function, you usually want `add_lcp`
|
|
|
|
# * main_src_files -- variable to be updated with generated cpp files
|
2019-05-03 02:53:54 +08:00
|
|
|
# * generated_lcp_files -- variable to be updated with generated hpp and cpp files
|
2018-10-15 17:01:57 +08:00
|
|
|
#
|
|
|
|
# The `add_lcp` function expects at least a single argument, path to lcp file.
|
|
|
|
# Each added file is standalone and we avoid recompiling everything.
|
2018-11-16 17:55:37 +08:00
|
|
|
#
|
|
|
|
# By default, each `.lcp` file will produce a `.hpp` and `.cpp` file. To tell
|
|
|
|
# CMake that no `.cpp` file will be generated, pass a NO_CPP option.
|
2018-10-15 17:01:57 +08:00
|
|
|
macro(define_add_lcp name main_src_files generated_lcp_files)
|
|
|
|
function(${name} lcp_file)
|
2019-05-03 02:53:54 +08:00
|
|
|
set(options NO_CPP SLK_SERIALIZE)
|
2018-10-15 17:01:57 +08:00
|
|
|
set(multi_value_kwargs DEPENDS)
|
|
|
|
# NOTE: ${${}ARGN} syntax escapes evaluating macro's ARGN variable; see:
|
|
|
|
# https://stackoverflow.com/questions/50365544/how-to-access-enclosing-functions-arguments-from-within-a-macro
|
2018-11-16 17:55:37 +08:00
|
|
|
cmake_parse_arguments(KW "${options}" "${one_value_kwargs}" "${multi_value_kwargs}" ${${}ARGN})
|
2019-07-25 19:48:21 +08:00
|
|
|
if (IS_ABSOLUTE ${lcp_file})
|
|
|
|
string(REGEX REPLACE "\.lcp$" ".hpp" h_file ${lcp_file})
|
|
|
|
else()
|
|
|
|
string(REGEX REPLACE "\.lcp$" ".hpp" h_file
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/${lcp_file}")
|
|
|
|
endif()
|
2018-11-16 17:55:37 +08:00
|
|
|
if (NOT KW_NO_CPP)
|
2019-07-25 19:48:21 +08:00
|
|
|
if (IS_ABSOLUTE ${lcp_file})
|
|
|
|
set(cpp_file ${lcp_file}.cpp)
|
|
|
|
else()
|
|
|
|
set(cpp_file ${CMAKE_CURRENT_SOURCE_DIR}/${lcp_file}.cpp)
|
|
|
|
endif()
|
2018-11-16 17:55:37 +08:00
|
|
|
# Update *global* main_src_files
|
|
|
|
set(${main_src_files} ${${main_src_files}} ${cpp_file} PARENT_SCOPE)
|
|
|
|
endif()
|
2019-05-03 02:53:54 +08:00
|
|
|
if (KW_SLK_SERIALIZE)
|
|
|
|
set(slk_serialize "SLK_SERIALIZE")
|
2018-10-15 17:01:57 +08:00
|
|
|
endif()
|
2018-10-25 22:36:05 +08:00
|
|
|
# Repeat the `lcp_src_files` because this is a macro and the variable is
|
|
|
|
# not visible when invoked in another file.
|
|
|
|
set(lcp_src_files
|
2021-10-15 00:58:42 +08:00
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/lcp.asd
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/compile-lcp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/package.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/names.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/types.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/clone.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/code-gen.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/slk.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/lcp.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/debug.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/test.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/src/lisp/util.lisp
|
|
|
|
${PROJECT_SOURCE_DIR}/tools/lcp)
|
2019-05-03 02:53:54 +08:00
|
|
|
add_custom_command(OUTPUT ${h_file} ${cpp_file}
|
2021-10-15 00:58:42 +08:00
|
|
|
COMMAND ${PROJECT_SOURCE_DIR}/tools/lcp ${lcp_file} ${slk_serialize}
|
2018-10-15 17:01:57 +08:00
|
|
|
VERBATIM
|
2019-05-03 02:53:54 +08:00
|
|
|
DEPENDS ${lcp_src_files} lcp ${lcp_file}
|
2018-10-15 17:01:57 +08:00
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
# Update *global* generated_lcp_files
|
2019-05-03 02:53:54 +08:00
|
|
|
set(${generated_lcp_files} ${${generated_lcp_files}} ${h_file} ${cpp_file} PARENT_SCOPE)
|
2018-10-15 17:01:57 +08:00
|
|
|
endfunction(${name})
|
|
|
|
endmacro(define_add_lcp)
|