瀏覽代碼

Merge pull request #1 from Lucino772/master

Add Cmake support
pull/178/head
Pixout Lighting 1 年之前
committed by GitHub
父節點
當前提交
3855023073
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 8 個文件被更改,包括 268 次插入0 次删除
  1. +26
    -0
      CMakeLists.txt
  2. +38
    -0
      README.md
  3. +9
    -0
      cmake/get-version.cmake
  4. +24
    -0
      cmake/toolchain-rpi.cmake
  5. +44
    -0
      devLib/CMakeLists.txt
  6. +33
    -0
      gpio/CMakeLists.txt
  7. +62
    -0
      wiringPi/CMakeLists.txt
  8. +32
    -0
      wiringPiD/CMakeLists.txt

+ 26
- 0
CMakeLists.txt 查看文件

@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.10)

include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/get-version.cmake")

project(wiringPi_lib VERSION ${VERSION})

add_subdirectory(wiringPi)
add_subdirectory(devLib)
add_subdirectory(wiringPiD)
add_subdirectory(gpio)

# CPack
set(CPACK_PACKAGE_NAME "wiringPi")
set(CPACK_PACKAGE_DESCRIPTION "WiringPi Library for RaspberryPi")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/WiringPi/WiringPi")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LESSER")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")

set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "WiringPi")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf")

set(CPACK_SOURCE_GENERATOR "TGZ;ZIP")

include(CPack)

+ 38
- 0
README.md 查看文件

@@ -11,6 +11,44 @@ to support newer hardware (primarily for use by the ports) and fix bugs.
* The default `master` branch contains code that has been written since that final source
release to provide support for newer hardware.

Build
-----

```shell
mdkir dist && cd dist
cmake ..
cmake --build .
```

Debian package:
```shell
cpack -config CPackConfig.cmake
```

Build Archive:
```shell
cpack -config CPackSourceConfig.cmake
```

**Cross-Compiling:**

Make sure to install the [`arm toolchain`](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) for the raspberry pi.

Then set the environment variable `TOOLCHAIN_PATH` to the `bin/` directory in your toolchain and run:
```shell
mkdir dist && cd dist
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain-rpi.cmake
cmake --build .
```

Install
-------

To install the wiringPi library, simply download the `.deb` package available in the [`latest release`](https://github.com/WiringPi/WiringPi/releases/latest) or build it from source and install it using `dpkg`:
```shell
sudo dpkg -i wiringpi-2.61-1-armhf.deb
```

Ports
-----



+ 9
- 0
cmake/get-version.cmake 查看文件

@@ -0,0 +1,9 @@
file(READ "${CMAKE_CURRENT_LIST_DIR}/../version.h" ver)

string(REGEX MATCH "VERSION_MAJOR ([0-9]*)" _ ${ver})
set(VERSION_MAJOR ${CMAKE_MATCH_1})

string(REGEX MATCH "VERSION_MINOR ([0-9]*)" _ ${ver})
set(VERSION_MINOR ${CMAKE_MATCH_1})

set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR})

+ 24
- 0
cmake/toolchain-rpi.cmake 查看文件

@@ -0,0 +1,24 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

if (NOT DEFINED ENV{TOOLCHAIN_PATH})
message(SEND_ERROR "Missing environment variable 'TOOLCHAIN_PATH'")
endif()

set(TOOLCHAIN_PATH $ENV{TOOLCHAIN_PATH})
set(TOOLCHAIN_PREFIX arm-none-linux-gnueabihf)

set(CMAKE_AR ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-ar)
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_C_COMPILER ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-gcc)
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-g++)
set(CMAKE_LINKER ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-ld)
set(CMAKE_OBJCOPY ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-objcopy CACHE INTERNAL "")
set(CMAKE_RANLIB ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-ranlib CACHE INTERNAL "")
set(CMAKE_SIZE ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-size CACHE INTERNAL "")
set(CMAKE_STRIP ${TOOLCHAIN_PATH}/${TOOLCHAIN_PREFIX}-strip CACHE INTERNAL "")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

+ 44
- 0
devLib/CMakeLists.txt 查看文件

@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.10)

include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/get-version.cmake")

project(wiringPiDev VERSION ${VERSION})
set(TARGET wiringPiDev)

# Have CMake find pthreads library within our toolchain
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)

# Source Files
set(wiringPiDev_src
ds1302.c maxdetect.c piNes.c gertboard.c
piFace.c lcd128x64.c lcd.c scrollPhat.c
piGlow.c
)

# Headers file
set(wiringPiDev_h
ds1302.h gertboard.h lcd128x64.h lcd.h maxdetect.h
piFace.h piGlow.h piNes.h scrollPhat.h
)

# Add library target
add_library (${TARGET} SHARED ${wiringPiDev_src})

# Version
set_target_properties(${TARGET} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})

