diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2021-10-11 00:36:22 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2021-10-11 11:47:34 +0200 |
| commit | b68ee957234387f8a5bb0e0a4eac88fc4cf5ed47 (patch) | |
| tree | f5d920a9e6a1b2b35ae90cc9fc1c1d2e1a4bb85c /src | |
| parent | 7f0b6bd9c6978ac7639bcaf0de452cb29318e683 (diff) | |
| download | PROJ-b68ee957234387f8a5bb0e0a4eac88fc4cf5ed47.tar.gz PROJ-b68ee957234387f8a5bb0e0a4eac88fc4cf5ed47.zip | |
CMake build: add generate_wkt1_parser and generate_wkt2_parser manual target, and logic to detect when they must be run
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 6 | ||||
| -rw-r--r-- | src/check_md5sum.cmake | 7 | ||||
| -rw-r--r-- | src/generate_wkt_parser.cmake | 18 | ||||
| -rw-r--r-- | src/lib_proj.cmake | 54 |
4 files changed, 84 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index bae922d5..0723d942 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,7 +14,11 @@ include_HEADERS = proj.h proj_experimental.h proj_constants.h geodesic.h \ EXTRA_DIST = bin_cct.cmake bin_gie.cmake bin_cs2cs.cmake \ bin_geod.cmake bin_proj.cmake bin_projinfo.cmake \ - lib_proj.cmake CMakeLists.txt bin_geodtest.cmake \ + lib_proj.cmake \ + check_md5sum.cmake \ + generate_wkt_parser.cmake \ + CMakeLists.txt \ + bin_geodtest.cmake \ bin_projsync.cmake \ tests/geodtest.cpp \ wkt1_grammar.y wkt2_grammar.y apps/emess.h apps/utils.h \ diff --git a/src/check_md5sum.cmake b/src/check_md5sum.cmake new file mode 100644 index 00000000..bab6fc6f --- /dev/null +++ b/src/check_md5sum.cmake @@ -0,0 +1,7 @@ +file(READ "${IN_FILE}" CONTENTS) + +string(MD5 MD5SUM "${CONTENTS}") + +if(NOT("${MD5SUM}" STREQUAL "${EXPECTED_MD5SUM}")) + message(FATAL_ERROR "File ${IN_FILE} has been modified. target ${TARGET} should be manually run. And lib_proj.cmake should be updated with \"${MD5SUM}\"") +endif() diff --git a/src/generate_wkt_parser.cmake b/src/generate_wkt_parser.cmake new file mode 100644 index 00000000..bcfc09be --- /dev/null +++ b/src/generate_wkt_parser.cmake @@ -0,0 +1,18 @@ +message("Generating ${OUT_FILE}") + +execute_process(COMMAND "bison" "--no-lines" "-d" "-p" "${PREFIX}" "-o${OUT_FILE}" "${IN_FILE}" + RESULT_VARIABLE STATUS) + +if(STATUS AND NOT STATUS EQUAL 0) + message(FATAL_ERROR "bison failed") +endif() + +# Post processing of the generated file +# All those replacements are to please MSVC +file(READ ${OUT_FILE} CONTENTS) +string(REPLACE "yyerrorlab:" "#if 0\nyyerrorlab:" CONTENTS "${CONTENTS}") +string(REPLACE "yyerrlab1:" "#endif\nyyerrlab1:" CONTENTS "${CONTENTS}") +string(REPLACE "for (yylen = 0; yystr[yylen]; yylen++)" "for (yylen = 0; yystr && yystr[yylen]; yylen++)" CONTENTS "${CONTENTS}") +string(REPLACE "return yystpcpy (yyres, yystr) - yyres;" "return (YYPTRDIFF_T)(yystpcpy (yyres, yystr) - yyres);" CONTENTS "${CONTENTS}") +string(REPLACE "YYPTRDIFF_T yysize = yyssp - yyss + 1;" "YYPTRDIFF_T yysize = (YYPTRDIFF_T)(yyssp - yyss + 1);" CONTENTS "${CONTENTS}") +file(WRITE "${OUT_FILE}" "${CONTENTS}") diff --git a/src/lib_proj.cmake b/src/lib_proj.cmake index 785ec6f0..4ece9094 100644 --- a/src/lib_proj.cmake +++ b/src/lib_proj.cmake @@ -298,6 +298,60 @@ source_group("CMake Files" FILES CMakeLists.txt) # Embed PROJ_LIB data files location add_definitions(-DPROJ_LIB="${CMAKE_INSTALL_PREFIX}/${DATADIR}") + +########################################################### +# targets to refresh wkt1_parser.cpp and wkt2_parser.cpp +########################################################### + +# Those targets need to be run manually each time wkt1_grammar.y / wkt2_grammar.y +# is modified. +# We could of course run them automatically, but that would make building +# PROJ harder. + +# This target checks that wkt1_grammar.y md5sum has not changed +# If it has, then it should be updated and the generate_wkt1_parser target +# should be manually run +add_custom_target(check_wkt1_grammar_md5 ALL + COMMAND ${CMAKE_COMMAND} + "-DIN_FILE=wkt1_grammar.y" + "-DTARGET=generate_wkt1_parser" + "-DEXPECTED_MD5SUM=3a1720c3fa1b759719e33dd558603efb" + -P "${CMAKE_CURRENT_SOURCE_DIR}/check_md5sum.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/wkt1_grammar.y" + VERBATIM) + +add_custom_target(generate_wkt1_parser + COMMAND ${CMAKE_COMMAND} + "-DPREFIX=pj_wkt1_" + "-DIN_FILE=wkt1_grammar.y" + "-DOUT_FILE=wkt1_generated_parser.c" + -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_wkt_parser.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM) + +# This target checks that wkt2_grammar.y md5sum has not changed +# If it has, then it should be updated and the generate_wkt2_parser target +# should be manually run +add_custom_target(check_wkt2_grammar_md5 ALL + COMMAND ${CMAKE_COMMAND} + "-DIN_FILE=wkt2_grammar.y" + "-DTARGET=generate_wkt2_parser" + "-DEXPECTED_MD5SUM=1691b7d213073d5a1b49db2e080bc96e" + -P "${CMAKE_CURRENT_SOURCE_DIR}/check_md5sum.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/wkt2_grammar.y" + VERBATIM) + +add_custom_target(generate_wkt2_parser + COMMAND ${CMAKE_COMMAND} + "-DPREFIX=pj_wkt2_" + "-DIN_FILE=wkt2_grammar.y" + "-DOUT_FILE=wkt2_generated_parser.c" + -P "${CMAKE_CURRENT_SOURCE_DIR}/generate_wkt_parser.cmake" + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + VERBATIM) + ################################################# ## targets: libproj and proj_config.h ################################################# |
