kopia lustrzana https://github.com/stlink-org/stlink
CMakeLists.txt: Add shared library build and debian packaging
Signed-off-by: Andrew Andrianov <andrew@ncrmnt.org>pull/444/head
rodzic
1ca526ca4d
commit
a35cc23525
|
@ -1,4 +1,6 @@
|
|||
cmake_minimum_required(VERSION 2.8.7)
|
||||
project(stlink C)
|
||||
set(PROJECT_DESCRIPTION "Open source version of the STMicroelectronics Stlink Tools")
|
||||
|
||||
project(stlink C)
|
||||
include(CheckCCompilerFlag)
|
||||
|
@ -18,7 +20,6 @@ if (DEFINED ENV{TRAVIS_TAG} AND NOT "$ENV{TRAVIS_TAG}" STREQUAL "")
|
|||
set (STLINK_PACKAGE_VERSION "$ENV{TRAVIS_TAG}")
|
||||
elseif (GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
|
||||
# Working off a git repo, using git versioning
|
||||
|
||||
# Check if HEAD is pointing to a tag
|
||||
execute_process (
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --always
|
||||
|
@ -40,9 +41,23 @@ elseif (EXISTS ${PROJECT_SOURCE_DIR}/.version)
|
|||
# we can extract the package version from .version file.
|
||||
file (STRINGS .version STLINK_PACKAGE_VERSION)
|
||||
else ()
|
||||
set (STLINK_PACKAGE_VERSION "Unknown")
|
||||
set (STLINK_PACKAGE_VERSION "999.99.99-unknown")
|
||||
endif()
|
||||
|
||||
# We shall use STLINK_PACKAGE_VERSION* variables to set soversion and other stuff
|
||||
# Since these numbers will appear in .so names, e.g. libstlink.so.1.2.0
|
||||
# We can't just use STLINK_PACKAGE_VERSION here
|
||||
# (Well, we can, but that breaks all the existing conventions)
|
||||
# We can't as well use PROJECT_VERSION* variables here, since they are managed
|
||||
# by project() directive and the whole version detection relies on PROJECT_SOURCE_DIR
|
||||
|
||||
string(REPLACE "." ";" STLINK_PACKAGE_VERSION_ARRAY ${STLINK_PACKAGE_VERSION})
|
||||
string(REPLACE "-" ";" STLINK_PACKAGE_VERSION_ARRAY "${STLINK_PACKAGE_VERSION_ARRAY}")
|
||||
list(GET STLINK_PACKAGE_VERSION_ARRAY 0 STLINK_PACKAGE_VERSION_MAJOR)
|
||||
list(GET STLINK_PACKAGE_VERSION_ARRAY 1 STLINK_PACKAGE_VERSION_MINOR)
|
||||
list(GET STLINK_PACKAGE_VERSION_ARRAY 2 STLINK_PACKAGE_VERSION_PATCH)
|
||||
list(GET STLINK_PACKAGE_VERSION_ARRAY 3 STLINK_PACKAGE_VERSION_TAG)
|
||||
|
||||
if(WIN32)
|
||||
find_package(7Zip REQUIRED)
|
||||
message(STATUS "7Zip Location: " ${ZIP_LOCATION})
|
||||
|
@ -133,11 +148,30 @@ include_directories(${LIBUSB_INCLUDE_DIR})
|
|||
include_directories(include)
|
||||
include_directories(src/mingw)
|
||||
|
||||
add_library(${PROJECT_NAME} STATIC
|
||||
set(STLINK_LIB_STATIC ${PROJECT_NAME}-static)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
${STLINK_HEADERS} # header files for ide projects generated by cmake
|
||||
${STLINK_SOURCE})
|
||||
target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY})
|
||||
|
||||
if (WIN32 OR MSYS OR MINGW)
|
||||
set(STLINK_SHARED_VERSION
|
||||
${STLINK_PACKAGE_VERSION_MAJOR}.${STLINK_PACKAGE_VERSION_MINOR})
|
||||
else()
|
||||
set(STLINK_SHARED_VERSION
|
||||
${STLINK_PACKAGE_VERSION_MAJOR}.${STLINK_PACKAGE_VERSION_MINOR}.${STLINK_PACKAGE_VERSION_PATCH})
|
||||
endif()
|
||||
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES SOVERSION ${STLINK_PACKAGE_VERSION_MAJOR}
|
||||
VERSION ${STLINK_SHARED_VERSION})
|
||||
|
||||
add_library(${STLINK_LIB_STATIC} STATIC
|
||||
${STLINK_HEADERS} # header files for ide projects generated by cmake
|
||||
${STLINK_SOURCE})
|
||||
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY})
|
||||
set_target_properties(${STLINK_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
|
||||
|
||||
if (APPLE)
|
||||
find_library(ObjC objc)
|
||||
find_library(CoreFoundation CoreFoundation)
|
||||
|
@ -163,10 +197,48 @@ else ()
|
|||
target_link_libraries(st-util ${PROJECT_NAME})
|
||||
endif ()
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} st-flash st-util st-info
|
||||
install(TARGETS ${PROJECT_NAME} ${STLINK_LIB_STATIC} st-flash st-util st-info
|
||||
RUNTIME DESTINATION bin
|
||||
ARCHIVE DESTINATION lib
|
||||
ARCHIVE DESTINATION lib/${CMAKE_LIBRARY_PATH}
|
||||
LIBRARY DESTINATION lib/${CMAKE_LIBRARY_PATH}
|
||||
)
|
||||
# Now, install the development headers
|
||||
file(GLOB STLINK_HEADERS
|
||||
"${CMAKE_SOURCE_DIR}/include/stlink/*.h"
|
||||
)
|
||||
|
||||
install(FILES ${CMAKE_SOURCE_DIR}/include/stlink.h
|
||||
DESTINATION include/${CMAKE_LIBRARY_PATH}/stlink-${STLINK_PACKAGE_VERSION}/)
|
||||
|
||||
install(FILES ${STLINK_HEADERS}
|
||||
DESTINATION include/${CMAKE_LIBRARY_PATH}/stlink-${STLINK_PACKAGE_VERSION}/stlink)
|
||||
|
||||
if (NOT APPLE AND NOT WIN32)
|
||||
set(PKG_CONFIG_LIBDIR
|
||||
"\${prefix}/lib/\${deb_host_multiarch}"
|
||||
)
|
||||
set(PKG_CONFIG_INCLUDEDIR
|
||||
"\${prefix}/include/\${deb_host_multiarch}/${PROJECT_NAME}-${STLINK_PACKAGE_VERSION}"
|
||||
)
|
||||
set(PKG_CONFIG_LIBS
|
||||
"-L\${libdir} -l:libstlink.so.${STLINK_PACKAGE_VERSION}"
|
||||
)
|
||||
set(PKG_CONFIG_CFLAGS
|
||||
"-I\${includedir}"
|
||||
)
|
||||
|
||||
set(PKG_CONFIG_REQUIRES
|
||||
"libusb-1.0"
|
||||
)
|
||||
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
||||
)
|
||||
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
|
||||
DESTINATION lib/${CMAKE_LIBRARY_PATH}/pkgconfig/)
|
||||
endif()
|
||||
|
||||
if(NOT MINGW)
|
||||
list(APPEND STLINK_SOURCE src/tools/term.c)
|
||||
|
@ -212,6 +284,6 @@ if (APPLE)
|
|||
set(CPACK_GENERATOR "ZIP")
|
||||
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/dist/osx")
|
||||
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/dist/osx")
|
||||
endif ()
|
||||
endif()
|
||||
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
|
||||
include (CPack)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
libstlink (1.2.1) unstable; urgency=low
|
||||
|
||||
* Initial Debian-Packaged Release.
|
||||
|
||||
-- Andrew 'Necromant' Andrianov <andrew@ncrmnt.org> Sat, 09 Jul 2016 23:16:07 +0300
|
|
@ -0,0 +1 @@
|
|||
9
|
|
@ -0,0 +1,34 @@
|
|||
Source: libstlink
|
||||
Priority: optional
|
||||
Maintainer: Andrew 'Necromant' Andrianov <andrew@ncrmnt.org>
|
||||
Build-Depends: debhelper (>= 9), cmake, libusb-1.0-0-dev, libgtk-3-dev
|
||||
Standards-Version: 3.9.5
|
||||
Section: libs
|
||||
Homepage: <insert the upstream URL, if relevant>
|
||||
Vcs-Git: https://github.com/texane/stlink.git
|
||||
Vcs-Browser: https://github.com/texane/stlink
|
||||
|
||||
Package: libstlink-dev
|
||||
Section: libdevel
|
||||
Architecture: any
|
||||
Depends: libstlink (= ${binary:Version}), ${misc:Depends}
|
||||
Description: OpenSource ST-Link tools replacement. Development headers.
|
||||
This package contains development headers for libstlink.
|
||||
|
||||
Package: libstlink
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: OpenSource ST-Link tools replacement. Shared library.
|
||||
This package libstlink shared library.
|
||||
|
||||
Package: stlink-tools
|
||||
Section: libdevel
|
||||
Architecture: any
|
||||
Depends: libstlink (= ${binary:Version}), ${misc:Depends}
|
||||
Description: OpenSource ST-Link tools replacement. Commandline Utilities.
|
||||
|
||||
Package: stlink-gui
|
||||
Section: libdevel
|
||||
Architecture: any
|
||||
Depends: libstlink (= ${binary:Version}), ${misc:Depends}
|
||||
Description: OpenSource ST-Link tools replacement. GUI Tool.
|
|
@ -0,0 +1,2 @@
|
|||
usr/lib
|
||||
usr/include
|
|
@ -0,0 +1,3 @@
|
|||
usr/include/*
|
||||
usr/lib/*/lib*.a
|
||||
usr/lib/*/pkgconfig/*
|
|
@ -0,0 +1 @@
|
|||
usr/lib
|
|
@ -0,0 +1 @@
|
|||
usr/lib/*/lib*.so*
|
|
@ -0,0 +1,28 @@
|
|||
#!/usr/bin/make -f
|
||||
# See debhelper(7) (uncomment to enable)
|
||||
# output every command that modifies files on the build system.
|
||||
#DH_VERBOSE = 1
|
||||
|
||||
# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
|
||||
DPKG_EXPORT_BUILDFLAGS = 1
|
||||
include /usr/share/dpkg/default.mk
|
||||
|
||||
# see FEATURE AREAS in dpkg-buildflags(1)
|
||||
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
|
||||
|
||||
# see ENVIRONMENT in dpkg-buildflags(1)
|
||||
# package maintainers to append CFLAGS
|
||||
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
|
||||
# package maintainers to append LDFLAGS
|
||||
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
|
||||
|
||||
|
||||
# main packaging script based on dh7 syntax
|
||||
%:
|
||||
dh $@
|
||||
|
||||
# debmake generated override targets
|
||||
# This is example for Cmake (See http://bugs.debian.org/641051 )
|
||||
override_dh_auto_configure:
|
||||
dh_auto_configure -- \
|
||||
-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
|
|
@ -0,0 +1 @@
|
|||
3.0 (native)
|
|
@ -0,0 +1,2 @@
|
|||
/usr/bin
|
||||
/usr/share/
|
|
@ -0,0 +1,2 @@
|
|||
/usr/bin/stlink-gui*
|
||||
/usr/share/*
|
|
@ -0,0 +1,2 @@
|
|||
/usr/bin
|
||||
|
|
@ -0,0 +1 @@
|
|||
/usr/bin/st-*
|
|
@ -0,0 +1,28 @@
|
|||
# Warning: This example assumes that you are building on a host
|
||||
# with pkg-config available (e.g. linux). The logic required to
|
||||
# build under windows/mingw and/or mac was intentionally omitted
|
||||
# to keep this CMakeLists as small as possible
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(st-hello)
|
||||
set(PROJECT_VERSION 0.1)
|
||||
set(SRCS main.c)
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(STLINK REQUIRED stlink)
|
||||
|
||||
set(CMAKE_C_FLAGS " ${STLINK_CFLAGS_OTHER} -Wall -Werror")
|
||||
|
||||
include_directories(
|
||||
${STLINK_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SRCS})
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
${STLINK_LIBRARIES}
|
||||
)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
DESTINATION bin)
|
|
@ -0,0 +1,2 @@
|
|||
This is a simple standalone application example that uses libstlink.
|
||||
You can use this as a boilerplate for your own app development
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stlink.h>
|
||||
|
||||
static stlink_t *stlink_open_first(void)
|
||||
{
|
||||
stlink_t* sl = NULL;
|
||||
sl = stlink_v1_open(0, 1);
|
||||
if (sl == NULL)
|
||||
sl = stlink_open_usb(0, 1, NULL);
|
||||
|
||||
return sl;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
stlink_t* sl = NULL;
|
||||
sl = stlink_open_first();
|
||||
|
||||
if (sl == NULL) {
|
||||
fprintf(stderr, "Failed to open stlink device ;(\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
fprintf(stderr, "STlink device opened, that's cool!\n");
|
||||
stlink_close(sl);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
deb_host_multiarch=${CMAKE_LIBRARY_PATH}
|
||||
Name: ${PROJECT_NAME}
|
||||
Description: ${PROJECT_DESCRIPTION}
|
||||
Version: ${PROJECT_VERSION}
|
||||
Requires: ${PKG_CONFIG_REQUIRES}
|
||||
prefix=${CMAKE_INSTALL_PREFIX}
|
||||
includedir=${PKG_CONFIG_INCLUDEDIR}
|
||||
libdir=${PKG_CONFIG_LIBDIR}
|
||||
Libs: ${PKG_CONFIG_LIBS}
|
||||
Cflags: ${PKG_CONFIG_CFLAGS}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
# Run this hacky script in project root directory to start
|
||||
# clang static analysis. Adjust ccc-analyzer path if nesesary
|
||||
CCC_ANALYZER=/usr/share/clang/scan-build-3.5/ccc-analyzer
|
||||
mkdir -p build-clang-analyze/reports
|
||||
cd build-clang-analyze
|
||||
cmake -DCMAKE_C_COMPILER=${CCC_ANALYZER} $* ..
|
||||
scan-build -o ./reports --keep-empty make
|
Ładowanie…
Reference in New Issue