Skip to content

Commit 1aa3cfd

Browse files
committed
Fix Find modules to detect system libraries and validate lemon compatibility
FindLMDB and FindSQLite3 only searched paths when *_ROOT was set, missing system-installed libraries entirely. Add fallback to default CMake search paths so system -dev packages are found. FindLEMON now tests whether the found lemon supports %realloc/%free directives required by stepcode. System lemon (SQLite's) lacks these BRL-CAD extensions, so the test correctly rejects it and triggers a local build of the forked lemon.
1 parent b78aa61 commit 1aa3cfd

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CMake/FindLEMON.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,29 @@ endif (LEMON_EXECUTABLE AND NOT LEMON_TEMPLATE)
107107

108108
mark_as_advanced(LEMON_TEMPLATE)
109109

110+
# Verify lemon supports %realloc and %free directives (BRL-CAD extensions).
111+
# System lemon (from SQLite) does not support these, but stepcode requires them.
112+
if(LEMON_EXECUTABLE AND LEMON_TEMPLATE)
113+
set(_lemon_test_dir "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/lemon_test")
114+
file(MAKE_DIRECTORY "${_lemon_test_dir}")
115+
file(WRITE "${_lemon_test_dir}/test.y"
116+
"%token_type {int}\n%realloc realloc\n%free free\n%start_symbol start\nstart ::= .\n")
117+
execute_process(
118+
COMMAND ${LEMON_EXECUTABLE} -T${LEMON_TEMPLATE} -q test.y
119+
WORKING_DIRECTORY "${_lemon_test_dir}"
120+
RESULT_VARIABLE _lemon_test_result
121+
OUTPUT_QUIET ERROR_QUIET
122+
)
123+
if(NOT _lemon_test_result EQUAL 0)
124+
message(STATUS "Found lemon at ${LEMON_EXECUTABLE} but it lacks %realloc/%free support")
125+
set(LEMON_EXECUTABLE "LEMON_EXECUTABLE-NOTFOUND" CACHE FILEPATH "Path to lemon" FORCE)
126+
set(LEMON_TEMPLATE "LEMON_TEMPLATE-NOTFOUND" CACHE FILEPATH "Path to lempar.c" FORCE)
127+
endif()
128+
file(REMOVE_RECURSE "${_lemon_test_dir}")
129+
unset(_lemon_test_dir)
130+
unset(_lemon_test_result)
131+
endif()
132+
110133
include(FindPackageHandleStandardArgs)
111134
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LEMON DEFAULT_MSG LEMON_EXECUTABLE LEMON_TEMPLATE)
112135

CMake/FindLMDB.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ if(LMDB_ROOT)
4848
list(APPEND _LMDB_SEARCHES _LMDB_SEARCH_ROOT)
4949
endif()
5050

51+
# Fall back to default system paths
52+
set(_LMDB_SEARCH_NORMAL)
53+
list(APPEND _LMDB_SEARCHES _LMDB_SEARCH_NORMAL)
54+
5155
set(LMDB_NAMES lmdb lmdbd)
5256

5357
# Try each search configuration.

CMake/FindSQLite3.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ if(SQLite3_ROOT)
4242
list(APPEND _SQLite3_SEARCHES _SQLite3_SEARCH_ROOT)
4343
endif()
4444

45+
# Fall back to default system paths
46+
set(_SQLite3_SEARCH_NORMAL)
47+
list(APPEND _SQLite3_SEARCHES _SQLite3_SEARCH_NORMAL)
48+
4549
set(SQLite3_NAMES sqlite3 sqlite libsqlite3 libsqlite)
4650

4751
# Try each search configuration.

0 commit comments

Comments
 (0)