From 9cfb87edaf0e1744173b402a771d4c415f9d888d Mon Sep 17 00:00:00 2001 From: Ulya Trofimovich Date: Tue, 10 Dec 2024 16:18:28 +0000 Subject: [PATCH] CMake: split object library by language, pass correct options to each. Previously target compile definitions weren't properly added to the autogenerated sources, as they were built into a separate object library (to ensure that they are built before the rest of the sources). Now the object library is built separately for each language with proper options. This addresses issue #515 "version 4.0.1 re2rust default generate C code". --- CMakeLists.txt | 62 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca50cd480..c5187ef9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,7 +156,8 @@ include_directories(. "${CMAKE_CURRENT_BINARY_DIR}") # generated once at the beginning of build (as with Automake BUILT_SOURCES). # WARNING: custom target that depends on autogenerated sources won't do here # as its dependencies get built multiple times, which ruins parallel builds. -add_library(re2c_objects_autogen OBJECT + +set(autogen_sources "${CMAKE_CURRENT_BINARY_DIR}/src/options/parse_opts.cc" "${CMAKE_CURRENT_BINARY_DIR}/src/parse/lexer.cc" "${CMAKE_CURRENT_BINARY_DIR}/src/parse/lexer.h" @@ -178,6 +179,42 @@ add_library(re2c_objects_autogen OBJECT "${CMAKE_CURRENT_BINARY_DIR}/src/default_syntax_zig.cc" "${re2c_docs}" ) + +# We need a separate object lib for each language, as they have different compile definitions. + +add_library(autogen_objects_c OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_c PUBLIC "RE2C_LANG=Lang::C" "RE2C_PROG=\"re2c\"") + +add_library(autogen_objects_d OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_d PUBLIC "RE2C_LANG=Lang::D" "RE2C_PROG=\"re2d\"") + +add_library(autogen_objects_go OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_go PUBLIC "RE2C_LANG=Lang::GO" "RE2C_PROG=\"re2go\"") + +add_library(autogen_objects_hs OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_hs PUBLIC "RE2C_LANG=Lang::HASKELL" "RE2C_PROG=\"re2hs\"") + +add_library(autogen_objects_java OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_java PUBLIC "RE2C_LANG=Lang::JAVA" "RE2C_PROG=\"re2java\"") + +add_library(autogen_objects_js OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_js PUBLIC "RE2C_LANG=Lang::JS" "RE2C_PROG=\"re2js\"") + +add_library(autogen_objects_ocaml OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_ocaml PUBLIC "RE2C_LANG=Lang::OCAML" "RE2C_PROG=\"re2ocaml\"") + +add_library(autogen_objects_py OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_py PUBLIC "RE2C_LANG=Lang::PYTHON" "RE2C_PROG=\"re2py\"") + +add_library(autogen_objects_rust OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_rust PUBLIC "RE2C_LANG=Lang::RUST" "RE2C_PROG=\"re2rust\"") + +add_library(autogen_objects_v OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_v PUBLIC "RE2C_LANG=Lang::V" "RE2C_PROG=\"re2v\"") + +add_library(autogen_objects_zig OBJECT "${autogen_sources}") +target_compile_definitions(autogen_objects_zig PUBLIC "RE2C_LANG=Lang::ZIG" "RE2C_PROG=\"re2zig\"") + add_library(re2c_objects_autogen_ver_to_vernum OBJECT "${CMAKE_CURRENT_BINARY_DIR}/src/msg/ver_to_vernum.cc" ) @@ -242,7 +279,6 @@ set(re2c_sources src/util/string_utils.cc src/util/range.cc src/main.cc - $ $ ) @@ -276,13 +312,13 @@ re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_c}") add_custom_target(docs DEPENDS "${re2c_docs}") # re2c -add_executable(re2c ${re2c_sources} "${re2c_help_c}") +add_executable(re2c ${re2c_sources} "${re2c_help_c}" $) # re2d if (RE2C_BUILD_RE2D) re2c_gen_help("${re2c_help_source}" "${re2c_help_d}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_d}") - add_executable(re2d ${re2c_sources} "${re2c_help_d}") + add_executable(re2d ${re2c_sources} "${re2c_help_d}" $) target_compile_definitions(re2d PUBLIC "RE2C_LANG=Lang::D" "RE2C_PROG=\"re2d\"" @@ -293,7 +329,7 @@ endif() if (RE2C_BUILD_RE2GO) re2c_gen_help("${re2c_help_source}" "${re2c_help_go}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_go}") - add_executable(re2go ${re2c_sources} "${re2c_help_go}") + add_executable(re2go ${re2c_sources} "${re2c_help_go}" $) target_compile_definitions(re2go PUBLIC "RE2C_LANG=Lang::GO" "RE2C_PROG=\"re2go\"" @@ -304,7 +340,7 @@ endif() if (RE2C_BUILD_RE2HS) re2c_gen_help("${re2c_help_source}" "${re2c_help_haskell}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_haskell}") - add_executable(re2hs ${re2c_sources} "${re2c_help_haskell}") + add_executable(re2hs ${re2c_sources} "${re2c_help_haskell}" $) target_compile_definitions(re2hs PUBLIC "RE2C_LANG=Lang::HASKELL" "RE2C_PROG=\"re2hs\"" @@ -315,7 +351,7 @@ endif() if (RE2C_BUILD_RE2JAVA) re2c_gen_help("${re2c_help_source}" "${re2c_help_java}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_java}") - add_executable(re2java ${re2c_sources} "${re2c_help_java}") + add_executable(re2java ${re2c_sources} "${re2c_help_java}" $) target_compile_definitions(re2java PUBLIC "RE2C_LANG=Lang::JAVA" "RE2C_PROG=\"re2java\"" @@ -326,7 +362,7 @@ endif() if (RE2C_BUILD_RE2JS) re2c_gen_help("${re2c_help_source}" "${re2c_help_js}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_js}") - add_executable(re2js ${re2c_sources} "${re2c_help_js}") + add_executable(re2js ${re2c_sources} "${re2c_help_js}" $) target_compile_definitions(re2js PUBLIC "RE2C_LANG=Lang::JS" "RE2C_PROG=\"re2js\"" @@ -337,7 +373,7 @@ endif() if (RE2C_BUILD_RE2OCAML) re2c_gen_help("${re2c_help_source}" "${re2c_help_ocaml}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_ocaml}") - add_executable(re2ocaml ${re2c_sources} "${re2c_help_ocaml}") + add_executable(re2ocaml ${re2c_sources} "${re2c_help_ocaml}" $) target_compile_definitions(re2ocaml PUBLIC "RE2C_LANG=Lang::OCAML" "RE2C_PROG=\"re2ocaml\"" @@ -348,7 +384,7 @@ endif() if (RE2C_BUILD_RE2PY) re2c_gen_help("${re2c_help_source}" "${re2c_help_python}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_python}") - add_executable(re2py ${re2c_sources} "${re2c_help_python}") + add_executable(re2py ${re2c_sources} "${re2c_help_python}" $) target_compile_definitions(re2py PUBLIC "RE2C_LANG=Lang::PYTHON" "RE2C_PROG=\"re2py\"" @@ -359,7 +395,7 @@ endif() if (RE2C_BUILD_RE2RUST) re2c_gen_help("${re2c_help_source}" "${re2c_help_rust}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_rust}") - add_executable(re2rust ${re2c_sources} "${re2c_help_rust}") + add_executable(re2rust ${re2c_sources} "${re2c_help_rust}" $) target_compile_definitions(re2rust PUBLIC "RE2C_LANG=Lang::RUST" "RE2C_PROG=\"re2rust\"" @@ -370,7 +406,7 @@ endif() if (RE2C_BUILD_RE2V) re2c_gen_help("${re2c_help_source}" "${re2c_help_v}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_v}") - add_executable(re2v ${re2c_sources} "${re2c_help_v}") + add_executable(re2v ${re2c_sources} "${re2c_help_v}" $) target_compile_definitions(re2v PUBLIC "RE2C_LANG=Lang::V" "RE2C_PROG=\"re2v\"" @@ -381,7 +417,7 @@ endif() if (RE2C_BUILD_RE2ZIG) re2c_gen_help("${re2c_help_source}" "${re2c_help_zig}") re2c_gen_manpage("${re2c_manpage_source}" "${re2c_manpage_zig}") - add_executable(re2zig ${re2c_sources} "${re2c_help_zig}") + add_executable(re2zig ${re2c_sources} "${re2c_help_zig}" $) target_compile_definitions(re2zig PUBLIC "RE2C_LANG=Lang::ZIG" "RE2C_PROG=\"re2zig\""