diff --git a/.gitignore b/.gitignore index f537d5a6..b0997294 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ stamp-h? /tests/*.log /tests/*.trs /tests/main +CMakeLists.txt.user diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..b9c988b9 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,126 @@ +cmake_minimum_required(VERSION 3.23) # file_set needs at least 3.23 +project(libsigrokdecode LANGUAGES C + VERSION 0.6.0 + HOMEPAGE_URL "http://www.sigrok.org" +) + +set(CMAKE_C_STANDARD 99) + +set(PROJECT_BUG_URL "sigrok-devel@lists.sourceforge.net") +set(PROJECT_PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") + +set(SR_LIB_VERSION_MAJOR 4) +set(SR_LIB_VERSION_MINOR 0) +set(SR_LIB_VERSION_PATCH 0) +set(CONF_HOST "${CMAKE_SYSTEM_PROCESSOR}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}") + +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + +include(CheckIncludeFile) +# Check for the existence of the header files +check_include_file("inttypes.h" HAVE_INTTYPES_H) +check_include_file("stdint.h" HAVE_STDINT_H) +check_include_file("stdio.h" HAVE_STDIO_H) +check_include_file("stdlib.h" HAVE_STDLIB_H) +check_include_file("strings.h" HAVE_STRINGS_H) +check_include_file("string.h" HAVE_STRING_H) +check_include_file("sys/stat.h" HAVE_SYS_STAT_H) +check_include_file("sys/types.h" HAVE_SYS_TYPES_H) +check_include_file("unistd.h" HAVE_UNISTD_H) +check_include_file("dlfcn.h" HAVE_DLFCN_H) + +configure_file(cmake/config.h.in config.h) +configure_file(cmake/version.h.in version.h) + +# Source files +set(LIBSIGROKDECODE_SOURCES + srd.c + session.c + decoder.c + instance.c + log.c + util.c + exception.c + module_sigrokdecode.c + type_decoder.c + error.c + version.c +) + +# Additional headers +set(LIBSIGROKDECODE_HEADERS + libsigrokdecode-internal.h +) + +# Check for Python +find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + +# Check for glib-2.0 +find_package(PkgConfig REQUIRED) +pkg_check_modules(GLIB REQUIRED glib-2.0>=2.3.4) + +# Check for Check (optional) +option(ENABLE_TESTS "Build with tests" ON) +if(ENABLE_TESTS) + enable_testing(true) # must be in the root file! + add_subdirectory(tests) +endif() + +# Check for IRMP (optional) +option(WITH_IRMP "Enable IRMP support" ON) +if(WITH_IRMP) + pkg_check_modules(LIBIRMP REQUIRED) +endif() + +# Set compiler flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wmissing-prototypes -Wshadow -Wformat=2 -Wno-format-nonliteral -Wfloat-equal") +if(WITH_IRMP) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_IRMP") +endif() + +# Build the library +add_library(sigrokdecode SHARED ${LIBSIGROKDECODE_SOURCES} ${LIBSIGROKDECODE_HEADERS}) +target_link_libraries(sigrokdecode ${GLIB_LIBRARIES} ${LIBIRMP_LIBRARIES} ${Python3_LIBRARIES}) +target_include_directories(sigrokdecode PRIVATE ${PROJECT_BINARY_DIR} ${GLIB_INCLUDE_DIRS} ${LIBIRMP_INCLUDE_DIRS}) # for config.h +target_include_directories(sigrokdecode PUBLIC ${Python3_INCLUDE_DIRS}) # TODO: why this must be PUBLIC? +target_include_directories(sigrokdecode PUBLIC ${PROJECT_SOURCE_DIR}) +target_sources(sigrokdecode PUBLIC + FILE_SET HEADERS + BASE_DIRS ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR} + TYPE HEADERS + FILES ${PROJECT_BINARY_DIR}/version.h libsigrokdecode.h) + +# Install rules +install(TARGETS sigrokdecode DESTINATION lib) +install(TARGETS sigrokdecode FILE_SET HEADERS) + +# Autotools-like configuration summary +message(STATUS "libsigrokdecode configuration summary:") +message(STATUS " - Package version................. ${PROJECT_VERSION}") +message(STATUS " - Library ABI version............. ${SR_LIB_VERSION_MAJOR}:${SR_LIB_VERSION_MINOR}:${SR_LIB_VERSION_PATCH}") +message(STATUS " - Prefix.......................... ${CMAKE_INSTALL_PREFIX}") +message(STATUS " - Building as..................... ${CMAKE_BUILD_TYPE}") +message(STATUS " - Building for.................... ${CONF_HOST}") +#message(STATUS " - Building shared / static........ ON / OFF") + +# Display additional configuration information +message(STATUS "Compile configuration:") +message(STATUS " - C compiler...................... ${CMAKE_C_COMPILER}") +message(STATUS " - C compiler version.............. ${CMAKE_C_COMPILER_VERSION}") +message(STATUS " - C compiler flags................ ${CMAKE_C_FLAGS}") +message(STATUS "Detected libraries (required):") +message(STATUS " - glib-2.0........................ ${GLIB_VERSION}") +if(WITH_IRMP) + message(STATUS " - IRMP support library............ ${LIBIRMP_VERSION}") +endif() + +if(WITH_CHECK) + message(STATUS "Optional features:") + message(STATUS " - Check unit testing framework... ENABLED") +endif() + diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 00000000..5ddc79d5 --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,89 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define if building universal (internal helper macro) */ +#undef AC_APPLE_UNIVERSAL_BUILD + +/* The canonical host libsigrokdecode will run on. */ +#define CONF_HOST "@CONF_HOST@" + +/* Define to 1 if you have the header file. */ +#define HAVE_DLFCN_H @HAVE_DLFCN_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H @HAVE_INTTYPES_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H @HAVE_STDINT_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDIO_H @HAVE_STDIO_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H @HAVE_STDLIB_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRINGS_H @HAVE_STRINGS_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H @HAVE_STRING_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H @HAVE_UNISTD_H@ + +/* Define to the sub-directory where libtool stores uninstalled libraries. */ +#undef LT_OBJDIR + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "@PROJECT_BUG_URL@" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "@PROJECT_NAME@" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "@PROJECT_PACKAGE_STRING@" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "@PROJECT_NAME@" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "@PROJECT_HOMEPAGE_URL@" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "@PROJECT_VERSION@" + +/* Define to 1 if all of the C90 standard headers exist (not just the ones + required in a freestanding environment). This macro is provided for + backward compatibility; new code need not use it. */ +#undef STDC_HEADERS + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# undef WORDS_BIGENDIAN +# endif +#endif + +/* Number of bits in a file offset, on hosts where this is settable. */ +#undef _FILE_OFFSET_BITS + +/* Define for large files, on AIX-style hosts. */ +#undef _LARGE_FILES + +/* The targeted POSIX standard. */ +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#endif + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const diff --git a/cmake/version.h.in b/cmake/version.h.in new file mode 100644 index 00000000..d3121260 --- /dev/null +++ b/cmake/version.h.in @@ -0,0 +1,70 @@ +/* + * This file is part of the libsigrokdecode project. + * + * Copyright (C) 2010 Uwe Hermann + * Copyright (C) 2012 Bert Vermeulen + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef LIBSIGROKDECODE_VERSION_H +#define LIBSIGROKDECODE_VERSION_H + +/** + * @file + * + * Version number definitions and macros. + */ + +/** + * @ingroup grp_versions + * + * @{ + */ + +/* + * Package version macros (can be used for conditional compilation). + */ + +/** The libsigrokdecode package 'major' version number. */ +#define SRD_PACKAGE_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ + +/** The libsigrokdecode package 'minor' version number. */ +#define SRD_PACKAGE_VERSION_MINOR @PROJECT_VERSION_MINOR@ + +/** The libsigrokdecode package 'micro' version number. */ +#define SRD_PACKAGE_VERSION_MICRO @PROJECT_VERSION_PATCH@ + +/** The libsigrokdecode package version ("major.minor.micro") as string. */ +#define SRD_PACKAGE_VERSION_STRING "@PROJECT_VERSION@-git-@GIT_HASH@" + +/* + * Library/libtool version macros (can be used for conditional compilation). + */ + +/** The libsigrokdecode libtool 'current' version number. */ +#define SRD_LIB_VERSION_CURRENT @SR_LIB_VERSION_MAJOR@ + +/** The libsigrokdecode libtool 'revision' version number. */ +#define SRD_LIB_VERSION_REVISION @SR_LIB_VERSION_MINOR@ + +/** The libsigrokdecode libtool 'age' version number. */ +#define SRD_LIB_VERSION_AGE @SR_LIB_VERSION_PATCH@ + +/** The libsigrokdecode libtool version ("current:revision:age") as string. */ +#define SRD_LIB_VERSION_STRING "@SR_LIB_VERSION_MAJOR@:@SR_LIB_VERSION_MINOR@:@SR_LIB_VERSION_PATCH@" + +/** @} */ + +#endif diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 00000000..ba21a8a9 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,18 @@ +find_package(Check REQUIRED) + +add_executable(MainTest main.c + core.c + decoder.c + inst.c + session.c +) +target_link_libraries(MainTest sigrokdecode check) +target_link_libraries(MainTest ${GLIB_LIBRARIES}) +target_include_directories(MainTest PRIVATE ${GLIB_INCLUDE_DIRS}) +target_include_directories(MainTest PRIVATE ${PROJECT_BINARY_DIR}) # config.h / version.h + +target_compile_definitions(MainTest PRIVATE "-DDECODERS_TESTDIR=\"${PROJECT_SOURCE_DIR}/decoders\"") + +add_test(NAME MainTest COMMAND MainTest) + +