Files
ptouch-print/CMakeLists.txt
T
Kevin Bradenstein ef6e6f4925 cmake: let the argp probe pass where argp-standalone needs strchrnul
On macOS with Homebrew's argp-standalone, Findargp's link test for
argp_parse fails with an undefined strchrnul, because libargp.a itself
references that GNU extension and the platform has none. The module then
stops with "does not have a symbol named argp_parse", which is not what
is wrong.

Probe for strchrnul first (with _GNU_SOURCE, so glibc answers correctly).
Where it exists, the test is unchanged. Where it is missing, run the same
argp_parse test with a local definition of strchrnul, and have ptouch-print
supply that definition for the real build.

On glibc nothing changes: the probe finds strchrnul and the original test
runs. Checked on Debian stable in the same session.
2026-09-08 07:16:31 +02:00

85 lines
2.0 KiB
CMake

cmake_minimum_required(VERSION 3.15)
project(ptouch-print C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(GNUInstallDirs)
set(CMAKE_INSTALL_PREFIX /usr)
set(CMAKE_C_STANDARD 11)
# Configure required dependencies
find_package(Gettext REQUIRED)
find_package(GD REQUIRED)
find_package(Git REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(Intl REQUIRED)
find_package(argp REQUIRED)
if(NOT ARGP_IN_LIBC AND NOT HAVE_STRCHRNUL)
# See cmake/Findargp.cmake: argp-standalone needs a strchrnul() the
# platform does not have, so ptouch-print.c defines one.
add_compile_definitions(NEED_STRCHRNUL=1)
endif()
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
# Configure project executable
add_executable(${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_BINARY_DIR} # HB9HEI - location of generated version.h
${CMAKE_SOURCE_DIR}/include
${GD_INCLUDE_DIR}
${LIBUSB_INCLUDE_DIRS}
${Intl_INCLUDE_DIRS}
${ARGP_INCLUDE_DIR}
)
target_link_libraries(${PROJECT_NAME} PRIVATE
${GD_LIBRARIES}
${LIBUSB_LINK_LIBRARIES}
${Intl_LIBRARIES}
${ARGP_LIBRARIES}
)
target_sources(${PROJECT_NAME} PRIVATE
include/ptouch.h
src/libptouch.c
src/ptouch-print.c
)
add_dependencies(${PROJECT_NAME}
git-version
)
target_compile_definitions(${PROJECT_NAME} PUBLIC
LOCALEDIR="${CMAKE_INSTALL_LOCALEDIR}"
USING_CMAKE=1
PACKAGE="ptouch-print"
)
target_compile_options(${PROJECT_NAME} PUBLIC
-g
-Wall
-Wextra
-Wunused
-O3
-fPIC
)
# HB9HEI - custom target that produces version.h (req. cmake 3.0)
add_custom_target(git-version ALL
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/gitversion.cmake
)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gettext.cmake)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/ptouch-print.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
if(EXISTS /etc/udev/rules.d)
install(FILES udev/20-usb-ptouch-permissions.rules DESTINATION /etc/udev/rules.d)
install(CODE "execute_process(COMMAND udevadm control --reload-rules)")
endif()