diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..d56ec8bb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.16) +project("qFlipper" C CXX) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") + +include(FindCCache) +include(VersionInfo) +include(CompileOptions) +include(GNUInstallDirs) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Debug") +endif() + +if(CMAKE_INSTALL_PREFIX) + set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/dist") + message(STATUS "Install Prefix defaulted to: ${CMAKE_INSTALL_PREFIX}") +else() + message(STATUS "Install Prefix set to: ${CMAKE_INSTALL_PREFIX}") +endif() + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_AUTOMOC ON) + +find_package(Qt6 COMPONENTS Core Core5Compat Network SerialPort REQUIRED CONFIG) + +if(NOT CMAKE_SYSTEM_NAME STREQUAL "Windows") + find_package(PkgConfig REQUIRED) + pkg_check_modules(libusb REQUIRED IMPORTED_TARGET "libusb-1.0") + pkg_check_modules(zlib REQUIRED IMPORTED_TARGET "zlib") +endif() + +add_subdirectory("dfu") +add_subdirectory("backend") +add_subdirectory("plugins") +add_subdirectory("cli") diff --git a/backend/CMakeLists.txt b/backend/CMakeLists.txt new file mode 100644 index 00000000..61b761b9 --- /dev/null +++ b/backend/CMakeLists.txt @@ -0,0 +1,36 @@ +qt_add_library(backend STATIC) + +file(GLOB BACKEND_SOURCES + "*.cpp" + "flipperzero/*.cpp" + "flipperzero/*/*.cpp" +) + +target_sources(backend + PRIVATE + ${BACKEND_SOURCES} +) + +target_include_directories(backend + PUBLIC + "." +) + +target_compile_definitions(backend + PUBLIC + "-DAPP_NAME=\"${CMAKE_PROJECT_NAME}\"" + "-DAPP_VERSION=\"${GIT_TAG}\"" + "-DAPP_COMMIT=\"%{GIT_COMMIT}\"" + "-DAPP_TIMESTAMP=\"${GIT_TIMESTAMP}\"" +) + +target_link_libraries(backend + PUBLIC + Qt::Network + Qt::SerialPort + PkgConfig::zlib + + PRIVATE + dfu + protobufinterface +) diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt new file mode 100644 index 00000000..7a6d6cda --- /dev/null +++ b/cli/CMakeLists.txt @@ -0,0 +1,18 @@ +set(CLI_TARGET "${CMAKE_PROJECT_NAME}_cli") + +qt_add_executable(${CLI_TARGET}) + +file(GLOB CLI_SOURCES + "*.cpp" +) + +target_sources(${CLI_TARGET} + PRIVATE + ${CLI_SOURCES} +) + +target_link_libraries(${CLI_TARGET} + PRIVATE + backend + dfu +) diff --git a/cmake/CompileOptions.cmake b/cmake/CompileOptions.cmake new file mode 100644 index 00000000..4340ee40 --- /dev/null +++ b/cmake/CompileOptions.cmake @@ -0,0 +1,5 @@ +if(MSVC) + add_compile_options(/W4 /WX) +else() + add_compile_options(-Wall -Wextra) +endif() diff --git a/cmake/FindCCache.cmake b/cmake/FindCCache.cmake new file mode 100644 index 00000000..1bfd16c4 --- /dev/null +++ b/cmake/FindCCache.cmake @@ -0,0 +1,6 @@ +find_program(CCACHE_FOUND ccache) + +if(CCACHE_FOUND) + message(STATUS "Found CCache: ${CCACHE_FOUND}") + set_property(GLOBAL PROPERTY CXX_COMPILER_LAUNCHER ${CCACHE_FOUND}) +endif() diff --git a/cmake/VersionInfo.cmake b/cmake/VersionInfo.cmake new file mode 100644 index 00000000..2eeb7318 --- /dev/null +++ b/cmake/VersionInfo.cmake @@ -0,0 +1,47 @@ +execute_process(COMMAND "git" + "describe" + "--tags" + "--abbrev=0" + WORKING_DIRECTORY + "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE + GIT_TAG + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +if(GIT_TAG STREQUAL "") + set(GIT_TAG "unknown") +endif() + +execute_process(COMMAND "git" + "rev-parse" + "--short=8" + "HEAD" + WORKING_DIRECTORY + "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE + GIT_COMMIT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +if(GIT_COMMIT STREQUAL "") + set(GIT_COMMIT "unknown") +endif() + +execute_process(COMMAND "git" + "log" + "-1" + "--pretty=format:%ct" + WORKING_DIRECTORY + "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE + GIT_TIMESTAMP + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET +) + +if(GIT_TIMESTAMP STREQUAL "") + set(GIT_TIMESTAMP "unknown") +endif() diff --git a/dfu/CMakeLists.txt b/dfu/CMakeLists.txt new file mode 100644 index 00000000..1687b1b8 --- /dev/null +++ b/dfu/CMakeLists.txt @@ -0,0 +1,39 @@ +qt_add_library(dfu STATIC) + +if(CMAKE_SYSTEM_NAME STREQUAL "Windows") + set(USB_BACKEND "win32") + set(USB_BACKEND_LIBS setupapi) +else() + set(USB_BACKEND "libusb") + set(USB_BACKEND_LIBS PkgConfig::libusb) +endif() + +file(GLOB DFU_SOURCES + "*.cpp" + "device/*.cpp" + "device/*/*.cpp" + "${USB_BACKEND}/*.cpp" +) + +target_sources(dfu + PRIVATE + ${DFU_SOURCES} +) + +target_include_directories(dfu + PUBLIC + "." + "./${USB_BACKEND}" +) + +target_compile_definitions(dfu + PUBLIC + "-DUSB_BACKEND_$" +) + +target_link_libraries(dfu + PUBLIC + Qt6::Core + Qt6::Core5Compat + ${USB_BACKEND_LIBS} +) diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt new file mode 100644 index 00000000..0275e31c --- /dev/null +++ b/plugins/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory("protobufinterface") +add_subdirectory("flipperproto0") diff --git a/plugins/flipperproto0/CMakeLists.txt b/plugins/flipperproto0/CMakeLists.txt new file mode 100644 index 00000000..e69de29b diff --git a/plugins/protobufinterface/CMakeLists.txt b/plugins/protobufinterface/CMakeLists.txt new file mode 100644 index 00000000..50c0c2cd --- /dev/null +++ b/plugins/protobufinterface/CMakeLists.txt @@ -0,0 +1,2 @@ +add_library(protobufinterface INTERFACE) +target_include_directories(protobufinterface INTERFACE .)