From 9218241da68042f01bdc29584a57518a52c5b3f0 Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Wed, 25 Nov 2015 12:22:59 +0100 Subject: [PATCH] cmake: Add a helper script which defines generator rules for eo files eo_rule_create adds rules to generate to .eo.x .eo.h .eot.h files. It also monitors its deps. @feature --- Makefile.am | 3 +- cmakeconfig/EolianHelper.cmake | 80 ++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 cmakeconfig/EolianHelper.cmake diff --git a/Makefile.am b/Makefile.am index c1d0a84300..235cdc009f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -297,7 +297,8 @@ cmakeconfig/EoConfigVersion.cmake eolian_cmakeconfigdir = $(libdir)/cmake/Eolian/ eolian_cmakeconfig_DATA = \ cmakeconfig/EolianConfig.cmake \ -cmakeconfig/EolianConfigVersion.cmake +cmakeconfig/EolianConfigVersion.cmake \ +cmakeconfig/EolianHelper.cmake eolian_cxx_cmakeconfigdir = $(libdir)/cmake/EolianCxx/ eolian_cxx_cmakeconfig_DATA = \ diff --git a/cmakeconfig/EolianHelper.cmake b/cmakeconfig/EolianHelper.cmake new file mode 100644 index 0000000000..9b0397327e --- /dev/null +++ b/cmakeconfig/EolianHelper.cmake @@ -0,0 +1,80 @@ +find_package(Eolian 1.16 REQUIRED) +# macro to create a eolian generated c source file +# +# macro adds a generate rule, which depends on the original file the rule will output file.x +# +# The passed include snippet will just be added to the command + +macro(_rule_eox file include deps) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${file}.x + COMMAND eolian_gen ${include} --gc -o ${CMAKE_CURRENT_SOURCE_DIR}/${file}.x ${CMAKE_CURRENT_SOURCE_DIR}/${file} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file} + DEPENDS ${deps} + ) +endmacro() + +# macro to create a eolian generated header file +# +# other details are like the eox rule +macro(_rule_eoh file include deps) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${file}.h + COMMAND eolian_gen ${include} --gh -o ${CMAKE_CURRENT_SOURCE_DIR}/${file}.h ${CMAKE_CURRENT_SOURCE_DIR}/${file} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${file} + DEPENDS ${deps} + ) +endmacro() + +# Can be used to create .eo.x , .eo.h, .eot.h generator rules. +# .eo files are generated into .eo.x and .eo.h files +# .eot files are generated into .eot.h files +# The standard include path of efl eolian files is automatically added to the includes +# +# build_files - A list of files +# relative_include_dirs - A list of dirs to include +# +# If one of the included files is changed the file will be rebuilded at the next +# make call +# +# The macro scans for .eo files, hey have to be in the build_files. +# The generator rules are just executed if the file is a dependecy of some lib/executable. + +function(eo_rule_create build_files relative_include_dirs) + string(REPLACE "\n" "" EOLIAN_EO_DIR_WITHOUT_NEWLINE "${EOLIAN_EO_DIR}") + + # add std includes + list(APPEND include_dirs + ${EOLIAN_EO_DIR_WITHOUT_NEWLINE} + ) + + # convert relative to absolut + foreach(relative_include_dir ${relative_include_dirs}) + list(APPEND include_dirs + ${CMAKE_CURRENT_SOURCE_DIR}/${relative_include_dir} + ) + endforeach() + + # work with the absolut paths + foreach(include_cmd ${include_dirs}) + # build include cmd + string(CONCAT includes "${includes}" " -I${include_cmd}") + # fetch dep files + file(GLOB_RECURSE files "${include_cmd}/*.eo") + foreach(file ${files}) + list(APPEND dep_files ${file}) + endforeach() + endforeach() + + string(REPLACE " " ";" includes "${includes}") + foreach(file ${build_files}) + get_filename_component(ext ${file} EXT) + if (ext MATCHES "^\\.eo$") + _rule_eoh("${file}" "${includes}" "${dep_files}") + _rule_eox("${file}" "${includes}" "${dep_files}") + endif() + if (ext MATCHES "^\\.eot$") + _rule_eoh("${file}" "${includes}" "${dep_files}") + endif() + endforeach() +endfunction()