aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2022-01-13 11:19:50 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2022-01-27 09:28:42 +0100
commite626adea1ad5be2565164c5059f8d02c81f57c87 (patch)
treee4d1daf8ecbff8ed7645ca8e16afa23f11a68f90
parentf9e30ebde987f006686555bbab219bc6fb01d156 (diff)
downloadayatana-indicator-notifications-e626adea1ad5be2565164c5059f8d02c81f57c87.tar.gz
ayatana-indicator-notifications-e626adea1ad5be2565164c5059f8d02c81f57c87.tar.bz2
ayatana-indicator-notifications-e626adea1ad5be2565164c5059f8d02c81f57c87.zip
Use Ayatana-style CMakeList + clean up compilation flags
-rw-r--r--CMakeLists.txt53
-rw-r--r--src/CMakeLists.txt16
2 files changed, 40 insertions, 29 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 90b79bd..d11322d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,32 @@
project(ayatana-indicator-notifications C CXX)
-cmake_minimum_required(VERSION 2.8.9)
-
-list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
+cmake_minimum_required(VERSION 3.13)
set(PROJECT_VERSION "0.9.0")
set(PACKAGE ${CMAKE_PROJECT_NAME})
+# Options
+
+option(ENABLE_TESTS "Enable all tests and checks" OFF)
+option(ENABLE_COVERAGE "Enable coverage reports (includes enabling all tests and checks)" OFF)
+option(ENABLE_WERROR "Treat all build warnings as errors" OFF)
+
+if(ENABLE_COVERAGE)
+ set(ENABLE_TESTS ON)
+ set(CMAKE_BUILD_TYPE "Coverage")
+else()
+ set(CMAKE_BUILD_TYPE "Release")
+endif()
+
+if(ENABLE_WERROR)
+ add_definitions("-Werror")
+endif()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ add_definitions("-Weverything")
+else()
+ add_definitions("-Wall")
+endif()
+
##
## GNU standard installation directories
##
@@ -53,20 +74,24 @@ add_custom_target (cppcheck COMMAND cppcheck --enable=all -q --error-exitcode=2
## Actual building
##
-if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
- set(C_WARNING_ARGS "${C_WARNING_ARGS} -Weverything")
- set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-c++98-compat -Wno-padded") # these are annoying
- set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-documentation") # gtk-doc != doxygen
-else()
- set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wall -Wformat=2") # Use -Wextra and -Wpedantic explicitly if needed
-endif()
-set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-missing-field-initializers") # GActionEntry
-
-
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories (${CMAKE_CURRENT_BINARY_DIR}/include)
-# actually build things
add_subdirectory(src)
add_subdirectory(data)
add_subdirectory(po)
+
+if (ENABLE_TESTS)
+ include(CTest)
+ enable_testing()
+
+ if (ENABLE_COVERAGE)
+ find_package(CoverageReport)
+ endif()
+endif()
+
+# Display config info
+
+message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
+message(STATUS "Unit tests: ${ENABLE_TESTS}")
+message(STATUS "Build with -Werror: ${ENABLE_WERROR}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9a19244..5bd56b5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,5 @@
set (SERVICE_LIB "ayatanaindicatornotificationsservice")
set (SERVICE_EXEC "ayatana-indicator-notifications-service")
-
add_definitions(-DG_LOG_DOMAIN="ayatana-indicator-notifications")
# handwritten sources
@@ -10,28 +9,15 @@ set(SERVICE_MANUAL_SOURCES
dbus-spy.c
service.c)
-# generated sources
-include(GdbusCodegen)
-set(SERVICE_GENERATED_SOURCES)
-
# add the bin dir to our include path so the code can find the generated header files
include_directories(${CMAKE_CURRENT_BINARY_DIR})
-
-# add warnings/coverage info on handwritten files
-# but not the autogenerated ones...
-set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-bad-function-cast") # g_clear_object()
-set(C_WARNING_ARGS "${C_WARNING_ARGS} -Wno-switch-enum")
-set_source_files_properties(${SERVICE_MANUAL_SOURCES}
- PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} -g -std=c99")
-
# the service library for tests to link against (basically, everything except main())
-add_library(${SERVICE_LIB} STATIC ${SERVICE_MANUAL_SOURCES} ${SERVICE_GENERATED_SOURCES})
+add_library(${SERVICE_LIB} STATIC ${SERVICE_MANUAL_SOURCES})
include_directories(${CMAKE_SOURCE_DIR})
link_directories(${SERVICE_DEPS_LIBRARY_DIRS})
# the executable: lib + main()
add_executable (${SERVICE_EXEC} main.c)
-set_source_files_properties(${SERVICE_SOURCES} main.c PROPERTIES COMPILE_FLAGS "${C_WARNING_ARGS} -std=c99")
target_link_libraries (${SERVICE_EXEC} ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES})
install (TARGETS ${SERVICE_EXEC} RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_PKGLIBEXECDIR})