2016-04-07 08:01:20 +00:00
|
|
|
cmake_minimum_required(VERSION 2.8.7)
|
2017-06-17 06:05:47 +00:00
|
|
|
set(CMAKE_USER_MAKE_RULES_OVERRIDE cmake/c_flag_overrides.cmake)
|
2016-07-09 20:07:50 +00:00
|
|
|
project(stlink C)
|
|
|
|
set(PROJECT_DESCRIPTION "Open source version of the STMicroelectronics Stlink Tools")
|
2016-10-26 18:40:25 +00:00
|
|
|
set(STLINK_UDEV_RULES_DIR "/etc/udev/rules.d" CACHE PATH "Udev rules directory")
|
|
|
|
set(STLINK_MODPROBED_DIR "/etc/modprobe.d" CACHE PATH "modprobe.d directory")
|
2018-04-17 08:30:31 +00:00
|
|
|
set(STLINK_STATIC_LIB ON CACHE BOOL "Install static lib")
|
2018-03-28 07:49:14 +00:00
|
|
|
|
2018-04-16 18:54:03 +00:00
|
|
|
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}")
|
2018-03-28 07:49:14 +00:00
|
|
|
else()
|
2018-04-16 18:54:03 +00:00
|
|
|
set(LIB_INSTALL_DIR "lib" CACHE PATH "Main library directory")
|
|
|
|
set(STLINK_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" )
|
2018-03-28 07:49:14 +00:00
|
|
|
endif()
|
|
|
|
|
2018-04-16 18:54:03 +00:00
|
|
|
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}" )
|
2018-03-28 07:49:14 +00:00
|
|
|
else()
|
2018-04-16 18:54:03 +00:00
|
|
|
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
|
|
|
|
2016-10-22 07:44:37 +00:00
|
|
|
option(STLINK_GENERATE_MANPAGES "Generate manpages with pandoc" OFF)
|
2018-10-24 17:33:02 +00:00
|
|
|
option(STLINK_INSTALL_UDEV_RULES "Install udev rules files" ON)
|
|
|
|
option(STLINK_INSTALL_MODPROBE_CONF "Install modprobe conf files" ON)
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2016-06-18 14:19:09 +00:00
|
|
|
if (POLICY CMP0042)
|
|
|
|
# Newer cmake on MacOS should use @rpath
|
|
|
|
cmake_policy (SET CMP0042 NEW)
|
|
|
|
endif ()
|
|
|
|
|
2016-05-05 10:52:58 +00:00
|
|
|
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")
|
2016-09-15 20:29:59 +00:00
|
|
|
include(cmake/Version.cmake)
|
2018-03-28 07:49:14 +00:00
|
|
|
if(NOT MSVC)
|
|
|
|
include(cmake/CFlags.cmake)
|
|
|
|
endif()
|
2016-05-05 10:52:58 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
###
|
|
|
|
# Dependencies
|
|
|
|
###
|
2016-05-05 10:52:58 +00:00
|
|
|
find_package(LibUSB REQUIRED)
|
2017-05-05 10:16:38 +00:00
|
|
|
if (NOT APPLE AND NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
|
2016-06-18 14:19:09 +00:00
|
|
|
find_package(PkgConfig)
|
|
|
|
pkg_check_modules(gtk gtk+-3.0)
|
|
|
|
endif ()
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2016-10-22 07:44:37 +00:00
|
|
|
include(CheckIncludeFile)
|
2016-08-03 09:04:20 +00:00
|
|
|
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()
|
|
|
|
|
2017-06-29 19:33:31 +00:00
|
|
|
CHECK_INCLUDE_FILE(unistd.h STLINK_HAVE_UNISTD_H)
|
|
|
|
if (STLINK_HAVE_UNISTD_H)
|
|
|
|
add_definitions(-DSTLINK_HAVE_UNISTD_H)
|
|
|
|
endif()
|
|
|
|
|
2016-09-15 20:29:59 +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
|
|
|
|
2016-05-16 08:21:04 +00:00
|
|
|
set(STLINK_HEADERS
|
|
|
|
include/stlink.h
|
|
|
|
include/stlink/usb.h
|
|
|
|
include/stlink/sg.h
|
|
|
|
include/stlink/logging.h
|
|
|
|
include/stlink/mmap.h
|
|
|
|
include/stlink/chipid.h
|
2016-05-20 18:03:57 +00:00
|
|
|
include/stlink/flash_loader.h
|
2016-05-05 12:46:42 +00:00
|
|
|
)
|
|
|
|
|
2016-05-16 08:21:04 +00:00
|
|
|
set(STLINK_SOURCE
|
|
|
|
src/chipid.c
|
|
|
|
src/common.c
|
|
|
|
src/usb.c
|
|
|
|
src/sg.c
|
|
|
|
src/logging.c
|
2016-05-20 18:03:57 +00:00
|
|
|
src/flash_loader.c
|
2016-05-05 12:46:42 +00:00
|
|
|
)
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2016-06-18 14:19:09 +00:00
|
|
|
if (WIN32 OR MSYS OR MINGW)
|
2017-01-28 10:49:06 +00:00
|
|
|
set (STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c")
|
2019-05-11 17:41:57 +00:00
|
|
|
set (STLINK_HEADERS "${STLINK_HEADERS};src/mingw/mingw.h")
|
2016-06-18 14:19:09 +00:00
|
|
|
endif ()
|
|
|
|
|
2016-05-05 10:52:58 +00:00
|
|
|
include_directories(${LIBUSB_INCLUDE_DIR})
|
2016-05-05 12:46:42 +00:00
|
|
|
include_directories(include)
|
2016-09-15 20:29:59 +00:00
|
|
|
include_directories(${PROJECT_BINARY_DIR}/include)
|
2016-05-05 12:46:42 +00:00
|
|
|
include_directories(src/mingw)
|
2017-06-17 06:05:47 +00:00
|
|
|
if (MSVC)
|
2017-06-29 19:33:31 +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)
|
2017-06-17 06:05:47 +00:00
|
|
|
endif ()
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2017-01-28 10:30:30 +00:00
|
|
|
###
|
2016-09-15 20:29:59 +00:00
|
|
|
# Shared library
|
2017-01-28 10:30:30 +00:00
|
|
|
###
|
2018-03-16 15:41:07 +00:00
|
|
|
if (NOT WIN32)
|
|
|
|
set(STLINK_LIB_SHARED ${PROJECT_NAME})
|
|
|
|
else ()
|
2017-01-28 10:30:30 +00:00
|
|
|
set(STLINK_LIB_SHARED ${PROJECT_NAME}-shared)
|
2018-03-16 15:41:07 +00:00
|
|
|
endif()
|
2017-01-28 10:30:30 +00:00
|
|
|
|
|
|
|
add_library(${STLINK_LIB_SHARED} SHARED
|
2016-09-15 20:29:59 +00:00
|
|
|
${STLINK_HEADERS} # header files for ide projects generated by cmake
|
|
|
|
${STLINK_SOURCE}
|
|
|
|
)
|
2017-01-28 10:30:30 +00:00
|
|
|
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY})
|
2016-05-20 18:36:41 +00:00
|
|
|
|
2016-07-09 20:07:50 +00:00
|
|
|
if (WIN32 OR MSYS OR MINGW)
|
2016-09-15 20:29:59 +00:00
|
|
|
set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
|
2016-07-09 20:07:50 +00:00
|
|
|
else()
|
2016-09-15 20:29:59 +00:00
|
|
|
set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
|
2016-07-09 20:07:50 +00:00
|
|
|
endif()
|
|
|
|
|
2017-01-28 10:30:30 +00:00
|
|
|
set_target_properties(${STLINK_LIB_SHARED}
|
2016-09-15 20:29:59 +00:00
|
|
|
PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}
|
|
|
|
VERSION ${STLINK_SHARED_VERSION}
|
|
|
|
)
|
2016-07-09 20:07:50 +00:00
|
|
|
|
2017-01-28 10:30:30 +00:00
|
|
|
# Link shared library with apple OS libraries
|
2016-05-20 18:36:41 +00:00
|
|
|
if (APPLE)
|
|
|
|
find_library(ObjC objc)
|
|
|
|
find_library(CoreFoundation CoreFoundation)
|
|
|
|
find_library(IOKit IOKit)
|
2017-01-28 10:30:30 +00:00
|
|
|
target_link_libraries(${STLINK_LIB_SHARED} ${CoreFoundation} ${IOKit} ${ObjC})
|
2017-01-28 10:49:06 +00:00
|
|
|
endif()
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2017-01-28 10:30:30 +00:00
|
|
|
if (WIN32 OR MSYS OR MINGW)
|
|
|
|
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} wsock32 ws2_32)
|
2016-09-15 13:05:00 +00:00
|
|
|
else()
|
2017-01-28 10:30:30 +00:00
|
|
|
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY})
|
2016-09-15 13:05:00 +00:00
|
|
|
endif()
|
|
|
|
|
2018-03-28 07:49:14 +00:00
|
|
|
|
2017-01-28 10:30:30 +00:00
|
|
|
install(TARGETS ${STLINK_LIB_SHARED}
|
2017-04-05 18:48:07 +00:00
|
|
|
DESTINATION ${STLINK_LIBRARY_PATH}
|
2016-07-09 20:07:50 +00:00
|
|
|
)
|
2016-09-15 02:58:49 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
###
|
|
|
|
# Static library
|
|
|
|
###
|
|
|
|
set(STLINK_LIB_STATIC ${PROJECT_NAME}-static)
|
2016-07-09 20:07:50 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
add_library(${STLINK_LIB_STATIC} STATIC
|
|
|
|
${STLINK_HEADERS} # header files for ide projects generated by cmake
|
|
|
|
${STLINK_SOURCE}
|
|
|
|
)
|
2017-01-28 10:30:30 +00:00
|
|
|
|
|
|
|
# Link shared library with apple OS libraries
|
|
|
|
if (APPLE)
|
|
|
|
find_library(ObjC objc)
|
|
|
|
find_library(CoreFoundation CoreFoundation)
|
|
|
|
find_library(IOKit IOKit)
|
|
|
|
target_link_libraries(${STLINK_LIB_STATIC} ${CoreFoundation} ${IOKit} ${ObjC})
|
2017-01-28 10:49:06 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if (WIN32 OR MSYS OR MINGW)
|
|
|
|
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} wsock32 ws2_32)
|
|
|
|
else()
|
|
|
|
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY})
|
|
|
|
endif()
|
2017-01-28 10:30:30 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
set_target_properties(${STLINK_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
|
2016-07-09 20:07:50 +00:00
|
|
|
|
2018-04-17 08:30:31 +00:00
|
|
|
if (STLINK_STATIC_LIB)
|
|
|
|
install(TARGETS ${STLINK_LIB_STATIC}
|
|
|
|
ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}
|
|
|
|
)
|
|
|
|
endif()
|
2016-07-09 20:07:50 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
###
|
|
|
|
# Tools
|
|
|
|
###
|
|
|
|
add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c)
|
2017-01-28 10:30:30 +00:00
|
|
|
if (WIN32 OR APPLE)
|
|
|
|
target_link_libraries(st-flash ${STLINK_LIB_STATIC})
|
|
|
|
else()
|
|
|
|
target_link_libraries(st-flash ${STLINK_LIB_SHARED})
|
|
|
|
endif()
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
add_executable(st-info src/tools/info.c)
|
2017-01-28 10:30:30 +00:00
|
|
|
if (WIN32 OR APPLE)
|
|
|
|
target_link_libraries(st-info ${STLINK_LIB_STATIC})
|
|
|
|
else()
|
|
|
|
target_link_libraries(st-info ${STLINK_LIB_SHARED})
|
|
|
|
endif()
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
install(TARGETS st-flash st-info
|
|
|
|
RUNTIME DESTINATION bin
|
|
|
|
)
|
2015-11-17 00:50:08 +00:00
|
|
|
|
2016-09-23 09:54:43 +00:00
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
2018-10-24 17:33:02 +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()
|
2016-09-23 09:54:43 +00:00
|
|
|
endif()
|
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
add_subdirectory(src/gdbserver)
|
|
|
|
add_subdirectory(src/tools/gui)
|
2016-05-20 22:23:23 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
###
|
|
|
|
# Others
|
|
|
|
###
|
|
|
|
add_subdirectory(usr/lib/pkgconfig)
|
2016-09-15 08:44:01 +00:00
|
|
|
add_subdirectory(include)
|
|
|
|
add_subdirectory(doc/man)
|
2016-05-20 22:23:23 +00:00
|
|
|
add_subdirectory(tests)
|
2016-06-18 14:19:09 +00:00
|
|
|
|
2016-09-15 20:29:59 +00:00
|
|
|
include(cmake/CPackConfig.cmake)
|
|
|
|
include(CPack)
|