Skip to content

Commit

Permalink
Merge pull request #931 from stlink-org/cmake_pkg
Browse files Browse the repository at this point in the history
Reconfiguration of package build process
  • Loading branch information
Nightwalker-87 authored Apr 20, 2020
2 parents c7874f8 + bc869d7 commit fb9f777
Show file tree
Hide file tree
Showing 20 changed files with 385 additions and 250 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ Features:

- Support for STM32L1, SM32L4 option bytes write (#596, #844, #847)
- CMake now creates an uninstall target (#619, #907)
- Added CMAKEFLAGS and install target (#804, #935)
- Support for STM32G4 (#822)
- Add aliased SRAM2 region in the L496 memory map (#824)
- Improved support for STM32G0 (#825, #850, #856, #857)
- Added postinst script with 'depmod -a' for 'make package' (#845, #931)
- Calculate checksums for flash operations (#862, #924)
- Added usb PID and udev rules for STlink v2.1 found on Nucleo-L432KC and Nucleo-L552ze boards (#900)
- STM32G0/G4 improvements (#910)
- Enable mass erase with a flash programming check
- Handle G4 Cat3 devices with configurable dual bank flash by using a helper
- Calculate checksums for flash operations (#862, #924)

Updates & changes:

Expand All @@ -38,6 +40,8 @@ Updates & changes:
- [doc] Defined version compatibility and installation instructions for macOS (commit 23c071edea45f6e8852fef52d884a680973d6d8f)
- Deprecated old appveyor-mingw script (commit 97484422008df0f75c978627054776f35842a075)
- Enhanced error log with file path for map_file() (#650, #879, #921)
- Refactoring: Overall option code rework (#927)
- Refactoring: Build settings / GUI-Build on UNIX-based systems if GTK3 is detected (#929)

Fixes:

Expand All @@ -56,7 +60,7 @@ Fixes:
- Fixed broken build on 32-bit systems (#919, #920)
- st-flash: minor usage fix and make cmdline parsing more user friendly (#925)
- Better argument parsing for CLI tools: stlink_open_usb can address v1, v2, v3 (#378, #922)
- Restored functionality of make test builds (Regression) (#926)
- Restored functionality of make test builds (Regression) (#926, #929)


v1.6.0
Expand Down Expand Up @@ -258,7 +262,7 @@ Updates and fixes:

* Fixed "unaligned addr or size" when trying to write a program in RAM ([#323](https://github.com/stlink-org/stlink/pull/323))
* Fixed flashing on STM32_F3_SMALL ([#325](https://github.com/stlink-org/stlink/pull/325))
* Fixed STM32L-problem with flash loader ([#390](https://github.com/stlink-org/stlink/pull/390), [#407](https://github.com/stlink-org/stlink/pull/407),[#408](https://github.com/stlink-org/stlink/pull/408))
* Fixed STM32L-problem with flash loader ([#390](https://github.com/stlink-org/stlink/pull/390), [#407](https://github.com/stlink-org/stlink/pull/407), [#408](https://github.com/stlink-org/stlink/pull/408))
* Don't read the target voltage on startup, because it crashes STM32F100 ([#423](https://github.com/stlink-org/stlink/pull/423), [#424](https://github.com/stlink-org/stlink/pull/424))
* Added a useful error message instead of "[!] send_recv" ([#425](https://github.com/stlink-org/stlink/pull/425), [#426](https://github.com/stlink-org/stlink/pull/426))
* Do a JTAG reset prior to reading CPU information when processor is in deep sleep ([#428](https://github.com/stlink-org/stlink/pull/428), [#430](https://github.com/stlink-org/stlink/pull/430), [#451](https://github.com/stlink-org/stlink/pull/451))
Expand Down
58 changes: 38 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
###
# General cmake settings
###

cmake_minimum_required(VERSION 3.4.2)
cmake_policy(SET CMP0042 NEW)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

# Define GNU standard installation directories
include(GNUInstallDirs)


###
# General project settings
###

project(stlink C)
set(PROJECT_DESCRIPTION "Open source version of the STMicroelectronics ST-LINK Tools")

Expand All @@ -14,10 +27,23 @@ option(STLINK_INSTALL_UDEV_RULES "Install udev rules files" ON)
option(STLINK_INSTALL_MODPROBE_CONF "Install modprobe conf files" ON)
option(STLINK_GENERATE_MANPAGES "Generate manpages with pandoc" OFF)

# Determine project version
include(${CMAKE_MODULE_PATH}/get_version.cmake)

# Set C build flags
if (NOT MSVC)
include(${CMAKE_MODULE_PATH}/c_flags.cmake)
else ()
message(STATUS "MSVC C Flags override to /MT")
set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif ()


# ====

#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if (IS_DIRECTORY ${LIB_INSTALL_DIR})
Expand All @@ -36,18 +62,6 @@ else ()
set(STLINK_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}")
endif ()

include(cmake/version.cmake)

if (NOT MSVC)
include(cmake/c_flags.cmake)
else ()
message(STATUS "MSVC C Flags override to /MT")
set(CMAKE_C_FLAGS_DEBUG_INIT "/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT "/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT "/MT /O2 /Ob2 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif ()


###
# Dependencies
Expand Down Expand Up @@ -243,29 +257,33 @@ add_subdirectory(src/stlink-gui)
# Others
###

add_subdirectory(debian/pkg-config)
add_subdirectory(include) ### TODO: Check path
add_subdirectory(doc/man)
add_subdirectory(tests)

include(cmake/cpack_config.cmake)
include(CPack)

# ====


###
# Package build
###

add_subdirectory(cmake/packaging)
include(cmake/packaging/cpack_config.cmake)


###
# Uninstall target
###

if (NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND}
-P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
-P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake
)
endif ()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Open source version of the STMicroelectronics STlink Tools

[![BSD licensed](https://img.shields.io/badge/license-BSD-blue.svg)](https://raw.githubusercontent.com/hyperium/hyper/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/stlink-org/stlink.svg)](https://github.com/stlink-org/stlink/releases/latest)
[![GitHub commits](https://img.shields.io/github/commits-since/stlink-org/stlink/v1.6.0.svg)](https://github.com/stlink-org/stlink/releases/master)
[![GitHub commits](https://img.shields.io/github/commits-since/stlink-org/stlink/v1.6.0.svg)](https://github.com/stlink-org/stlink/releases/develop)
[![Downloads](https://img.shields.io/github/downloads/stlink-org/stlink/total.svg)](https://github.com/stlink-org/stlink/releases)
[![Linux Status](https://img.shields.io/travis/stlink-org/stlink/master.svg?label=linux)](https://travis-ci.org/stlink-org/stlink)
[![macOS Status](https://img.shields.io/travis/stlink-org/stlink/master.svg?label=osx)](https://travis-ci.org/stlink-org/stlink)
Expand Down
27 changes: 0 additions & 27 deletions cmake/cpack_config.cmake

This file was deleted.

25 changes: 0 additions & 25 deletions cmake/linux-mingw32.cmake

This file was deleted.

25 changes: 0 additions & 25 deletions cmake/linux-mingw64.cmake

This file was deleted.

12 changes: 6 additions & 6 deletions cmake/c_flags.cmake → cmake/modules/c_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ add_cflag_if_supported("-Wimplicit-function-declaration")
# /usr/include/sys/types.h:218: warning: previous declaration of 'truncate' was here
##
if (NOT CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
add_cflag_if_supported("-Wredundant-decls")
add_cflag_if_supported("-Wredundant-decls")
endif ()

if (NOT WIN32)
add_cflag_if_supported("-fPIC")
add_cflag_if_supported("-fPIC")
endif ()

if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
add_cflag_if_supported("-ggdb")
add_cflag_if_supported("-O0")
else()
add_cflag_if_supported("-O2")
add_cflag_if_supported("-ggdb")
add_cflag_if_supported("-O0")
else ()
add_cflag_if_supported("-O2")
add_cflag_if_supported("-Werror")
endif ()
File renamed without changes.
4 changes: 4 additions & 0 deletions cmake/packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_subdirectory(debian)
add_subdirectory(fedora)
add_subdirectory(opensuse)
add_subdirectory(windows)
85 changes: 85 additions & 0 deletions cmake/packaging/cpack_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
###
# Configure package
###

set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set(CPACK_SET_DESTDIR "ON")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/dist")

if (APPLE)
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-macosx-amd64")
set(CPACK_INSTALL_PREFIX "")
elseif (WIN32) ### TODO: Binary build config for windows...
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32")
set(CPACK_INSTALL_PREFIX "")

# Sample toolchain file for building for Windows from a Debian/Ubuntu Linux system.
# Typical usage:
# *) install cross compiler: `sudo apt-get install mingw-w64`
# *) cd build
# *) cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw64.cmake ..
# *) cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/linux-mingw32.cmake ..

#set(CMAKE_SYSTEM_NAME Windows)
#set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
#set(TOOLCHAIN_PREFIX i686-w64-mingw32)

# cross compilers to use for C and C++
#set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
#set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
#set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)

# target environment on the build host system
# set 1st to dir with the cross compiler's C/C++ headers/libs
#set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})

# modify default behavior of FIND_XXX() commands to
# search for headers/libs in the target environment and
# search for programs in the build host environment
#set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
#set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND EXISTS "/etc/debian_version")
message(STATUS "Debian-based Linux OS detected")

### Debian-specific
set(CPACK_GENERATOR "DEB")
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Open source STM32 MCU programming toolset")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/stlink-org/stlink")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Luca Boccassi")
set(CPACK_PACKAGE_CONTACT "bluca@debian.org")

## Set debian_revision number
# Convention: Restart the debian_revision at 1 each time the upstream_version is increased.
set(CPACK_DEBIAN_PACKAGE_RELEASE "0")

## Debian package name
# CPack DEB generator generates package file name in deb format:
# <PackageName>_<VersionNumber>-<DebianRevisionNumber>_<DebianArchitecture>.deb
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

## Add CHANGELOG in Debian-specific format
### TODO

## Add license file
### TODO

# Include a postinst-script
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/cmake/packaging/debian/postinst")

### rpm-specific ### TODO: Package config for opensuse should go here...

else ()
### TODO: Package config for fedora should go here...
endif ()


###
# Build package
###

include(CPack)
Empty file.
Loading

0 comments on commit fb9f777

Please sign in to comment.