omcproxy: update cmake file
authorÁlvaro Fernández Rojas <[email protected]>
Sun, 19 Oct 2025 18:20:40 +0000 (20:20 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Sun, 19 Oct 2025 18:29:04 +0000 (20:29 +0200)
Now that the minimum cmake version has been bumped, the cmake file can
be modernized a bit. Although it might look like a lot of changes, most of them
are quite straightforward.

Every library is located in a consistent manner (allowing command-line
overrides of library locations, useful for local development, and also makes it
trivial to do static linking, if desired).

The compiler flags have been broken up to have one per line (making it easy in
the future to add/remove flags, which would create a simple one-line diff).

Although it might look like this bumps the C standard level, cmake is actually
smart enough to pick an earlier version if C11 isn't supported by the compiler
(quite unlikely on any versions of gcc currently in use in OpenWrt and even on
old distros).

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
CMakeLists.txt

index b9e59ed5d486fe4c8a4d71adb4044f5628495b76..f17a270144f0bae7260672ae15b1fabcfde6ce0e 100644 (file)
@@ -1,31 +1,49 @@
-cmake_minimum_required(VERSION 3.10)
-
-project(omcproxy C)
-
-set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -std=c99")
-
-add_definitions(-D_GNU_SOURCE -Wall -Wno-gnu)
-
+cmake_minimum_required(VERSION 3.13)
+
+
+# Project Definition
+project(omcproxy LANGUAGES C)
+add_executable(${PROJECT_NAME})
+target_sources(${PROJECT_NAME} PRIVATE
+       src/client.c
+       src/groups.c
+       src/igmp.c
+       src/mld.c
+       src/mrib.c
+       src/omcproxy.c
+       src/proxy.c
+       src/querier.c
+)
+
+
+# Compiler Options
+set_target_properties(${PROJECT_NAME} PROPERTIES C_STANDARD 11)
+target_compile_definitions(${PROJECT_NAME} PRIVATE _GNU_SOURCE)
+target_compile_options(${PROJECT_NAME} PRIVATE -g3)
+target_compile_options(${PROJECT_NAME} PRIVATE -Os)
+target_compile_options(${PROJECT_NAME} PRIVATE -Wall)
+target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
+target_compile_options(${PROJECT_NAME} PRIVATE -Wextra)
+target_compile_options(${PROJECT_NAME} PRIVATE -Werror=implicit-function-declaration)
+target_compile_options(${PROJECT_NAME} PRIVATE -Wformat)
+target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-security)
+target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-nonliteral)
+target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-parameter)
+target_compile_options(${PROJECT_NAME} PRIVATE -Wmissing-declarations)
+
+
+# Libraries
+find_path(ubox_include_dir libubox/uloop.h)
+target_include_directories(${PROJECT_NAME} PRIVATE ${ubox_include_dir})
+find_library(libubox ubox)
+target_link_libraries(${PROJECT_NAME} PRIVATE ${libubox})
+
+
+# Optional Features
 if(${L_LEVEL})
-  add_definitions(-DL_LEVEL=${L_LEVEL})
+       target_compile_definitions(${PROJECT_NAME} PRIVATE L_LEVEL=${L_LEVEL})
 endif(${L_LEVEL})
 
-FIND_PATH(ubox_include_dir libubox/list.h)
-INCLUDE_DIRECTORIES(${ubox_include_dir})
-
-if(WITH_LIBUBOX)
-  add_definitions(-Wextra)
-  set(PLATFORM_LINK ${PLATFORM_LINK} ubox)
-else (WITH_LIBUBOX)
-  add_definitions(-Dtypeof=__typeof)
-  include_directories(BEFORE .)
-  set(PLATFORM_SOURCE ${PLATFORM_SOURCE} libubox/uloop.c libubox/avl.c libubox/blobmsg.c libubox/blob.c)
-endif(WITH_LIBUBOX)
-
-add_executable(omcproxy src/client.c src/mrib.c src/querier.c src/groups.c src/igmp.c src/mld.c src/proxy.c src/omcproxy.c ${PLATFORM_SOURCE})
-target_link_libraries(omcproxy ${PLATFORM_LINK})
-
-install(TARGETS omcproxy DESTINATION sbin/)
-
 
+# Installation
+install(TARGETS ${PROJECT_NAME} DESTINATION sbin/)