| 1 | # CMake configuration for libsensors |
| 2 | cmake_minimum_required(VERSION 3.16.0...3.30) |
| 3 | |
| 4 | # Add static library for libsensors |
| 5 | add_library(vendored_libsensors STATIC |
| 6 | vendored/lib/access.c |
| 7 | vendored/lib/data.c |
| 8 | vendored/lib/error.c |
| 9 | vendored/lib/general.c |
| 10 | vendored/lib/init.c |
| 11 | vendored/lib/sysfs.c |
| 12 | ) |
| 13 | |
| 14 | # Add Flex and Bison dependencies |
| 15 | find_package(FLEX REQUIRED) |
| 16 | find_package(BISON REQUIRED) |
| 17 | |
| 18 | # Generate Bison parser |
| 19 | bison_target(LibsensorsParser vendored/lib/conf-parse.y ${CMAKE_CURRENT_BINARY_DIR}/conf-parse.c |
| 20 | COMPILE_FLAGS "-p sensors_yy --defines=${CMAKE_CURRENT_BINARY_DIR}/conf-parse.h" |
| 21 | ) |
| 22 | |
| 23 | # Generate Flex scanner |
| 24 | flex_target(LibsensorsLexer vendored/lib/conf-lex.l ${CMAKE_CURRENT_BINARY_DIR}/conf-lex.c |
| 25 | COMPILE_FLAGS "-Psensors_yy -Cfe -8" |
| 26 | ) |
| 27 | |
| 28 | # Add dependency to ensure correct build order |
| 29 | add_flex_bison_dependency(LibsensorsLexer LibsensorsParser) |
| 30 | |
| 31 | # Include generated files |
| 32 | target_sources(vendored_libsensors PRIVATE |
| 33 | ${BISON_LibsensorsParser_OUTPUTS} |
| 34 | ${FLEX_LibsensorsLexer_OUTPUTS} |
| 35 | ) |
| 36 | |
| 37 | # Include paths |
| 38 | target_include_directories(vendored_libsensors PUBLIC |
| 39 | vendored/lib |
| 40 | ${CMAKE_CURRENT_BINARY_DIR} # For generated conf-parse.h |
| 41 | ) |
| 42 | |
| 43 | # Compile definitions |
| 44 | target_compile_definitions(vendored_libsensors PRIVATE |
| 45 | ETCDIR="/etc" # Define ETCDIR |
| 46 | ) |
| 47 | |
| 48 | # Suppress warnings for Flex and Bison files |
| 49 | set_source_files_properties(${FLEX_LibsensorsLexer_OUTPUTS} PROPERTIES |
| 50 | COMPILE_FLAGS "-Wno-shadow -Wno-undef -Wno-unused -Wno-missing-prototypes -Wno-sign-compare" |
| 51 | ) |
| 52 | set_source_files_properties(${BISON_LibsensorsParser_OUTPUTS} PROPERTIES |
| 53 | COMPILE_FLAGS "-DYYLTYPE_IS_DECLARED=1" |
| 54 | ) |
| 55 | |
| 56 | # Link against required libraries |
| 57 | target_link_libraries(vendored_libsensors PRIVATE m) |
| 58 | |
| 59 | # Additional compile options to match Makefile |
| 60 | target_compile_options(vendored_libsensors PRIVATE |
| 61 | -fPIC -D_REENTRANT -Wall -O2 -Wstrict-prototypes -Wshadow |
| 62 | -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings |
| 63 | -Wnested-externs -Winline -Wmissing-prototypes -Wno-format-truncation |
| 64 | ) |