Skip to content

Add a CMakeLists.txt #1

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

Open
wants to merge 1 commit 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 @@ -8,3 +8,4 @@ streamdeckpp.sublime-project
streamdeckpp.sublime-workspace
streamdeckpp-*.tar.xz
streamdeckpp.spec
build/
73 changes: 73 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
cmake_minimum_required(VERSION 3.16)
project(streamdeckpp VERSION 1.8 LANGUAGES CXX)

# --- Options ---
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(ABI 1)
set(PUBLIC_HEADER streamdeckpp.hh)

# --- Find dependencies using pkg-config ---
find_package(PkgConfig REQUIRED)
pkg_check_modules(HIDAPI REQUIRED IMPORTED_TARGET hidapi-libusb)
pkg_check_modules(MAGICKPP REQUIRED IMPORTED_TARGET Magick++)

# --- Include directories ---
include_directories(
${HIDAPI_INCLUDE_DIRS}
${MAGICKPP_INCLUDE_DIRS}
)

# --- Sources ---
set(LIB_SRCS streamdeckpp.cc)
set(MAIN_SRCS main.cc)

# --- Static Library ---
add_library(streamdeckpp_static STATIC ${LIB_SRCS})
target_link_libraries(streamdeckpp_static PUBLIC PkgConfig::HIDAPI PkgConfig::MAGICKPP)
set_target_properties(streamdeckpp_static PROPERTIES OUTPUT_NAME streamdeckpp)
target_include_directories(streamdeckpp_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# --- Shared Library ---
add_library(streamdeckpp SHARED streamdeckpp.cc)
target_link_libraries(streamdeckpp PUBLIC PkgConfig::HIDAPI PkgConfig::MAGICKPP)
set_target_properties(streamdeckpp PROPERTIES
SOVERSION ${ABI}
VERSION ${PROJECT_VERSION}
OUTPUT_NAME streamdeckpp
PUBLIC_HEADER ${PUBLIC_HEADER}
)
# Optionally add linker script if needed
target_link_options(streamdeckpp PRIVATE LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/libstreamdeckpp.map)

# --- Executable ---
add_executable(streamdeck ${MAIN_SRCS})
target_link_libraries(streamdeck PRIVATE streamdeckpp_static)
target_include_directories(streamdeck PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

# --- Install Rules ---
include(GNUInstallDirs)

install(TARGETS streamdeckpp streamdeckpp_static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/streamdeckpp-${PROJECT_VERSION}
)

install(TARGETS streamdeck
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES ${PUBLIC_HEADER} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/streamdeckpp-${PROJECT_VERSION})

# --- pkg-config file generation ---
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/streamdeckpp.spec.in
${CMAKE_CURRENT_BINARY_DIR}/streamdeckpp.pc
@ONLY
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/streamdeckpp.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

# --- Clean/dist targets (CMake handles most) ---

# --- Custom targets for rpm, srpm, dist (optional, not implemented here) ---
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ The provided `read` interface returns a vector with the current state of the but
`read` interface is delayed until a button a pressed or released. The `read` variant with a `timeout`\
parameter returns an `optional` object which, in case the timeout is reached, contains nothing.

Debian/Ubuntu dependencies
--------------------------
```
$ sudo apt-get install libmagick++-dev libhidapi-dev
```

Using the library
-----------------
Expand Down
2 changes: 1 addition & 1 deletion main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main(int argc, char* argv[])

if ("image"s == argv[1]) {
int key = argc <= 2 ? 0 : atoi(argv[2]);
const char* fname = argc <= 3 ? "test.jpg" : argv[3];
const char* fname = argc <= 3 ? "cat-eye.jpg" : argv[3];
ctx[i]->set_key_image(key, fname);
} else if ("reset"s == argv[1])
ctx[i]->reset();
Expand Down