2023-08-01 03:01:06 +02:00
|
|
|
cmake_minimum_required (VERSION 3.0...3.27)
|
2024-02-27 00:39:23 +01:00
|
|
|
project (nncmpp VERSION 2.1.1 LANGUAGES C)
|
2016-10-06 03:27:29 +02:00
|
|
|
|
|
|
|
# Moar warnings
|
2018-06-24 04:29:06 +02:00
|
|
|
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
2020-10-26 14:11:53 +01:00
|
|
|
set (wdisabled "-Wno-unused-function")
|
2017-06-22 23:17:25 +02:00
|
|
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -Wextra ${wdisabled}")
|
2020-10-29 03:48:57 +01:00
|
|
|
endif ()
|
2016-10-06 03:27:29 +02:00
|
|
|
|
|
|
|
# For custom modules
|
2017-01-23 23:32:30 +01:00
|
|
|
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/liberty/cmake)
|
2016-10-06 03:27:29 +02:00
|
|
|
|
2022-09-12 21:19:55 +02:00
|
|
|
# Collect important build toggles for our simple preprocessor
|
|
|
|
# (cpp(1) isn't part of POSIX, otherwise we could reuse config.h)
|
|
|
|
set (options)
|
|
|
|
macro (add_option variable help value)
|
|
|
|
option (${ARGV})
|
|
|
|
list (APPEND options "${variable}=$<BOOL:${${variable}}>")
|
|
|
|
endmacro ()
|
|
|
|
|
2016-10-06 03:27:29 +02:00
|
|
|
# Dependencies
|
|
|
|
find_package (Ncursesw REQUIRED)
|
|
|
|
find_package (PkgConfig REQUIRED)
|
|
|
|
find_package (Unistring REQUIRED)
|
|
|
|
pkg_check_modules (curl REQUIRED libcurl)
|
|
|
|
|
|
|
|
include (AddThreads)
|
|
|
|
|
|
|
|
find_package (Termo QUIET NO_MODULE)
|
2022-09-12 21:19:55 +02:00
|
|
|
add_option (USE_SYSTEM_TERMO
|
2023-06-09 17:44:20 +02:00
|
|
|
"Don't compile our own termo library, use the system one" "${Termo_FOUND}")
|
2016-10-06 03:27:29 +02:00
|
|
|
if (USE_SYSTEM_TERMO)
|
|
|
|
if (NOT Termo_FOUND)
|
|
|
|
message (FATAL_ERROR "System termo library not found")
|
2021-10-30 01:38:32 +02:00
|
|
|
endif ()
|
2020-10-29 03:48:57 +01:00
|
|
|
else ()
|
2021-10-27 19:48:47 +02:00
|
|
|
# We don't want the library to install, but EXCLUDE_FROM_ALL ignores tests
|
2016-10-06 03:27:29 +02:00
|
|
|
add_subdirectory (termo EXCLUDE_FROM_ALL)
|
2021-10-27 19:48:47 +02:00
|
|
|
file (WRITE ${PROJECT_BINARY_DIR}/CTestCustom.cmake
|
|
|
|
"execute_process (COMMAND ${CMAKE_COMMAND} --build termo)")
|
|
|
|
|
|
|
|
# We don't have many good choices; this is a relatively clean approach
|
|
|
|
# (other possibilities: setting a variable in the parent scope, using
|
|
|
|
# a cache variable, writing a special config file with build paths in it
|
|
|
|
# and including it here, or setting a custom property on the targets)
|
2016-10-06 03:27:29 +02:00
|
|
|
get_directory_property (Termo_INCLUDE_DIRS
|
|
|
|
DIRECTORY termo INCLUDE_DIRECTORIES)
|
|
|
|
set (Termo_LIBRARIES termo-static)
|
2020-10-29 03:48:57 +01:00
|
|
|
endif ()
|
2016-10-06 03:27:29 +02:00
|
|
|
|
2021-07-03 23:58:05 +02:00
|
|
|
pkg_check_modules (fftw fftw3 fftw3f)
|
2023-06-09 17:44:20 +02:00
|
|
|
add_option (WITH_FFTW
|
|
|
|
"Use FFTW to enable spectrum visualisation" "${fftw_FOUND}")
|
2021-07-03 23:58:05 +02:00
|
|
|
if (WITH_FFTW)
|
|
|
|
if (NOT fftw_FOUND)
|
|
|
|
message (FATAL_ERROR "FFTW not found")
|
2021-10-30 01:38:32 +02:00
|
|
|
endif ()
|
2021-11-07 15:47:41 +01:00
|
|
|
list (APPEND extra_libraries ${fftw_LIBRARIES})
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
pkg_check_modules (libpulse libpulse)
|
2022-09-12 21:19:55 +02:00
|
|
|
add_option (WITH_PULSE
|
2023-06-09 17:44:20 +02:00
|
|
|
"Enable PulseAudio sink volume control" "${libpulse_FOUND}")
|
2021-11-07 15:47:41 +01:00
|
|
|
if (WITH_PULSE)
|
|
|
|
if (NOT libpulse_FOUND)
|
|
|
|
message (FATAL_ERROR "libpulse not found")
|
|
|
|
endif ()
|
|
|
|
list (APPEND extra_libraries ${libpulse_LIBRARIES})
|
2021-07-03 23:58:05 +02:00
|
|
|
endif ()
|
|
|
|
|
2024-02-10 10:09:32 +01:00
|
|
|
pkg_check_modules (x11 x11 xrender xft fontconfig libpng)
|
2023-06-17 21:47:12 +02:00
|
|
|
add_option (WITH_X11 "Build with X11 support" "${x11_FOUND}")
|
2022-08-18 01:43:41 +02:00
|
|
|
if (WITH_X11)
|
|
|
|
if (NOT x11_FOUND)
|
|
|
|
message (FATAL_ERROR "Some X11 libraries were not found")
|
|
|
|
endif ()
|
|
|
|
list (APPEND extra_libraries ${x11_LIBRARIES})
|
|
|
|
endif ()
|
|
|
|
|
2020-10-10 21:31:31 +02:00
|
|
|
include_directories (${Unistring_INCLUDE_DIRS}
|
2021-07-03 23:58:05 +02:00
|
|
|
${Ncursesw_INCLUDE_DIRS} ${Termo_INCLUDE_DIRS} ${curl_INCLUDE_DIRS}
|
2022-08-18 01:43:41 +02:00
|
|
|
${fftw_INCLUDE_DIRS} ${libpulse_INCLUDE_DIRS} ${x11_INCLUDE_DIRS})
|
2021-11-07 15:47:41 +01:00
|
|
|
link_directories (${curl_LIBRARY_DIRS}
|
2022-08-18 01:43:41 +02:00
|
|
|
${fftw_LIBRARY_DIRS} ${libpulse_LIBRARY_DIRS} ${x11_LIBRARY_DIRS})
|
2016-10-06 03:27:29 +02:00
|
|
|
|
|
|
|
# Configuration
|
2020-10-29 03:46:39 +01:00
|
|
|
if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
|
|
|
|
# Need this for SIGWINCH in FreeBSD and OpenBSD respectively;
|
|
|
|
# our POSIX version macros make it undefined
|
|
|
|
add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
|
2021-11-02 17:17:32 +01:00
|
|
|
elseif (APPLE)
|
|
|
|
add_definitions (-D_DARWIN_C_SOURCE)
|
2020-10-29 03:46:39 +01:00
|
|
|
endif ()
|
|
|
|
|
2021-10-30 01:38:32 +02:00
|
|
|
include (CheckFunctionExists)
|
|
|
|
set (CMAKE_REQUIRED_LIBRARIES ${Ncursesw_LIBRARIES})
|
|
|
|
CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
|
|
|
|
|
2021-07-03 23:58:05 +02:00
|
|
|
# -lm may or may not be a part of libc
|
|
|
|
foreach (extra m)
|
|
|
|
find_library (extra_lib_${extra} ${extra})
|
|
|
|
if (extra_lib_${extra})
|
|
|
|
list (APPEND extra_libraries ${extra_lib_${extra}})
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
|
2016-10-06 03:27:29 +02:00
|
|
|
# Generate a configuration file
|
2022-09-18 09:15:23 +02:00
|
|
|
include (GNUInstallDirs)
|
2016-10-06 03:27:29 +02:00
|
|
|
configure_file (${PROJECT_SOURCE_DIR}/config.h.in
|
|
|
|
${PROJECT_BINARY_DIR}/config.h)
|
|
|
|
include_directories (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
|
|
|
|
|
2021-11-16 03:33:54 +01:00
|
|
|
set (actions_list ${PROJECT_SOURCE_DIR}/nncmpp.actions)
|
2022-09-12 21:19:55 +02:00
|
|
|
set (actions_awk ${PROJECT_SOURCE_DIR}/nncmpp.actions.awk)
|
2021-11-08 02:13:57 +01:00
|
|
|
set (actions ${PROJECT_BINARY_DIR}/nncmpp-actions.h)
|
|
|
|
add_custom_command (OUTPUT ${actions}
|
2022-09-12 21:19:55 +02:00
|
|
|
COMMAND env LC_ALL=C ${options}
|
|
|
|
awk -f ${actions_awk} ${actions_list} > ${actions}
|
|
|
|
DEPENDS ${actions_awk} ${actions_list} VERBATIM)
|
2021-11-08 02:13:57 +01:00
|
|
|
|
2016-10-06 03:27:29 +02:00
|
|
|
# Build the main executable and link it
|
2021-11-08 02:13:57 +01:00
|
|
|
add_executable (${PROJECT_NAME} ${PROJECT_NAME}.c ${actions})
|
2020-10-10 21:31:31 +02:00
|
|
|
target_link_libraries (${PROJECT_NAME} ${Unistring_LIBRARIES}
|
2024-04-10 17:31:40 +02:00
|
|
|
${Ncursesw_LIBRARIES} ${Termo_LIBRARIES} ${curl_LIBRARIES}
|
|
|
|
${extra_libraries})
|
2016-10-06 03:27:29 +02:00
|
|
|
add_threads (${PROJECT_NAME})
|
|
|
|
|
2016-10-09 15:47:25 +02:00
|
|
|
# Installation
|
2016-10-06 03:27:29 +02:00
|
|
|
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
|
|
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
2020-11-05 01:44:53 +01:00
|
|
|
install (DIRECTORY contrib DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
|
2024-02-25 05:13:37 +01:00
|
|
|
install (DIRECTORY info DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}
|
|
|
|
USE_SOURCE_PERMISSIONS)
|
2023-06-15 15:44:00 +02:00
|
|
|
if (WITH_X11)
|
2024-02-10 05:44:08 +01:00
|
|
|
include (IconUtils)
|
|
|
|
|
|
|
|
set (icon_base ${PROJECT_BINARY_DIR}/icons)
|
|
|
|
set (icon_png_list)
|
|
|
|
foreach (icon_size 16 32 48)
|
|
|
|
icon_to_png (${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.svg
|
|
|
|
${icon_size} ${icon_base} icon_png)
|
|
|
|
list (APPEND icon_png_list ${icon_png})
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
add_custom_target (icons ALL DEPENDS ${icon_png_list})
|
|
|
|
|
2023-06-15 15:44:00 +02:00
|
|
|
install (FILES ${PROJECT_NAME}.svg
|
|
|
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
|
2024-02-10 05:44:08 +01:00
|
|
|
install (DIRECTORY ${icon_base}
|
|
|
|
DESTINATION ${CMAKE_INSTALL_DATADIR})
|
2023-06-15 15:44:00 +02:00
|
|
|
install (FILES ${PROJECT_NAME}.desktop
|
|
|
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
|
|
|
|
endif ()
|
2016-10-06 03:27:29 +02:00
|
|
|
|
2020-10-26 13:24:46 +01:00
|
|
|
# Generate documentation from text markup
|
|
|
|
find_program (ASCIIDOCTOR_EXECUTABLE asciidoctor)
|
2022-08-23 22:32:45 +02:00
|
|
|
find_program (A2X_EXECUTABLE a2x)
|
|
|
|
if (NOT ASCIIDOCTOR_EXECUTABLE AND NOT A2X_EXECUTABLE)
|
2022-09-25 21:14:36 +02:00
|
|
|
message (WARNING "Neither asciidoctor nor a2x were found, "
|
|
|
|
"falling back to a substandard manual page generator")
|
2020-10-29 03:48:57 +01:00
|
|
|
endif ()
|
2016-10-09 15:47:25 +02:00
|
|
|
|
|
|
|
foreach (page ${PROJECT_NAME})
|
|
|
|
set (page_output "${PROJECT_BINARY_DIR}/${page}.1")
|
|
|
|
list (APPEND project_MAN_PAGES "${page_output}")
|
2022-08-23 22:32:45 +02:00
|
|
|
if (ASCIIDOCTOR_EXECUTABLE)
|
|
|
|
add_custom_command (OUTPUT ${page_output}
|
|
|
|
COMMAND ${ASCIIDOCTOR_EXECUTABLE} -b manpage
|
|
|
|
-a release-version=${PROJECT_VERSION}
|
|
|
|
-o "${page_output}"
|
|
|
|
"${PROJECT_SOURCE_DIR}/${page}.adoc"
|
|
|
|
DEPENDS ${page}.adoc
|
|
|
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
|
|
|
elseif (A2X_EXECUTABLE)
|
|
|
|
add_custom_command (OUTPUT ${page_output}
|
|
|
|
COMMAND ${A2X_EXECUTABLE} --doctype manpage --format manpage
|
|
|
|
-a release-version=${PROJECT_VERSION}
|
|
|
|
-D "${PROJECT_BINARY_DIR}"
|
|
|
|
"${PROJECT_SOURCE_DIR}/${page}.adoc"
|
|
|
|
DEPENDS ${page}.adoc
|
|
|
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
2022-09-25 21:14:36 +02:00
|
|
|
else ()
|
|
|
|
set (ASCIIMAN ${PROJECT_SOURCE_DIR}/liberty/tools/asciiman.awk)
|
|
|
|
add_custom_command (OUTPUT ${page_output}
|
2022-09-30 18:22:28 +02:00
|
|
|
COMMAND env LC_ALL=C asciidoc-release-version=${PROJECT_VERSION}
|
|
|
|
awk -f ${ASCIIMAN} "${PROJECT_SOURCE_DIR}/${page}.adoc"
|
|
|
|
> ${page_output}
|
2022-09-25 21:14:36 +02:00
|
|
|
DEPENDS ${page}.adoc ${ASCIIMAN}
|
|
|
|
COMMENT "Generating man page for ${page}" VERBATIM)
|
2022-08-23 22:32:45 +02:00
|
|
|
endif ()
|
2020-10-29 03:48:57 +01:00
|
|
|
endforeach ()
|
2016-10-09 15:47:25 +02:00
|
|
|
|
|
|
|
add_custom_target (docs ALL DEPENDS ${project_MAN_PAGES})
|
|
|
|
|
|
|
|
foreach (page ${project_MAN_PAGES})
|
|
|
|
string (REGEX MATCH "\\.([0-9])$" manpage_suffix "${page}")
|
|
|
|
install (FILES "${page}"
|
|
|
|
DESTINATION "${CMAKE_INSTALL_MANDIR}/man${CMAKE_MATCH_1}")
|
2020-10-29 03:48:57 +01:00
|
|
|
endforeach ()
|
2016-10-09 15:47:25 +02:00
|
|
|
|
2023-06-15 15:44:00 +02:00
|
|
|
# Testing
|
|
|
|
option (BUILD_TESTING "Build tests" OFF)
|
|
|
|
if (BUILD_TESTING)
|
|
|
|
enable_testing ()
|
|
|
|
|
|
|
|
find_program (xmlwf_EXECUTABLE xmlwf)
|
|
|
|
find_program (xmllint_EXECUTABLE xmllint)
|
|
|
|
foreach (xml ${PROJECT_NAME}.svg)
|
|
|
|
if (xmlwf_EXECUTABLE)
|
|
|
|
add_test (test-xmlwf-${xml} ${xmlwf_EXECUTABLE}
|
|
|
|
${PROJECT_SOURCE_DIR}/${xml})
|
|
|
|
endif ()
|
|
|
|
if (xmllint_EXECUTABLE)
|
|
|
|
add_test (test-xmllint-${xml} ${xmllint_EXECUTABLE} --noout
|
|
|
|
${PROJECT_SOURCE_DIR}/${xml})
|
|
|
|
endif ()
|
|
|
|
endforeach ()
|
|
|
|
|
|
|
|
find_program (dfv_EXECUTABLE desktop-file-validate)
|
|
|
|
if (dfv_EXECUTABLE)
|
|
|
|
foreach (df ${PROJECT_NAME}.desktop)
|
|
|
|
add_test (test-dfv-${df} ${dfv_EXECUTABLE}
|
|
|
|
${PROJECT_SOURCE_DIR}/${df})
|
|
|
|
endforeach ()
|
|
|
|
endif ()
|
|
|
|
endif ()
|
|
|
|
|
2016-10-06 03:27:29 +02:00
|
|
|
# CPack
|
2022-08-18 01:43:41 +02:00
|
|
|
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Terminal/X11 MPD client")
|
2020-08-01 14:04:10 +02:00
|
|
|
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
|
|
|
|
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
|
2016-10-06 03:27:29 +02:00
|
|
|
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
|
|
|
set (CPACK_GENERATOR "TGZ;ZIP")
|
|
|
|
set (CPACK_PACKAGE_FILE_NAME
|
2020-10-26 13:16:59 +01:00
|
|
|
"${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
|
|
|
|
set (CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}-${PROJECT_VERSION}")
|
2016-10-06 03:27:29 +02:00
|
|
|
set (CPACK_SOURCE_GENERATOR "TGZ;ZIP")
|
|
|
|
set (CPACK_SOURCE_IGNORE_FILES "/\\\\.git;/build;/CMakeLists.txt.user")
|
2020-10-26 13:16:59 +01:00
|
|
|
set (CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}")
|
2016-10-06 03:27:29 +02:00
|
|
|
|
|
|
|
set (CPACK_SET_DESTDIR TRUE)
|
|
|
|
include (CPack)
|