From 0384976e68391c8f5f13cf7d8a6dd3791af567d3 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 11 Jan 2024 16:06:08 +0100 Subject: [PATCH 1/7] Add possibility to build with cmake --- .gitignore | 1 + CMakeLists.txt | 92 +++++++++++++++++++++++++++++++++++++++++++++++ cmake/config.h.in | 16 +++++++++ 3 files changed, 109 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/config.h.in diff --git a/.gitignore b/.gitignore index d1d8ffc..785ac7f 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ /sigrok-cli-*.tar.* /sigrok-cli.exe /stamp-h? +CMakeLists.txt.user diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3cd00e3 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,92 @@ +cmake_minimum_required(VERSION 3.1) + +project(sigrok-cli + VERSION 0.8.0 + HOMEPAGE_URL "http://www.sigrok.org") + +set(PROJECT_BUG_URL "sigrok-devel@lists.sourceforge.net") +set(PROJECT_PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}") + +execute_process( + COMMAND git log -1 --format=%h + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + OUTPUT_VARIABLE GIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + +# Source files +set(SR_SOURCES + main.c + show.c + device.c + session.c + input.c + output.c + decode.c + sigrok-cli.h + parsers.c + anykey.c + options.c +) + +configure_file(cmake/config.h.in config.h) + +# Find required packages +find_package(PkgConfig REQUIRED) +pkg_check_modules(SIGROK_CLI REQUIRED + glib-2.0>=2.32.0 + libsigrok>=0.5.0 +) + +# Optional dependencies +find_package(libsigrokdecode 0.5.0 QUIET) + +# Compiler flags +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") # Enable C99 standard + +# Include directories +include_directories(${SIGROK_CLI_INCLUDE_DIRS}) +if (libsigrokdecode_FOUND) + include_directories(${LIBSIGROKDECODE_INCLUDE_DIRS}) +endif() + +# Build executable +add_executable(sigrok-cli ${SR_SOURCES}) +target_include_directories(sigrok-cli PRIVATE ${CMAKE_BINARY_DIR}) # config.h + +# Link libraries +target_link_libraries(sigrok-cli ${SIGROK_CLI_LIBRARIES}) +if (libsigrokdecode_FOUND) + target_link_libraries(sigrok-cli ${LIBSIGROKDECODE_LIBRARIES}) +endif() + +# Install executable +install(TARGETS sigrok-cli DESTINATION bin) + +# Install desktop file and icon +install(FILES contrib/org.sigrok.sigrok-cli.desktop DESTINATION share/applications) +install(FILES contrib/sigrok-cli.svg DESTINATION share/icons/hicolor/scalable/apps) + +# Print configuration summary +message("\n--- sigrok-cli configuration summary ---") +message(" - Package version................. ${SC_PACKAGE_VERSION}") +message(" - Prefix.......................... ${CMAKE_INSTALL_PREFIX}") +message(" - Building on..................... ${CMAKE_BUILD_TYPE}") +message(" - Building for.................... ${CMAKE_SYSTEM_PROCESSOR}") + +# Compiler information +message("\nCompile configuration:") +message(" - C compiler...................... ${CMAKE_C_COMPILER}") +message(" - C compiler flags................ ${CMAKE_C_FLAGS}") + +# Detected libraries +message("\nDetected libraries (required):") +message(" - glib-2.0 >= 2.32.0.............. ${SIGROK_CLI_VERSION}") +message(" - libsigrok >= 0.5.0.............. ${SIGROK_CLI_VERSION}") + +if (libsigrokdecode_FOUND) + message("\nDetected libraries (optional):") + message(" - libsigrokdecode >= 0.5.0....... ${LIBSIGROKDECODE_VERSION}") +endif() + diff --git a/cmake/config.h.in b/cmake/config.h.in new file mode 100644 index 0000000..f7b4cdc --- /dev/null +++ b/cmake/config.h.in @@ -0,0 +1,16 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#define PACKAGE_NAME "@PROJECT_NAME@" +#define PACKAGE_STRING "@PROJECT_PACKAGE_STRING@" +#define PACKAGE_TARNAME "@PROJECT_NAME@" +#define PACKAGE_URL "@PROJECT_HOMEPAGE_URL@" +#define PACKAGE_VERSION "@PROJECT_VERSION@" +#define PACKAGE_BUGREPORT "@PROJECT_BUG_URL@" + +#define SC_PACKAGE_VERSION_STRING "@PROJECT_VERSION@-git-@GIT_HASH@" +#define SC_PACKAGE_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define SC_PACKAGE_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define SC_PACKAGE_VERSION_MICRO @PROJECT_VERSION_PATCH@ + +#endif // CONFIG_H From 0697deee5bea9df087c33ab64101e13b9e571170 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 11 Jan 2024 16:21:11 +0100 Subject: [PATCH 2/7] Implement correct finding of libsigrokdecode --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cd00e3..ebdc3ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,14 +40,17 @@ pkg_check_modules(SIGROK_CLI REQUIRED ) # Optional dependencies -find_package(libsigrokdecode 0.5.0 QUIET) +pkg_check_modules(LIBSIGROKDECODE + libsigrokdecode>=0.5.0 +) # Compiler flags set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") # Enable C99 standard # Include directories include_directories(${SIGROK_CLI_INCLUDE_DIRS}) -if (libsigrokdecode_FOUND) +if (LIBSIGROKDECODE_FOUND) + add_definitions("-DHAVE_SRD") include_directories(${LIBSIGROKDECODE_INCLUDE_DIRS}) endif() @@ -57,7 +60,7 @@ target_include_directories(sigrok-cli PRIVATE ${CMAKE_BINARY_DIR}) # config.h # Link libraries target_link_libraries(sigrok-cli ${SIGROK_CLI_LIBRARIES}) -if (libsigrokdecode_FOUND) +if (LIBSIGROKDECODE_FOUND) target_link_libraries(sigrok-cli ${LIBSIGROKDECODE_LIBRARIES}) endif() From efe2a5e09fb1b1a01cc045afbab30dc00c5c6431 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 11 Jan 2024 16:28:23 +0100 Subject: [PATCH 3/7] fix variable name --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ebdc3ec..2b18421 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,7 +88,7 @@ message("\nDetected libraries (required):") message(" - glib-2.0 >= 2.32.0.............. ${SIGROK_CLI_VERSION}") message(" - libsigrok >= 0.5.0.............. ${SIGROK_CLI_VERSION}") -if (libsigrokdecode_FOUND) +if (LIBSIGROKDECODE_FOUND) message("\nDetected libraries (optional):") message(" - libsigrokdecode >= 0.5.0....... ${LIBSIGROKDECODE_VERSION}") endif() From 516f9a645f05ce23939aeb21d59aad446b570167 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 11 Jan 2024 18:41:18 +0100 Subject: [PATCH 4/7] add possibility to use local version of libsigrokdecode --- CMakeLists.txt | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b18421..bee9346 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,20 +39,11 @@ pkg_check_modules(SIGROK_CLI REQUIRED libsigrok>=0.5.0 ) -# Optional dependencies -pkg_check_modules(LIBSIGROKDECODE - libsigrokdecode>=0.5.0 -) - # Compiler flags set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") # Enable C99 standard # Include directories include_directories(${SIGROK_CLI_INCLUDE_DIRS}) -if (LIBSIGROKDECODE_FOUND) - add_definitions("-DHAVE_SRD") - include_directories(${LIBSIGROKDECODE_INCLUDE_DIRS}) -endif() # Build executable add_executable(sigrok-cli ${SR_SOURCES}) @@ -60,8 +51,28 @@ target_include_directories(sigrok-cli PRIVATE ${CMAKE_BINARY_DIR}) # config.h # Link libraries target_link_libraries(sigrok-cli ${SIGROK_CLI_LIBRARIES}) -if (LIBSIGROKDECODE_FOUND) - target_link_libraries(sigrok-cli ${LIBSIGROKDECODE_LIBRARIES}) + +# libsigrokdecode +option(LOCAL_LIBSIGROKDECODE "Use local libsigrokdecode" false) +if (${LOCAL_LIBSIGROKDECODE}) + Include(FetchContent) + FetchContent_Declare(libsigrokdecode + GIT_REPOSITORY https://github.com/Murmele/libsigrokdecode.git + GIT_TAG master + ) + FetchContent_MakeAvailable(libsigrokdecode) # name of the target in the CMakeLists.txt + target_include_directories(sigrok-cli PRIVATE ${libsigrokdecode_SOURCE_DIR}) + target_link_libraries(sigrok-cli sigrokdecode) + target_compile_definitions(sigrok-cli PRIVATE "-DHAVE_SRD") +else() + pkg_check_modules(LIBSIGROKDECODE + libsigrokdecode>=0.5.0 + ) + if (LIBSIGROKDECODE_FOUND) + target_link_libraries(sigrok-cli ${LIBSIGROKDECODE_LIBRARIES}) + target_compile_definitions(sigrok-cli PRIVATE "-DHAVE_SRD") + target_include_directories(sigrok-cli PRIVATE ${LIBSIGROKDECODE_INCLUDE_DIRS}) + endif() endif() # Install executable From 54afc2ac5943d844c3023d78d15b5f0222356d7b Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 11 Jan 2024 18:42:06 +0100 Subject: [PATCH 5/7] Add note --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bee9346..2e281ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,8 @@ option(LOCAL_LIBSIGROKDECODE "Use local libsigrokdecode" false) if (${LOCAL_LIBSIGROKDECODE}) Include(FetchContent) FetchContent_Declare(libsigrokdecode - GIT_REPOSITORY https://github.com/Murmele/libsigrokdecode.git + # GIT_REPOSITORY https://github.com/sigrokproject/libsigrokdecode.git + GIT_REPOSITORY https://github.com/Murmele/libsigrokdecode.git # TODO: remove as soon as libsigrokdecode supports cmake! GIT_TAG master ) FetchContent_MakeAvailable(libsigrokdecode) # name of the target in the CMakeLists.txt From 3b43b73d1bb42c1003fcc84cf0eb32825dcacb19 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Wed, 31 Jan 2024 19:15:46 +0100 Subject: [PATCH 6/7] Add comment --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e281ff..4b2a0cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,7 @@ if (${LOCAL_LIBSIGROKDECODE}) FetchContent_Declare(libsigrokdecode # GIT_REPOSITORY https://github.com/sigrokproject/libsigrokdecode.git GIT_REPOSITORY https://github.com/Murmele/libsigrokdecode.git # TODO: remove as soon as libsigrokdecode supports cmake! - GIT_TAG master + GIT_TAG cmake # GIT_TAG master TODO: change when merged ) FetchContent_MakeAvailable(libsigrokdecode) # name of the target in the CMakeLists.txt target_include_directories(sigrok-cli PRIVATE ${libsigrokdecode_SOURCE_DIR}) From 4fd2d6ea8275a75fddb00bd73a9be8f12198a277 Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Thu, 4 Jul 2024 21:46:32 +0200 Subject: [PATCH 7/7] WIP --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b2a0cd..235eed2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,9 +36,12 @@ configure_file(cmake/config.h.in config.h) find_package(PkgConfig REQUIRED) pkg_check_modules(SIGROK_CLI REQUIRED glib-2.0>=2.32.0 - libsigrok>=0.5.0 + #libsigrok>=0.5.0 ) +list(APPEND CMAKE_PREFIX_PATH "/home/martin/GIT/SigrokInstall/lib/libsigrok") +#set(SIGROK_CLI_INCLUDE_DIRS ${SIGROK_CLI_INCLUDE_DIRS} "/home/martin/GIT/SigrokInstall/include" "/home/martin/GIT/SigrokInstall/include/libsigrok" "/home/martin/GIT/SigrokInstall/include/libsigrokcxx") + # Compiler flags set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99") # Enable C99 standard @@ -51,6 +54,7 @@ target_include_directories(sigrok-cli PRIVATE ${CMAKE_BINARY_DIR}) # config.h # Link libraries target_link_libraries(sigrok-cli ${SIGROK_CLI_LIBRARIES}) +target_include_directories(sigrok-cli PRIVATE "/home/martin/GIT/SigrokInstall/include") # libsigrokdecode option(LOCAL_LIBSIGROKDECODE "Use local libsigrokdecode" false) @@ -76,6 +80,9 @@ else() endif() endif() +link_directories(BEFORE "/home/martin/GIT/SigrokInstall/lib") +target_link_libraries(sigrok-cli "/home/martin/GIT/SigrokInstall/lib/libsigrok.so") + # Install executable install(TARGETS sigrok-cli DESTINATION bin)