-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add License; CMake builds this fine locally
- Loading branch information
Showing
22 changed files
with
1,049 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
# ignore doxygen generated files | ||
# Generated library files | ||
*.so | ||
*.so.1 | ||
|
||
# ignore docs folder | ||
docs/html/ | ||
docs/xml/ | ||
|
||
# ignore CMake stuff | ||
build/ | ||
*CMakeUserPresets.json | ||
|
||
# ignore local vscode folder | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
# Set the project name to your project name | ||
project(RF24Gateway C CXX) | ||
include(cmake/StandardProjectSettings.cmake) | ||
include(cmake/PreventInSourceBuilds.cmake) | ||
|
||
# Link this 'library' to set the c++ standard / compile-time options requested | ||
add_library(project_options INTERFACE) | ||
target_compile_features(project_options INTERFACE cxx_std_17) | ||
add_compile_options(-Ofast -Wall) | ||
|
||
# detect CPU and add compiler flags accordingly | ||
include(cmake/detectCPU.cmake) | ||
|
||
if(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") | ||
option(ENABLE_BUILD_WITH_TIME_TRACE "Enable -ftime-trace to generate time tracing .json files on clang" OFF) | ||
if(ENABLE_BUILD_WITH_TIME_TRACE) | ||
add_compile_definitions(project_options INTERFACE -ftime-trace) | ||
endif() | ||
endif() | ||
|
||
# Link this 'library' to use the warnings specified in CompilerWarnings.cmake | ||
add_library(project_warnings INTERFACE) | ||
|
||
# enable cache system | ||
include(cmake/Cache.cmake) | ||
|
||
# standard compiler warnings | ||
include(cmake/CompilerWarnings.cmake) | ||
set_project_warnings(project_warnings) | ||
|
||
# get library info from Arduino IDE's required library.properties file | ||
include(cmake/GetLibInfo.cmake) # sets the variable LibTargetName | ||
|
||
# setup CPack options | ||
include(cmake/CPackInfo.cmake) | ||
|
||
find_library(RF24 rf24 REQUIRED) | ||
message(STATUS "using RF24 library: ${RF24}") | ||
|
||
find_library(RF24Network rf24network REQUIRED) | ||
message(STATUS "using RF24Network library: ${RF24Network}") | ||
|
||
find_library(RF24Mesh rf24mesh REQUIRED) | ||
message(STATUS "using RF24Mesh library: ${RF24Mesh}") | ||
|
||
########################### | ||
# create target for bulding the RF24Log lib | ||
########################### | ||
add_library(${LibTargetName} SHARED | ||
RF24Gateway.cpp | ||
) | ||
target_include_directories(${LibTargetName} PUBLIC | ||
${CMAKE_CURRENT_LIST_DIR} | ||
) | ||
|
||
target_link_libraries(${LibTargetName} INTERFACE | ||
project_options | ||
project_warnings | ||
SHARED ${RF24} | ||
SHARED ${RF24Network} | ||
SHARED ${RF24Mesh} | ||
) | ||
|
||
set_target_properties( | ||
${LibTargetName} | ||
PROPERTIES | ||
SOVERSION ${${LibName}_VERSION_MAJOR} | ||
VERSION ${${LibName}_VERSION_STRING} | ||
) | ||
|
||
########################### | ||
# target install rules for the RF24Log lib | ||
########################### | ||
install(TARGETS ${LibTargetName} | ||
DESTINATION lib | ||
) | ||
|
||
install(FILES | ||
RF24Gateway.h | ||
DESTINATION include/RF24Gateway | ||
) | ||
|
||
# CMAKE_CROSSCOMPILING is only TRUE when CMAKE_TOOLCHAIN_FILE is specified via CLI | ||
if(CMAKE_HOST_UNIX AND "${CMAKE_CROSSCOMPILING}" STREQUAL "FALSE") | ||
install(CODE "message(STATUS \"Updating ldconfig\")") | ||
install(CODE "execute_process(COMMAND ldconfig)") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# This module will build a debian compatible package to install - handy for cross-compiling | ||
|
||
if(NOT PKG_REV) | ||
set(PKG_REV "1") | ||
endif() | ||
|
||
# get target arch if not cross-compiling | ||
if(NOT TARGET_ARCH) # TARGET_ARCH is defined only in the toolchain_<ARCH_TYPE>.cmake files | ||
if(WIN32) | ||
set(TARGET_ARCH $ENV{PROCESSOR_ARCHITECTURE}) | ||
else() | ||
execute_process(COMMAND dpkg --print-architecture | ||
OUTPUT_VARIABLE TARGET_ARCH | ||
) | ||
endif() | ||
string(STRIP "${TARGET_ARCH}" TARGET_ARCH) | ||
endif() | ||
|
||
# set the Cpack generators (specific to types of packages to create) | ||
if(NOT WIN32) | ||
set(CPACK_GENERATOR DEB RPM) # RPM requires rpmbuild executable | ||
else() | ||
set(CPACK_GENERATOR "") # should find out how to build vcpkg packages | ||
endif() | ||
|
||
# assemble a debian package filename from known info | ||
include(InstallRequiredSystemLibraries) | ||
set(CPACK_PACKAGE_FILE_NAME "lib${LibTargetName}_${${LibName}_VERSION_STRING}-${PKG_REV}_${TARGET_ARCH}") | ||
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") | ||
set(CPACK_PACKAGE_VERSION_MAJOR "${${LibName}_VERSION_MAJOR}") | ||
set(CPACK_PACKAGE_VERSION_MINOR "${${LibName}_VERSION_MINOR}") | ||
set(CPACK_PACKAGE_VERSION_PATCH "${${LibName}_VERSION_PATCH}") | ||
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/pkgs") # for easy uploading to github releases | ||
|
||
if(NOT WIN32) | ||
############################### | ||
# info specific debian packages | ||
############################### | ||
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${TARGET_ARCH}) | ||
set(CPACK_DEBIAN_PACKAGE_SECTION libs) | ||
set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE) | ||
set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON) | ||
|
||
############################### | ||
# info specific rpm (fedora) packages | ||
############################### | ||
set(CPACK_RPM_FILE_NAME "lib${LibTargetName}-${${LibName}_VERSION_STRING}-${PKG_REV}.${TARGET_ARCH}.rpm") | ||
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${TARGET_ARCH}) | ||
set(CPACK_RPM_PACKAGE_LICENSE "GPLv2.0") | ||
set(CPACK_RPM_PACKAGE_VENDOR "Humanity") | ||
|
||
# create a post-install & post-removal scripts to update linker | ||
set(POST_SCRIPTS | ||
${CMAKE_BINARY_DIR}/DEBIAN/postrm | ||
${CMAKE_BINARY_DIR}/DEBIAN/postinst | ||
) | ||
foreach(script ${POST_SCRIPTS}) | ||
file(WRITE ${script} /sbin/ldconfig) | ||
execute_process(COMMAND chmod +x ${script}) | ||
execute_process(COMMAND chmod 775 ${script}) | ||
endforeach() | ||
# declare scripts for deb pkgs | ||
list(JOIN POST_SCRIPTS ";" EXTRA_CTRL_FILES) | ||
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA EXTRA_CTRL_FILES) | ||
# declare scripts for rpm pkgs | ||
list(POP_FRONT POST_SCRIPTS CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE) | ||
list(POP_FRONT POST_SCRIPTS CPACK_RPM_POST_INSTALL_SCRIPT_FILE) | ||
|
||
message(STATUS "ready to package: ${CPACK_PACKAGE_FILE_NAME}.deb") | ||
message(STATUS "ready to package: ${CPACK_RPM_FILE_NAME}") | ||
endif() | ||
|
||
include(CPack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
option(ENABLE_CACHE "Enable cache if available" ON) | ||
if(NOT ENABLE_CACHE) | ||
return() | ||
endif() | ||
|
||
set(CACHE_OPTION | ||
"ccache" | ||
CACHE STRING "Compiler cache to be used" | ||
) | ||
set(CACHE_OPTION_VALUES "ccache" "sccache") | ||
set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES}) | ||
list( | ||
FIND | ||
CACHE_OPTION_VALUES | ||
${CACHE_OPTION} | ||
CACHE_OPTION_INDEX | ||
) | ||
|
||
if(${CACHE_OPTION_INDEX} EQUAL -1) | ||
message(STATUS | ||
"Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}" | ||
) | ||
endif() | ||
|
||
find_program(CACHE_BINARY ${CACHE_OPTION}) | ||
if(CACHE_BINARY) | ||
message(STATUS "${CACHE_OPTION} found and enabled") | ||
set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY}) | ||
else() | ||
message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# from here: | ||
# | ||
# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md | ||
|
||
function(set_project_warnings project_name) | ||
option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" TRUE) | ||
|
||
set(MSVC_WARNINGS | ||
/W4 # Baseline reasonable warnings | ||
/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data | ||
/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data | ||
/w14263 # 'function': member function does not override any base class virtual member function | ||
/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not | ||
# be destructed correctly | ||
/w14287 # 'operator': unsigned/negative constant mismatch | ||
/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside | ||
# the for-loop scope | ||
/w14296 # 'operator': expression is always 'boolean_value' | ||
/w14311 # 'variable': pointer truncation from 'type1' to 'type2' | ||
/w14545 # expression before comma evaluates to a function which is missing an argument list | ||
/w14546 # function call before comma missing argument list | ||
/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect | ||
/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'? | ||
/w14555 # expression has no effect; expected expression with side- effect | ||
/w14619 # pragma warning: there is no warning number 'number' | ||
/w14640 # Enable warning on thread un-safe static member initialization | ||
/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior. | ||
/w14905 # wide string literal cast to 'LPSTR' | ||
/w14906 # string literal cast to 'LPWSTR' | ||
/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied | ||
/permissive- # standards conformance mode for MSVC compiler. | ||
) | ||
|
||
set(CLANG_WARNINGS | ||
-Wall | ||
-Wextra # reasonable and standard | ||
-Wshadow # warn the user if a variable declaration shadows one from a parent context | ||
-Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps | ||
# catch hard to track down memory errors | ||
-Wold-style-cast # warn for c-style casts | ||
-Wcast-align # warn for potential performance problem casts | ||
-Wunused # warn on anything being unused | ||
-Woverloaded-virtual # warn if you overload (not override) a virtual function | ||
-Wpedantic # warn if non-standard C++ is used | ||
-Wconversion # warn on type conversions that may lose data | ||
-Wsign-conversion # warn on sign conversions | ||
-Wnull-dereference # warn if a null dereference is detected | ||
-Wdouble-promotion # warn if float is implicit promoted to double | ||
-Wformat=2 # warn on security issues around functions that format output (ie printf) | ||
) | ||
|
||
if(WARNINGS_AS_ERRORS) | ||
set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) | ||
set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) | ||
endif() | ||
|
||
set(GCC_WARNINGS | ||
${CLANG_WARNINGS} | ||
-Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist | ||
-Wduplicated-cond # warn if if / else chain has duplicated conditions | ||
-Wduplicated-branches # warn if if / else branches have duplicated code | ||
-Wlogical-op # warn about logical operations being used where bitwise were probably wanted | ||
-Wuseless-cast # warn if you perform a cast to the same type | ||
) | ||
|
||
if(MSVC) | ||
set(PROJECT_WARNINGS ${MSVC_WARNINGS}) | ||
elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") | ||
set(PROJECT_WARNINGS ${CLANG_WARNINGS}) | ||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") | ||
set(PROJECT_WARNINGS ${GCC_WARNINGS}) | ||
else() | ||
message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") | ||
endif() | ||
|
||
target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) | ||
|
||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# get lib info from the git cmds | ||
execute_process(COMMAND git config --get remote.origin.url OUTPUT_VARIABLE CMAKE_PROJECT_HOMEPAGE_URL) | ||
string(STRIP CMAKE_PROJECT_HOMEPAGE_URL ${CMAKE_PROJECT_HOMEPAGE_URL}) | ||
|
||
# use URL to get repo owner as Contact/Maintainer name | ||
string(REGEX REPLACE "^http[s]?://github.com/(.+)/.+\\.git" "\\1" CPACK_PACKAGE_CONTACT "${CMAKE_PROJECT_HOMEPAGE_URL}") | ||
string(STRIP "${CPACK_PACKAGE_CONTACT}" CPACK_PACKAGE_CONTACT) | ||
|
||
# use URL to get the repo name as the Lib Name. Note that we don't use the folder name for this | ||
string(REGEX REPLACE "^http[s]?://github.com/.+/(.+)\\.git" "\\1" LibName "${CMAKE_PROJECT_HOMEPAGE_URL}") | ||
string(STRIP "${LibName}" LibName) | ||
|
||
# convert the LibName to lower case | ||
string(TOLOWER ${LibName} LibTargetName) | ||
|
||
# have to hard-code the Repo Summary (which is copied from the parent repo's "About" info) | ||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "TCP/IP (RF24Ethernet) and RF24Network Gateway") | ||
|
||
# Use repo README.md to get the project description | ||
file(READ "README.md" CPACK_PACKAGE_DESCRIPTION) | ||
string(FIND "${CPACK_PACKAGE_DESCRIPTION}" "## RF24Gateway" README_TITLE) | ||
math(EXPR README_TITLE "${README_TITLE} + 15") # compensates for '\n' char | ||
string(FIND "${CPACK_PACKAGE_DESCRIPTION}" "### Documentation" DOC_LINK_TITLE) | ||
math(EXPR DESCRIPTION_LENGTH "${DOC_LINK_TITLE} - ${README_TITLE}") | ||
string(SUBSTRING "${CPACK_PACKAGE_DESCRIPTION}" ${README_TITLE} ${DESCRIPTION_LENGTH} CPACK_PACKAGE_DESCRIPTION) | ||
|
||
# parse the version information into pieces. | ||
execute_process(COMMAND git describe --tags OUTPUT_VARIABLE VERSION) | ||
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}") | ||
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}") | ||
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}") | ||
|
||
# this is the library version | ||
set(${LibName}_VERSION_MAJOR ${VERSION_MAJOR}) | ||
set(${LibName}_VERSION_MINOR ${VERSION_MINOR}) | ||
set(${LibName}_VERSION_PATCH ${VERSION_PATCH}) | ||
set(${LibName}_VERSION_STRING ${${LibName}_VERSION_MAJOR}.${${LibName}_VERSION_MINOR}.${${LibName}_VERSION_PATCH}) | ||
|
||
message(STATUS "${LibName} library version: ${${LibName}_VERSION_STRING}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# | ||
# This function will prevent in-source builds | ||
function(AssureOutOfSourceBuilds) | ||
# make sure the user doesn't play dirty with symlinks | ||
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH) | ||
get_filename_component(bindir "${CMAKE_BINARY_DIR}" REALPATH) | ||
|
||
# disallow in-source builds | ||
if("${srcdir}" STREQUAL "${bindir}") | ||
message("######################################################") | ||
message("Warning: in-source builds are disabled") | ||
message("Please create a separate build directory and run cmake from there") | ||
message("######################################################") | ||
message(FATAL_ERROR "Quitting configuration") | ||
endif() | ||
endfunction() | ||
|
||
assureoutofsourcebuilds() |
Oops, something went wrong.