Skip to content

Commit

Permalink
Add cmake files to some of the modules
Browse files Browse the repository at this point in the history
  • Loading branch information
gsurkov committed Jun 7, 2024
1 parent 51196a2 commit cd4e2bd
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 0 deletions.
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
36 changes: 36 additions & 0 deletions backend/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
18 changes: 18 additions & 0 deletions cli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
5 changes: 5 additions & 0 deletions cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if(MSVC)
add_compile_options(/W4 /WX)
else()
add_compile_options(-Wall -Wextra)
endif()
6 changes: 6 additions & 0 deletions cmake/FindCCache.cmake
Original file line number Diff line number Diff line change
@@ -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()
47 changes: 47 additions & 0 deletions cmake/VersionInfo.cmake
Original file line number Diff line number Diff line change
@@ -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()
39 changes: 39 additions & 0 deletions dfu/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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_$<UPPER_CASE:${USB_BACKEND}>"
)

target_link_libraries(dfu
PUBLIC
Qt6::Core
Qt6::Core5Compat
${USB_BACKEND_LIBS}
)
2 changes: 2 additions & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory("protobufinterface")
add_subdirectory("flipperproto0")
Empty file.
2 changes: 2 additions & 0 deletions plugins/protobufinterface/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(protobufinterface INTERFACE)
target_include_directories(protobufinterface INTERFACE .)

0 comments on commit cd4e2bd

Please sign in to comment.