<commit_before>cmake_minimum_required(VERSION 2.8)
project(hnetd 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 -Wextra)

if(${L_LEVEL})
	add_definitions(-DL_LEVEL=${L_LEVEL})
endif(${L_LEVEL})


if(${BACKEND} MATCHES "openwrt")
	set(BACKEND_SOURCE "src/platform-openwrt.c")
	set(BACKEND_LINK "ubus")
else(${BACKEND} MATCHES "openwrt")
	set(BACKEND_SOURCE src/platform-generic.c src/ipc.c)
	set(BACKEND_LINK "")
	add_definitions(-DWITH_IPC=1)
        install(PROGRAMS generic/dhcp.script generic/dhcpv6.script DESTINATION share/hnetd/)
        install(PROGRAMS generic/hnetd-backend DESTINATION sbin/)
        # Symlinks for different hnetd aliases
        install(CODE "execute_process(COMMAND ln -s hnetd \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sbin/hnet-ifup)")
        install(CODE "execute_process(COMMAND ln -s hnetd \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sbin/hnet-ifdown)")
        install(CODE "execute_process(COMMAND ln -s hnetd \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sbin/hnet-call)")
endif(${BACKEND} MATCHES "openwrt")

# TODO: split platform logic
set(PA src/pa.c src/pa_data.c src/pa_store.c src/pa_local.c src/pa_core.c)
set(HNCP_NIO_BASE src/hncp.c src/hncp_notify.c src/hncp_proto.c src/hncp_timeout.c src/prefix_utils.c src/tlv.c)
set(HNCP_NIO ${HNCP_NIO_BASE} src/hncp_pa.c src/hncp_sd.c)
set(HNCP ${HNCP_NIO} src/hncp_io.c)
add_executable(hnetd ${HNCP} src/hncp_routing.c src/hnetd.c src/iface.c ${PA} src/pa_store.c ${BACKEND_SOURCE})
target_link_libraries(hnetd ubox blobmsg_json resolv ${BACKEND_LINK})

# Unit test stuff
OPTION(COVERAGE "build with coverage" OFF)

if (${COVERAGE})
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif (${COVERAGE})

# With this, 'make check' works even in a clean tree (sigh, cmake..)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
enable_testing()
include_directories(src)

add_executable(test_dummy test/test_dummy.c)
add_test(dummy test_dummy)
add_dependencies(check test_dummy)

add_executable(test_tlv src/tlv.c test/test_tlv.c)
target_link_libraries(test_tlv ubox ${BACKEND_LINK} blobmsg_json)
add_test(tlv test_tlv)
add_dependencies(check test_tlv)

add_executable(test_hncp ${HNCP} ${PA} src/prefix_utils.c src/tlv.c test/test_hncp.c)
target_link_libraries(test_hncp ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp test_hncp)
add_dependencies(check test_hncp)

add_executable(test_hncp_net ${HNCP_NIO} test/test_hncp_net.c)
target_link_libraries(test_hncp_net ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_net test_hncp_net)
add_dependencies(check test_hncp_net)

add_executable(test_hncp_pa ${HNCP_NIO} test/test_hncp_pa.c)
target_link_libraries(test_hncp_pa ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_pa test_hncp_pa)
add_dependencies(check test_hncp_pa)

add_executable(test_hncp_sd ${HNCP_NIO_BASE} test/test_hncp_sd.c)
target_link_libraries(test_hncp_sd ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_sd test_hncp_sd)
add_dependencies(check test_hncp_sd)

add_executable(test_hncp_nio src/tlv.c test/test_hncp_nio.c src/prefix_utils.c)
target_link_libraries(test_hncp_nio ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_nio test_hncp_nio)
add_dependencies(check test_hncp_nio)

add_executable(test_hncp_bfs test/test_hncp_bfs.c src/hncp.c src/hncp_notify.c src/hncp_timeout.c src/hncp_io.c src/prefix_utils.c src/tlv.c)
target_link_libraries(test_hncp_bfs ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_bfs test_hncp_bfs)
add_dependencies(check test_hncp_bfs)

