Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmake support #110

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ stamp-h?
/tests/*.log
/tests/*.trs
/tests/main
CMakeLists.txt.user
126 changes: 126 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "[email protected]")
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()

89 changes: 89 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -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 <dlfcn.h> header file. */
#define HAVE_DLFCN_H @HAVE_DLFCN_H@

/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H @HAVE_INTTYPES_H@

/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H @HAVE_STDINT_H@

/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H @HAVE_STDIO_H@

/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H @HAVE_STDLIB_H@

/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H @HAVE_STRINGS_H@

/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H @HAVE_STRING_H@

/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@

/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@

/* Define to 1 if you have the <unistd.h> 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
70 changes: 70 additions & 0 deletions cmake/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* This file is part of the libsigrokdecode project.
*
* Copyright (C) 2010 Uwe Hermann <[email protected]>
* Copyright (C) 2012 Bert Vermeulen <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#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
18 changes: 18 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)