libbsdl: scaffold + working BSDL parser (struct + JSON, C ABI)
Standalone LGPL-2.1 parser for BSDL (IEEE 1149.1), shared by essim and bs_explorer. The parser is ported from the Viveris JTAG Core loader, decoupled from jtag_core, and extended with two extractions the original lacks: - PIN_MAP_STRING -> per-port physical package pin, scalar and vector; - TAP_SCAN_* -> TAP signal roles (TDI/TDO/TMS/TCK/TRST). Exposes a stable C ABI (bsdl_parse_file/buffer -> bsdl_t, bsdl_to_json) with a dependency-free JSON serializer and a bsdl2json CLI. CMake builds a versioned shared library with install/export rules for find_package(bsdl). Verified against m2gl010t, xcku040 and xcku15p (100% pin mapping, correct IDCODEs and TAP roles); api and parse regression tests pass, clean build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
109
CMakeLists.txt
Normal file
109
CMakeLists.txt
Normal file
@@ -0,0 +1,109 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
project(bsdl
|
||||
LANGUAGES C
|
||||
VERSION 0.1.0
|
||||
DESCRIPTION "Standalone BSDL (IEEE 1149.1) parser — struct + JSON, stable C ABI"
|
||||
)
|
||||
|
||||
# --- top-level detection (PROJECT_IS_TOP_LEVEL needs CMake >= 3.21) ---
|
||||
if(NOT DEFINED PROJECT_IS_TOP_LEVEL)
|
||||
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||
set(PROJECT_IS_TOP_LEVEL ON)
|
||||
else()
|
||||
set(PROJECT_IS_TOP_LEVEL OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# This is a dynamic library by nature; build shared unless told otherwise.
|
||||
if(NOT DEFINED BUILD_SHARED_LIBS)
|
||||
set(BUILD_SHARED_LIBS ON)
|
||||
endif()
|
||||
|
||||
option(BSDL_BUILD_CLI "Build the bsdl2json command-line tool" ON)
|
||||
option(BSDL_BUILD_TESTS "Build the test suite" ${PROJECT_IS_TOP_LEVEL})
|
||||
|
||||
# ---------------------------------------------------------------- library ----
|
||||
add_library(bsdl
|
||||
src/bsdl.c
|
||||
src/bsdl_parse.c
|
||||
src/bsdl_strings.c
|
||||
src/bsdl_json.c
|
||||
)
|
||||
add_library(bsdl::bsdl ALIAS bsdl)
|
||||
|
||||
target_include_directories(bsdl
|
||||
PUBLIC
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src
|
||||
)
|
||||
|
||||
set_target_properties(bsdl PROPERTIES
|
||||
C_STANDARD 11
|
||||
C_STANDARD_REQUIRED ON
|
||||
C_VISIBILITY_PRESET hidden
|
||||
VISIBILITY_INLINES_HIDDEN ON
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/bsdl/bsdl.h
|
||||
)
|
||||
|
||||
# Mark exported symbols (dllexport on Windows; default-visibility on ELF).
|
||||
if(BUILD_SHARED_LIBS)
|
||||
target_compile_definitions(bsdl PRIVATE BSDL_BUILD_SHARED)
|
||||
endif()
|
||||
|
||||
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(bsdl PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
||||
# -------------------------------------------------------------------- CLI ----
|
||||
if(BSDL_BUILD_CLI)
|
||||
add_executable(bsdl2json tools/bsdl2json.c)
|
||||
target_link_libraries(bsdl2json PRIVATE bsdl)
|
||||
endif()
|
||||
|
||||
# ------------------------------------------------------------------ tests ----
|
||||
if(BSDL_BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
# --------------------------------------------------- install / export -------
|
||||
include(GNUInstallDirs)
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
install(TARGETS bsdl
|
||||
EXPORT bsdlTargets
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/bsdl
|
||||
)
|
||||
if(BSDL_BUILD_CLI)
|
||||
install(TARGETS bsdl2json RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
endif()
|
||||
|
||||
install(EXPORT bsdlTargets
|
||||
FILE bsdlTargets.cmake
|
||||
NAMESPACE bsdl::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bsdl
|
||||
)
|
||||
|
||||
configure_package_config_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/bsdlConfig.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/bsdlConfig.cmake
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bsdl
|
||||
)
|
||||
write_basic_package_version_file(
|
||||
${CMAKE_CURRENT_BINARY_DIR}/bsdlConfigVersion.cmake
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
)
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/bsdlConfig.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/bsdlConfigVersion.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/bsdl
|
||||
)
|
||||
Reference in New Issue
Block a user