stlink/CMakeLists.txt

290 wiersze
7.9 KiB
CMake
Czysty Zwykły widok Historia

###
# 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")
2020-04-07 15:11:45 +00:00
set(STLINK_UDEV_RULES_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/udev/rules.d" CACHE PATH "udev rules directory")
set(STLINK_MODPROBED_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/modprobe.d" CACHE PATH "modprobe.d directory")
set(STLINK_STATIC_LIB ON CACHE BOOL "Install static lib")
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_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if (IS_DIRECTORY ${LIB_INSTALL_DIR})
set(LIB_INSTALL_DIR ${LIB_INSTALL_DIR} CACHE PATH "Main library directory")
set(STLINK_LIBRARY_PATH "${LIB_INSTALL_DIR}")
else ()
set(LIB_INSTALL_DIR "lib" CACHE PATH "Main library directory")
set(STLINK_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
endif ()
if (IS_DIRECTORY ${INCLUDE_INSTALL_DIR})
set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR} CACHE PATH "Main include directory")
set(STLINK_INCLUDE_PATH "${INCLUDE_INSTALL_DIR}")
else ()
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "Main include directory")
set(STLINK_INCLUDE_PATH "${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}")
endif ()
2015-11-17 00:50:08 +00:00
2020-04-05 12:57:59 +00:00
###
# Dependencies
###
2020-04-05 12:57:59 +00:00
find_package(_libusb REQUIRED)
2020-04-17 15:01:36 +00:00
if (NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
find_package(PkgConfig)
pkg_check_modules(GTK3 gtk+-3.0)
2016-06-18 14:19:09 +00:00
endif ()
2015-11-17 00:50:08 +00:00
2016-10-22 07:44:37 +00:00
include(CheckIncludeFile)
CHECK_INCLUDE_FILE(sys/mman.h STLINK_HAVE_SYS_MMAN_H)
if (STLINK_HAVE_SYS_MMAN_H)
add_definitions(-DSTLINK_HAVE_SYS_MMAN_H)
endif ()
CHECK_INCLUDE_FILE(unistd.h STLINK_HAVE_UNISTD_H)
if (STLINK_HAVE_UNISTD_H)
add_definitions(-DSTLINK_HAVE_UNISTD_H)
endif ()
2020-03-21 12:48:40 +00:00
include(CheckLibraryExists)
CHECK_LIBRARY_EXISTS(ssp __stack_chk_fail "" _stack_chk_fail_exists)
if (_stack_chk_fail_exists)
2020-03-21 12:48:40 +00:00
set(SSP_LIB ssp)
else ()
2020-03-21 12:48:40 +00:00
set(SSP_LIB "")
endif ()
2020-03-21 12:48:40 +00:00
if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif ()
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
include(CTest)
endif ()
2016-06-18 14:19:09 +00:00
set(STLINK_HEADERS
2020-04-05 12:57:59 +00:00
include/stlink.h
include/stlink/usb.h
include/stlink/sg.h
include/stlink/logging.h
include/stlink/mmap.h
include/stlink/chipid.h
include/stlink/flash_loader.h
)
set(STLINK_SOURCE
2020-04-05 12:57:59 +00:00
src/chipid.c
src/common.c
src/usb.c
src/sg.c
src/logging.c
src/flash_loader.c
2020-04-13 09:12:58 +00:00
src/md5.c
2020-04-05 12:57:59 +00:00
)
2015-11-17 00:50:08 +00:00
2020-04-17 11:21:07 +00:00
if (WIN32 OR MINGW OR MSYS)
2020-04-15 14:20:17 +00:00
set(STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c")
set(STLINK_HEADERS "${STLINK_HEADERS};src/mingw/mingw.h")
2016-06-18 14:19:09 +00:00
endif ()
include_directories(${LIBUSB_INCLUDE_DIR})
include_directories(include)
include_directories(${PROJECT_BINARY_DIR}/include)
include_directories(src/mingw)
2020-04-17 11:21:07 +00:00
if (MSVC)
2020-04-05 12:57:59 +00:00
include_directories(src/win32)
include_directories(src/getopt)
# Use string.h rather than strings.h and disable annoying warnings
add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710)
endif ()
2015-11-17 00:50:08 +00:00
2020-04-05 12:57:59 +00:00
###
# Shared library
###
2020-04-05 12:57:59 +00:00
Debian packaging, CMake and README.md fixes (#683) * Use https for debian/copyright * Update dates and fix stanzas in debian/copyright No need to have 2 stanzas for the same license * Add BSD-3-clause body in debian/copyright * Remove generated boilerplate from debian/rules * Enable compiler hardening flags in debian/rules * Fix source package name according to repo and docs * Set source package section to electronics See https://packages.debian.org/unstable/electronics/ for a full list * Add long descriptions to packages * Add gbp.conf file * Update changelog for 1.5.0 release * Remove dirs files, not needed anymore * Rename library package to match SONAME As per Debian policy, shared library packages must be named after their SONAME version. * libstlink0: break+replace libstlink since it took over its files * Remove triggers, not needed anymore debhelper tools will generate the triggers file automatically since the package name was corrected * List GPL2+ in debian/copyright for flashloaders * Do not append -shared to shared library on *NIX Only on Windows it's necessary to have different file names, on *NIX the extension is what disambiguates between a static library (.a) and a shared library (.so). * Clarify license of flashloaders in README.md Fixes #682 * List all individual authors in debian/copyright The Debian FTP masters nowadays require that all authors are listed in debian/copyright. Print the list of authors from git. * Move modprobe and udev files from shared library package to tools package Multiple versions of a shared library might be installed on the same system. Do not ship unversioned files in their packages, or they will conflict and fail to install. * stlink-tools: break+replace libstlink It took ownership of udev and modprobe files from libstlink * Fix pkgconfig include dir: remove project version The headers are installed in /usr/include/stlink without a version number. * Add libstlink1 symbols file Generated with: dpkg-gensymbols -P/tmp -v1.5.0 -V -e/tmp/libstlink.so.1.5.0 -plibstlink1 -Odebian/libstlink1.symbols * Bump Standards-Version to 4.1.3 Main changes are shared library rename and files moved, and HTTPS URLs. https://www.debian.org/doc/packaging-manuals/upgrading-checklist.txt * Add debian/watch file for notifications The Debian package tracker can automatically notify when a new version is out.
2018-03-16 15:41:07 +00:00
if (NOT WIN32)
set(STLINK_LIB_SHARED ${PROJECT_NAME})
2020-04-17 11:21:07 +00:00
else (WIN32)
set(STLINK_LIB_SHARED ${PROJECT_NAME}-shared)
endif ()
add_library(
${STLINK_LIB_SHARED} SHARED
2020-04-05 12:57:59 +00:00
${STLINK_HEADERS} # header files for ide projects generated by cmake
${STLINK_SOURCE}
)
target_link_libraries(
${STLINK_LIB_SHARED}
${LIBUSB_LIBRARY}
)
set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
message(STATUS "STLINK_LIB_SHARED: ${STLINK_LIB_SHARED}")
message(STATUS "PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}")
message(STATUS "VERSION: ${STLINK_SHARED_VERSION}")
set_target_properties(${STLINK_LIB_SHARED} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${STLINK_SHARED_VERSION}
)
# Link shared library with Apple macOS libraries
if (APPLE)
2020-04-05 12:57:59 +00:00
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
2020-03-21 12:48:40 +00:00
target_link_libraries(${STLINK_LIB_SHARED} ${CoreFoundation} ${IOKit} ${ObjC} ${SSP_LIB})
endif ()
2015-11-17 00:50:08 +00:00
2020-04-17 11:21:07 +00:00
if (WIN32 OR MINGW OR MSYS)
2020-03-21 12:48:40 +00:00
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} wsock32 ws2_32 ${SSP_LIB})
else ()
2020-03-21 12:48:40 +00:00
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif ()
2016-09-15 13:05:00 +00:00
2020-04-17 11:21:07 +00:00
install(TARGETS ${STLINK_LIB_SHARED} DESTINATION ${STLINK_LIBRARY_PATH}) ### TODO: Check path
###
# Static library
###
2020-04-05 12:57:59 +00:00
set(STLINK_LIB_STATIC ${PROJECT_NAME}-static)
2020-04-05 12:57:59 +00:00
add_library(
${STLINK_LIB_STATIC} STATIC
${STLINK_HEADERS} # header files for ide projects generated by cmake
${STLINK_SOURCE}
)
2020-04-17 11:21:07 +00:00
# Link static library with Apple macOS libraries
if (APPLE)
2020-04-05 12:57:59 +00:00
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
2020-03-21 12:48:40 +00:00
target_link_libraries(${STLINK_LIB_STATIC} ${CoreFoundation} ${IOKit} ${ObjC} ${SSP_LIB})
2020-04-05 12:57:59 +00:00
endif ()
2020-04-17 11:21:07 +00:00
if (WIN32 OR MINGW OR MSYS) ### TODO: MinGW OR MSYS on Linux
2020-03-21 12:48:40 +00:00
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} wsock32 ws2_32 ${SSP_LIB})
else ()
2020-03-21 12:48:40 +00:00
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif ()
set_target_properties(${STLINK_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
if (STLINK_STATIC_LIB)
2020-04-17 11:21:07 +00:00
install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}) ### TODO: Check path
endif ()
2020-04-05 12:57:59 +00:00
###
# Tools
###
2020-04-05 12:57:59 +00:00
add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c)
add_executable(st-info src/tools/info.c)
if (WIN32 OR APPLE)
target_link_libraries(st-flash ${STLINK_LIB_STATIC} ${SSP_LIB})
2020-03-21 12:48:40 +00:00
target_link_libraries(st-info ${STLINK_LIB_STATIC} ${SSP_LIB})
else ()
target_link_libraries(st-flash ${STLINK_LIB_SHARED} ${SSP_LIB})
2020-03-21 12:48:40 +00:00
target_link_libraries(st-info ${STLINK_LIB_SHARED} ${SSP_LIB})
endif ()
2015-11-17 00:50:08 +00:00
2020-04-17 11:21:07 +00:00
install(TARGETS st-flash st-info RUNTIME DESTINATION bin) ### TODO: Check path
2015-11-17 00:50:08 +00:00
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
2020-04-05 12:57:59 +00:00
if (STLINK_INSTALL_MODPROBE_CONF)
install(FILES etc/modprobe.d/stlink_v1.conf DESTINATION ${STLINK_MODPROBED_DIR}/)
endif ()
if (STLINK_INSTALL_UDEV_RULES)
file(GLOB RULES_FILES etc/udev/rules.d/*.rules)
install(FILES ${RULES_FILES} DESTINATION ${STLINK_UDEV_RULES_DIR}/)
endif ()
endif ()
add_subdirectory(src/gdbserver)
add_subdirectory(src/stlink-gui)
2020-04-05 12:57:59 +00:00
###
# Others
###
2020-04-05 12:57:59 +00:00
2020-04-17 11:21:07 +00:00
add_subdirectory(include) ### TODO: Check path
add_subdirectory(doc/man)
add_subdirectory(tests)
2016-06-18 14:19:09 +00:00
# ====
###
# 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/cmake_uninstall.cmake"
IMMEDIATE @ONLY
)
add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND}
-P ${CMAKE_CURRENT_BINARY_DIR}/cmake/cmake_uninstall.cmake
)
endif ()