# Add include directory for wiringPiDev
target_include_directories (${TARGET} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../wiringPi
${CMAKE_INSTALL_PREFIX}/include)

# Add the following required libraries: Threads
target_link_libraries(${TARGET} ${CMAKE_THREAD_LIBS_INIT})

# Add install
install(TARGETS ${TARGET} DESTINATION lib)
install(FILES ${wiringPiDev_h} DESTINATION include)

+ 33
- 0
gpio/CMakeLists.txt 查看文件

@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.10)

include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/get-version.cmake")

project(gpio VERSION ${VERSION})
set(TARGET gpio)

# Have CMake find pthreads library within our toolchain
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)

# Source Files
set(gpio_src
gpio.c readall.c
)

# Add library target
add_executable (${TARGET} ${gpio_src})

# Add include directory for gpio
target_include_directories (${TARGET} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../wiringPiDev
${CMAKE_CURRENT_SOURCE_DIR}/../wiringPi
${CMAKE_INSTALL_PREFIX}/include)


# Add the following required libraries: wiringPi, wiringPiDev, Threads, Math, Crypt, and RealTime
target_link_directories(${TARGET} PUBLIC ${CMAKE_INSTALL_PREFIX}/lib)
target_link_libraries(${TARGET} wiringPi wiringPiDev ${CMAKE_THREAD_LIBS_INIT} crypt m rt)

# Add install
install(TARGETS ${TARGET} DESTINATION bin)

+ 62
- 0
wiringPi/CMakeLists.txt 查看文件

@@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.10)

include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/get-version.cmake")

project(wiringPi VERSION ${VERSION})
set(TARGET wiringPi)

# Have CMake find pthreads library within our toolchain
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)

# Source Files
set(wiringPi_src
ads1115.c bmp180.c drcNet.c drcSerial.c
ds18b20.c htu21d.c max31855.c max5322.c
mcp23008.c mcp23016.c mcp23017.c mcp23s08.c
mcp23s17.c mcp3002.c mcp3004.c mcp3422.c
mcp4802.c pcf8574.c pcf8591.c piHiPri.c
piThread.c pseudoPins.c rht03.c sn3218.c
softPwm.c softServo.c softTone.c sr595.c
wiringPi.c wiringPiI2C.c wiringPiSPI.c
wiringSerial.c wiringShift.c wpiExtensions.c
)

# Headers file
set(wiringPi_h
ads1115.h bmp180.h drcNet.h drcSerial.h
ds18b20.h htu21d.h max31855.h max5322.h
mcp23008.h mcp23016.h mcp23016reg.h mcp23017.h
mcp23s08.h mcp23s17.h mcp23x08.h mcp23x0817.h
mcp3002.h mcp3004.h mcp3422.h mcp4802.h
pcf8574.h pcf8591.h pseudoPins.h rht03.h
sn3218.h softPwm.h softServo.h softTone.h
sr595.h wiringPi.h wiringPiI2C.h wiringPiSPI.h
wiringSerial.h wiringShift.h wpiExtensions.h
)

# Add library target
add_library (${TARGET} SHARED ${wiringPi_src})

# Version
set_target_properties(${TARGET} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR})

# Add include directory for wiringPi
target_include_directories (${TARGET} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_INSTALL_PREFIX}/include)


# Add the following required libraries: Threads, Math, Crypt, and RealTime
target_link_libraries(${TARGET} ${CMAKE_THREAD_LIBS_INIT} crypt m rt)

# Expose wiringPi public to other subprojects
set(${TARGET}_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
CACHE INTERNAL "${PROJECT_NAME}: Include directories" FORCE
)

# Add install
install(TARGETS ${TARGET} DESTINATION lib)
install(FILES ${wiringPi_h} DESTINATION include)

+ 32
- 0
wiringPiD/CMakeLists.txt 查看文件

@@ -0,0 +1,32 @@
cmake_minimum_required(VERSION 3.10)

include("${CMAKE_CURRENT_SOURCE_DIR}/../cmake/get-version.cmake")

project(wiringPiD VERSION ${VERSION})
set(TARGET wiringpid)

# Have CMake find pthreads library within our toolchain
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)

# Source Files
set(wiringPiD_src
wiringpid.c network.c runRemote.c daemonise.c
)

# Add library target
add_executable (${TARGET} ${wiringPiD_src})

# Add include directory for wiringPiD
target_include_directories (${TARGET} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../wiringPi
${CMAKE_INSTALL_PREFIX}/include)


# Add the following required libraries: wiringPi, wiringPiDev, Threads, Math, Crypt, and RealTime
target_link_directories(${TARGET} PUBLIC ${CMAKE_INSTALL_PREFIX}/lib)
target_link_libraries(${TARGET} wiringPi wiringPiDev ${CMAKE_THREAD_LIBS_INIT} crypt m rt)

# Add install
install(TARGETS ${TARGET} DESTINATION bin)

Loading…
取消
儲存