diff --git a/CMakeLists.txt b/CMakeLists.txt index 20a744ce5..665a06d43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,19 +8,51 @@ include(CheckIncludeFiles) include(CheckSymbolExists) include(CheckTypeSize) -find_package(OpenSSL REQUIRED) -set(LIBCRYPTO_INCLUDE_DIRS "${OpenSSL_INCLUDE_DIRS}") -set(LIBCRYPTO_LIBRARY_DIRS "${OpenSSL_LIBRARY_DIRS}") -set(LIBCRYPTO_LIBRARIES "${OpenSSL_LIBRARIES}") +set(BUILD_COMPONENTS) -find_package(NSPR REQUIRED) -find_package(NSS REQUIRED) +macro (build_switch name default) + if (NOT DEFINED BUILD_${name}) + if (BUILD_NOTHING_BY_DEFAULT) + set(BUILD_${name} 0) + else () + set(BUILD_${name} "${default}") + endif () + endif () + list(APPEND BUILD_COMPONENTS "${name}") +endmacro () + +# define build defaults +build_switch(EXAMPLES 1) +build_switch(TESTS 1) +build_switch(SERVER 1) +build_switch(CLIENT 1) +build_switch(FLOODER 1) +build_switch(TUN2SOCKS 1) +build_switch(UDPGW 1) +build_switch(NCD 1) + +if (BUILD_NCD AND NOT (CMAKE_SYSTEM_NAME STREQUAL "Linux")) + message(FATAL_ERROR, "NCD is only available on Linux") +endif () + +if (BUILD_CLIENT OR BUILD_SERVER OR BUILD_NCD) + find_package(OpenSSL REQUIRED) + set(LIBCRYPTO_INCLUDE_DIRS "${OpenSSL_INCLUDE_DIRS}") + set(LIBCRYPTO_LIBRARY_DIRS "${OpenSSL_LIBRARY_DIRS}") + set(LIBCRYPTO_LIBRARIES "${OpenSSL_LIBRARIES}") +endif () + +if (BUILD_SERVER OR BUILD_CLIENT OR BUILD_FLOODER) + find_package(NSPR REQUIRED) + find_package(NSS REQUIRED) +endif () include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${LIBCRYPTO_INCLUDE_DIRS} ${NSPR_INCLUDE_DIRS} ${NSS_INCLUDE_DIRS} + ${FUSE_INCLUDE_DIRS} lwip/custom lwip/src/include lwip/src/include/ipv4 @@ -30,6 +62,11 @@ link_directories( ${LIBCRYPTO_LIBRARY_DIRS} ${NSPR_LIBRARY_DIRS} ${NSS_LIBRARY_DIRS} + ${FUSE_LIBRARY_DIRS} +) + +add_definitions( + ${FUSE_CFLAGS} ) test_big_endian(BIG_ENDIAN) @@ -141,48 +178,115 @@ install( DESTINATION share/man/man8 ) +# reset variables indicating whether we're building various libraries, +# and set them in the respective CMakeLists files. This is used to disable +# building examples and tests which require libraries that are not available. +set(BUILDING_DHCPCLIENT 0) +set(BUILDING_BKIO 0) +set(BUILDING_PREDICATE 0) +set(BUILDING_UDEVMONITOR 0) +set(BUILDING_THREADWORK 0) + # internal libraries add_subdirectory(base) add_subdirectory(system) add_subdirectory(flow) add_subdirectory(flowextra) -add_subdirectory(tuntap) -add_subdirectory(predicate) -add_subdirectory(nspr_support) -add_subdirectory(server_connection) -add_subdirectory(security) -add_subdirectory(socksclient) -add_subdirectory(lwip) -add_subdirectory(dhcpclient) -add_subdirectory(threadwork) -add_subdirectory(stringmap) -add_subdirectory(udpgw_client) -if (NOT WIN32) +if (OpenSSL_FOUND) + add_subdirectory(security) +endif () +if (NSS_FOUND) + add_subdirectory(nspr_support) +endif () +if (BUILD_CLIENT OR BUILD_NCD) + set(BUILDING_THREADWORK 1) + add_subdirectory(threadwork) +endif () +if (BUILD_CLIENT OR BUILD_TUN2SOCKS) + add_subdirectory(tuntap) +endif () +if (BUILD_SERVER) + set(BUILDING_PREDICATE 1) + add_subdirectory(predicate) +endif () +if (BUILD_CLIENT OR BUILD_FLOODER) + add_subdirectory(server_connection) +endif () +if (BUILD_NCD) + set(BUILDING_DHCPCLIENT 1) + set(BUILDING_UDEVMONITOR 1) + add_subdirectory(stringmap) add_subdirectory(udevmonitor) + add_subdirectory(dhcpclient) +endif () +if (BUILD_TUN2SOCKS) + add_subdirectory(socksclient) + add_subdirectory(udpgw_client) + add_subdirectory(lwip) endif () # example programs -add_subdirectory(examples) +if (BUILD_EXAMPLES) + add_subdirectory(examples) +endif () # tests -add_subdirectory(tests) +if (BUILD_TESTS) + add_subdirectory(tests) +endif () # server -add_subdirectory(server) +if (BUILD_SERVER) + add_subdirectory(server) +endif () # client -add_subdirectory(client) +if (BUILD_CLIENT) + add_subdirectory(client) +endif () # flooder -add_subdirectory(flooder) +if (BUILD_FLOODER) + add_subdirectory(flooder) +endif () # tun2socks -add_subdirectory(tun2socks) +if (BUILD_TUN2SOCKS) + add_subdirectory(tun2socks) +endif () # udpgw -add_subdirectory(udpgw) +if (BUILD_UDPGW) + add_subdirectory(udpgw) +endif () # ncd -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if (BUILD_NCD) add_subdirectory(ncd) endif () + +message(STATUS "Building components:") + +# print what we're building and what not +foreach (name ${BUILD_COMPONENTS}) + # to lower name + string(TOLOWER "${name}" name_withspaces) + + # append spaces to name + #while (TRUE) + # string(LENGTH "${name_withspaces}" length) + # if (NOT (length LESS 12)) + # break() + # endif () + # set(name_withspaces "${name_withspaces} ") + #endwhile () + + # determine if we're building + if (BUILD_${name}) + set(building "yes") + else () + set(building "no") + endif () + + message(STATUS " ${name_withspaces} ${building}") +endforeach () diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b2011f1c6..966d65d38 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,45 +3,59 @@ add_executable(linkedlist2_example linkedlist2_example.c) add_executable(btimer_example btimer_example.c) target_link_libraries(btimer_example system) -add_executable(predicate_test predicate_test.c) -target_link_libraries(predicate_test predicate) +if (BUILDING_PREDICATE) + add_executable(predicate_test predicate_test.c) + target_link_libraries(predicate_test predicate) +endif () add_executable(fairqueue_test fairqueue_test.c) target_link_libraries(fairqueue_test system flow) -add_executable(fairqueue_test2 fairqueue_test2.c) -target_link_libraries(fairqueue_test2 system flow security) - -add_executable(bheap_test bheap_test.c) -target_link_libraries(bheap_test security) +if (LIBCRYPTO_LIBRARIES) + add_executable(fairqueue_test2 fairqueue_test2.c) + target_link_libraries(fairqueue_test2 system flow security) +endif () -add_executable(bavl_test bavl_test.c) -target_link_libraries(bavl_test security) +if (LIBCRYPTO_LIBRARIES) + add_executable(bheap_test bheap_test.c) + target_link_libraries(bheap_test security) +endif () -add_executable(bencryption_bench bencryption_bench.c) -target_link_libraries(bencryption_bench system security) +if (LIBCRYPTO_LIBRARIES) + add_executable(bavl_test bavl_test.c) + target_link_libraries(bavl_test security) +endif () -add_executable(ncd_tokenizer_test ncd_tokenizer_test.c) -target_link_libraries(ncd_tokenizer_test ncdconfig) +if (LIBCRYPTO_LIBRARIES) + add_executable(bencryption_bench bencryption_bench.c) + target_link_libraries(bencryption_bench system security) +endif () -add_executable(ncd_parser_test ncd_parser_test.c) -target_link_libraries(ncd_parser_test ncdconfig) +if (BUILD_NCD) + add_executable(ncd_tokenizer_test ncd_tokenizer_test.c) + target_link_libraries(ncd_tokenizer_test ncdconfig) -if (NOT WIN32) - add_executable(bprocess_example bprocess_example.c) - target_link_libraries(bprocess_example system) + add_executable(ncd_parser_test ncd_parser_test.c) + target_link_libraries(ncd_parser_test ncdconfig) +endif () +if (BUILDING_UDEVMONITOR) add_executable(ncdudevmonitor_test ncdudevmonitor_test.c) target_link_libraries(ncdudevmonitor_test udevmonitor) add_executable(ncdudevmanager_test ncdudevmanager_test.c) target_link_libraries(ncdudevmanager_test udevmonitor) +endif () + +if (NOT WIN32) + add_executable(bprocess_example bprocess_example.c) + target_link_libraries(bprocess_example system) add_executable(stdin_input stdin_input.c) target_link_libraries(stdin_input system flow flowextra) endif () -if (CMAKE_SYSTEM_NAME STREQUAL "Linux") +if (BUILDING_DHCPCLIENT) add_executable(dhcpclient_test dhcpclient_test.c) target_link_libraries(dhcpclient_test dhcpclient) endif () diff --git a/flowextra/CMakeLists.txt b/flowextra/CMakeLists.txt index fe826c4bd..cf89e3ceb 100644 --- a/flowextra/CMakeLists.txt +++ b/flowextra/CMakeLists.txt @@ -2,4 +2,4 @@ add_library(flowextra PacketPassInactivityMonitor.c KeepaliveIO.c ) -target_link_libraries(flowextra flow system security) +target_link_libraries(flowextra flow system) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f1bc49ebf..ebb0d62bf 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,5 +2,7 @@ add_executable(chunkbuffer2_test chunkbuffer2_test.c) add_executable(bproto_test bproto_test.c) -add_executable(threadwork_test threadwork_test.c) -target_link_libraries(threadwork_test threadwork) +if (BUILDING_THREADWORK) + add_executable(threadwork_test threadwork_test.c) + target_link_libraries(threadwork_test threadwork) +endif ()