diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f1527d4..8b3db929 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,25 @@ project(netremote VERSION 0.0.1 ) +# Conditional inclusion of OS-dependent source trees. +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(BUILD_FOR_LINUX TRUE) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(BUILD_FOR_WINDOWS TRUE) +else () + MESSAGE(FATAL_ERROR "No supported target OS detected, SYSTEM_NAME=${CMAKE_SYSTEM_NAME}") +endif() + +MESSAGE(STATUS "Target OS ${CMAKE_SYSTEM_NAME} detected") + +# Option determining whether the hostapd client library should be built from +# source, or a pre-built, packaged version discovered on the system. +option( + BUILD_HOSTAP_EXTERNAL + "Build hostap project from built-in external source" + ON +) + # Set language configutation options. The C++ standard used must be the lowest # common denominator for all the OS-dependent projects. In practice, since this # project must build under the Windows build system (build.exe), its toolchain @@ -27,9 +46,11 @@ set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) include(CheckPIESupported) include(CTest) +include(ExternalProject) include(GNUInstallDirs) include(grpc) include(protoc) +include(hostap) # Enable verbose output until project is bootstrapped. set(CMAKE_VERBOSE_MAKEFILE ON) @@ -108,6 +129,43 @@ if (CMAKE_BUILD_TYPE MATCHES "(Release|RelWithDebInfo|MinSizeRel)") add_compile_definitions(_FORTIFY_SOURCE=2) endif() +# Common source directories +set(NETREMOTE_DIR_SRC ${CMAKE_CURRENT_LIST_DIR}/src) +set(NETREMOTE_DIR_LINUX ${CMAKE_CURRENT_LIST_DIR}/linux) +set(NETREMOTE_DIR_WINDOWS ${CMAKE_CURRENT_LIST_DIR}/windows) + +# Add common, global compile definitions. +add_compile_definitions( + MAGIC_ENUM_RANGE_MIN=0 + MAGIC_ENUM_RANGE_MAX=255 +) + +# Conditional inclusion of OS-dependent source trees. +if (BUILD_FOR_LINUX) + add_subdirectory(linux) +elseif (BUILD_FOR_WINDOWS) + # Make public version of wil available. + set(WIL_BUILD_TESTS OFF CACHE INTERNAL "Turn off wil tests") + set(WIL_BUILD_PACKAGING OFF CACHE INTERNAL "Turn off wil packaging") + + find_package(wil CONFIG REQUIRED) + + # Add Windows-specific global compile definitions. + add_compile_definitions( + _UNICODE + UNICODE + NOMINMAX + WIN32_LEAN_AND_MEAN + ) + + # Allow more than default number of sections in object files. + add_compile_options( + /bigobj + ) + + add_subdirectory(windows) +endif() + add_subdirectory(protocol) add_subdirectory(src) add_subdirectory(tests) diff --git a/cmake/hostap.cmake b/cmake/hostap.cmake new file mode 100644 index 00000000..45e00f96 --- /dev/null +++ b/cmake/hostap.cmake @@ -0,0 +1,13 @@ + +if (BUILD_HOSTAP_EXTERNAL) + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/../external/hostap) +else() + find_library(LIBWPA_CLIENT + NAMES libwpa_client.so + REQUIRED) +endif() + +if(LIBWPA_CLIENT) + set(LIBWPA_CLIENT_TARGET ${LIBWPA_CLIENT}) + MESSAGE(STATUS "Found wpa client: ${LIBWPA_CLIENT}") +endif() diff --git a/external/hostap/.config b/external/hostap/.config new file mode 100644 index 00000000..e57b0b2b --- /dev/null +++ b/external/hostap/.config @@ -0,0 +1,2 @@ +CONFIG_CTRL_IFACE=y +CONFIG_BUILD_WPA_CLIENT_SO=y \ No newline at end of file diff --git a/external/hostap/CMakeLists.txt b/external/hostap/CMakeLists.txt new file mode 100644 index 00000000..e7bc4f2d --- /dev/null +++ b/external/hostap/CMakeLists.txt @@ -0,0 +1,23 @@ + +find_program(MAKE_EXE + NAMES gmake nmake make + REQUIRED +) + +set(HOSTAP_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/hostap-prefix/src/hostap/wpa_supplicant) + +ExternalProject_Add(hostap + GIT_REPOSITORY "http://w1.fi/hostap.git" + GIT_TAG "hostap_2_10" + CONFIGURE_COMMAND cp -n ${CMAKE_CURRENT_SOURCE_DIR}/.config ${HOSTAP_PREFIX}/.config + BINARY_DIR ${HOSTAP_PREFIX} + BUILD_COMMAND QUIET=1 ${MAKE_EXE} libwpa_client.so + INSTALL_DIR ${HOSTAP_PREFIX} + INSTALL_COMMAND QUIET=1 DESTDIR=${HOSTAP_PREFIX} ${MAKE_EXE} install +) + +set(LIBWPA_CLIENT + ${HOSTAP_PREFIX}/libwpa_client.so + CACHE FILEPATH + "wpa client shared object" +) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt new file mode 100644 index 00000000..e31076a5 --- /dev/null +++ b/linux/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(hostap-controller) \ No newline at end of file diff --git a/linux/hostap-controller/CMakeLists.txt b/linux/hostap-controller/CMakeLists.txt new file mode 100644 index 00000000..866ae640 --- /dev/null +++ b/linux/hostap-controller/CMakeLists.txt @@ -0,0 +1,16 @@ + +add_library(hostap-controller SHARED "") + +if (BUILD_HOSTAP_EXTERNAL) + add_dependencies(hostap-controller hostap) +endif() + +target_sources(hostap-controller + PRIVATE + Placeholder.cxx +) + +target_link_libraries(hostap-controller + INTERFACE + ${LIBWPA_CLIENT_TARGET} +) diff --git a/linux/hostap-controller/Placeholder.cxx b/linux/hostap-controller/Placeholder.cxx new file mode 100644 index 00000000..4631bc9e --- /dev/null +++ b/linux/hostap-controller/Placeholder.cxx @@ -0,0 +1,4 @@ + +#include + +#include diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt new file mode 100644 index 00000000..e69de29b