add_executable(test_prefix_utils src/prefix_utils.c test/test_prefix_utils.c)
add_test(prefix_utils test_prefix_utils)
add_dependencies(check test_prefix_utils)

add_executable(test_pa test/test_pa.c src/pa_store.c src/pa_data.c)
target_link_libraries(test_pa ubox)
add_test(pa test_pa)
add_dependencies(check test_pa)

add_executable(test_iface test/test_iface.c)
target_link_libraries(test_iface ubox)
add_test(iface test_iface)
add_dependencies(check test_iface)

add_executable(test_pa_store test/test_pa_store.c src/pa_data.c src/pa_store.c src/prefix_utils.c)
target_link_libraries(test_pa_store ubox)
add_test(pa_store test_pa_store)
add_dependencies(check test_pa_store)

add_executable(test_pa_data test/test_pa_data.c src/pa_data.c src/prefix_utils.c)
target_link_libraries(test_pa_data ubox)
add_test(pa_data test_pa_data)
add_dependencies(check test_pa_data)

# Installation rules
install(TARGETS hnetd DESTINATION sbin/)

# Packaging rules
set(CPACK_PACKAGE_VERSION "1")
set(CPACK_PACKAGE_CONTACT "<NAME> <<EMAIL>>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "hnetd")
set(CPACK_GENERATOR "DEB;RPM;STGZ")
set(CPACK_STRIP_FILES true)

SET(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}")

include(CPack)<commit_msg>Committed some serious atrocities to make most object files be built only once. Stupid cmake.<commit_after>cmake_minimum_required(VERSION 2.8)
project(hnetd 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 -Wextra)

if(${L_LEVEL})
	add_definitions(-DL_LEVEL=${L_LEVEL})
endif(${L_LEVEL})


if(${BACKEND} MATCHES "openwrt")
	set(BACKEND_SOURCE "src/platform-openwrt.c")
	set(BACKEND_LINK "ubus")
else(${BACKEND} MATCHES "openwrt")
	set(BACKEND_SOURCE src/platform-generic.c src/ipc.c)
	set(BACKEND_LINK "")
	add_definitions(-DWITH_IPC=1)
        install(PROGRAMS generic/dhcp.script generic/dhcpv6.script DESTINATION share/hnetd/)
        install(PROGRAMS generic/hnetd-backend DESTINATION sbin/)
        # Symlinks for different hnetd aliases
        install(CODE "execute_process(COMMAND ln -s hnetd \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sbin/hnet-ifup)")
        install(CODE "execute_process(COMMAND ln -s hnetd \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sbin/hnet-ifdown)")
        install(CODE "execute_process(COMMAND ln -s hnetd \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/sbin/hnet-call)")
endif(${BACKEND} MATCHES "openwrt")

# TODO: split platform logic
add_library(L_PU OBJECT src/prefix_utils.c)
set(PU $<TARGET_OBJECTS:L_PU>)
add_library(L_TLV OBJECT src/tlv.c)
set(TLV $<TARGET_OBJECTS:L_TLV>)
add_library(L_PA_DATA OBJECT src/pa_data.c)
set(PA_D $<TARGET_OBJECTS:L_PA_DATA>)
add_library(L_PA_STORE OBJECT src/pa_store.c)
set(PA_DS ${PA_D} $<TARGET_OBJECTS:L_PA_STORE>)
add_library(L_PA OBJECT src/pa.c src/pa_local.c src/pa_core.c)
set(PA ${PA_DS} $<TARGET_OBJECTS:L_PA>)
add_library(L_HNCP_BASE OBJECT src/hncp.c src/hncp_notify.c src/hncp_timeout.c)
set(HNCP_BASE $<TARGET_OBJECTS:L_HNCP_BASE> ${PU} ${TLV})
add_library(L_HNCP_PROTO OBJECT src/hncp_proto.c)
set(HNCP_WITH_PROTO ${HNCP_BASE} $<TARGET_OBJECTS:L_HNCP_PROTO>)
add_library(L_HNCP_GLUE OBJECT src/hncp_pa.c src/hncp_sd.c)
set(HNCP_WITH_GLUE ${HNCP_WITH_PROTO} $<TARGET_OBJECTS:L_HNCP_GLUE>)
add_library(L_HNCP_IO OBJECT src/hncp_io.c)
set(HNCP_IO $<TARGET_OBJECTS:L_HNCP_IO>)
set(HNCP ${HNCP_WITH_GLUE} ${HNCP_IO})
add_executable(hnetd ${HNCP} src/hncp_routing.c src/hnetd.c src/iface.c ${PA} src/ ${BACKEND_SOURCE})
target_link_libraries(hnetd ubox blobmsg_json resolv ${BACKEND_LINK})

# Unit test stuff
OPTION(COVERAGE "build with coverage" OFF)

if (${COVERAGE})
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
endif (${COVERAGE})

# With this, 'make check' works even in a clean tree (sigh, cmake..)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
enable_testing()
include_directories(src)

add_executable(test_dummy test/test_dummy.c)
add_test(dummy test_dummy)
add_dependencies(check test_dummy)

add_executable(test_tlv test/test_tlv.c ${TLV})
target_link_libraries(test_tlv ubox ${BACKEND_LINK} blobmsg_json)
add_test(tlv test_tlv)
add_dependencies(check test_tlv)

add_executable(test_hncp test/test_hncp.c ${HNCP} ${PA})
target_link_libraries(test_hncp ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp test_hncp)
add_dependencies(check test_hncp)

add_executable(test_hncp_net test/test_hncp_net.c ${HNCP_WITH_GLUE})
target_link_libraries(test_hncp_net ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_net test_hncp_net)
add_dependencies(check test_hncp_net)

add_executable(test_hncp_pa test/test_hncp_pa.c ${HNCP_WITH_GLUE})
target_link_libraries(test_hncp_pa ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_pa test_hncp_pa)
add_dependencies(check test_hncp_pa)

add_executable(test_hncp_sd test/test_hncp_sd.c ${HNCP_WITH_PROTO})
target_link_libraries(test_hncp_sd ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_sd test_hncp_sd)
add_dependencies(check test_hncp_sd)

add_executable(test_hncp_nio test/test_hncp_nio.c ${PU} ${TLV})
target_link_libraries(test_hncp_nio ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_nio test_hncp_nio)
add_dependencies(check test_hncp_nio)

add_executable(test_hncp_bfs test/test_hncp_bfs.c ${HNCP_BASE} ${HNCP_IO})
target_link_libraries(test_hncp_bfs ubox ${BACKEND_LINK} blobmsg_json)
add_test(hncp_bfs test_hncp_bfs)
add_dependencies(check test_hncp_bfs)

add_executable(test_prefix_utils test/test_prefix_utils.c ${PU})
add_test(prefix_utils test_prefix_utils)
add_dependencies(check test_prefix_utils)

add_executable(test_pa test/test_pa.c ${PA_DS})
target_link_libraries(test_pa ubox)
add_test(pa test_pa)
add_dependencies(check test_pa)

add_executable(test_iface test/test_iface.c)
target_link_libraries(test_iface ubox)
add_test(iface test_iface)
add_dependencies(check test_iface)

add_executable(test_pa_store test/test_pa_store.c ${PA_DS} ${PU})
target_link_libraries(test_pa_store ubox)
add_test(pa_store test_pa_store)
add_dependencies(check test_pa_store)

add_executable(test_pa_data test/test_pa_data.c ${PA_D} ${PU})
target_link_libraries(test_pa_data ubox)
add_test(pa_data test_pa_data)
add_dependencies(check test_pa_data)

# Installation rules
install(TARGETS hnetd DESTINATION sbin/)

# Packaging rules
set(CPACK_PACKAGE_VERSION "1")
set(CPACK_PACKAGE_CONTACT "<NAME> <<EMAIL>>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "hnetd")
set(CPACK_GENERATOR "DEB;RPM;STGZ")
set(CPACK_STRIP_FILES true)

SET(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION})
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}")

include(CPack)
{'fraction_non_alphanumeric': 0.10922283750238686, 'fraction_numerical': 0.001336643116287951, 'mean_word_length': 8.462511291779585, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '175327', 'n_tokens_mistral': 4406, 'n_tokens_neox': 4286, 'n_words': 648}