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 possibility to build with cmake #11

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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 @@ -28,3 +28,4 @@
/sigrok-cli-*.tar.*
/sigrok-cli.exe
/stamp-h?
CMakeLists.txt.user
114 changes: 114 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
cmake_minimum_required(VERSION 3.1)

project(sigrok-cli
VERSION 0.8.0
HOMEPAGE_URL "http://www.sigrok.org")

set(PROJECT_BUG_URL "[email protected]")
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
)

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

# Include directories
include_directories(${SIGROK_CLI_INCLUDE_DIRS})

# 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})
target_include_directories(sigrok-cli PRIVATE "/home/martin/GIT/SigrokInstall/include")

# libsigrokdecode
option(LOCAL_LIBSIGROKDECODE "Use local libsigrokdecode" false)
if (${LOCAL_LIBSIGROKDECODE})
Include(FetchContent)
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 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})
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()

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)

# 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()

16 changes: 16 additions & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
@@ -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