stlink/CMakeLists.txt

154 wiersze
3.7 KiB
CMake

cmake_minimum_required(VERSION 2.8.7)
project(stlink C)
set(PROJECT_DESCRIPTION "Open source version of the STMicroelectronics Stlink Tools")
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")
option(STLINK_GENERATE_MANPAGES "Generate manpages with pandoc" OFF)
if (POLICY CMP0042)
# Newer cmake on MacOS should use @rpath
cmake_policy (SET CMP0042 NEW)
endif ()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")
include(cmake/Version.cmake)
include(cmake/CFlags.cmake)
###
# Dependencies
###
find_package(LibUSB REQUIRED)
if (NOT APPLE AND NOT WIN32)
find_package(PkgConfig)
pkg_check_modules(gtk gtk+-3.0)
endif ()
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()
if (CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif()
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
include(CTest)
endif()
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
include/stlink/flash_loader.h
)
set(STLINK_SOURCE
src/chipid.c
src/common.c
src/usb.c
src/sg.c
src/logging.c
src/flash_loader.c
)
if (WIN32 OR MSYS OR MINGW)
set (STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c") # TODO
endif ()
include_directories(${LIBUSB_INCLUDE_DIR})
include_directories(include)
include_directories(${PROJECT_BINARY_DIR}/include)
include_directories(src/mingw)
# Shared library
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 ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR})
else()
set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
endif()
set_target_properties(${PROJECT_NAME}
PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${STLINK_SHARED_VERSION}
)
if (APPLE)
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
target_link_libraries(${PROJECT_NAME} ${CoreFoundation} ${IOKit} ${ObjC})
endif ()
if(WIN32 OR MSYS OR MINGW)
target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY} wsock32 ws2_32)
else()
target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY})
endif()
install(TARGETS ${PROJECT_NAME}
DESTINATION lib/${CMAKE_LIBRARY_PATH}
)
###
# Static library
###
set(STLINK_LIB_STATIC ${PROJECT_NAME}-static)
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})
install(TARGETS ${STLINK_LIB_STATIC}
ARCHIVE DESTINATION lib/${CMAKE_LIBRARY_PATH}
)
###
# Tools
###
add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c)
target_link_libraries(st-flash ${PROJECT_NAME})
add_executable(st-info src/tools/info.c)
target_link_libraries(st-info ${PROJECT_NAME})
install(TARGETS st-flash st-info
RUNTIME DESTINATION bin
)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
file(GLOB RULES_FILES etc/udev/rules.d/*.rules)
install(FILES etc/modprobe.d/stlink_v1.conf
DESTINATION ${STLINK_MODPROBED_DIR}/)
install(FILES ${RULES_FILES}
DESTINATION ${STLINK_UDEV_RULES_DIR}/)
endif()
add_subdirectory(src/gdbserver)
add_subdirectory(src/tools/gui)
###
# Others
###
add_subdirectory(usr/lib/pkgconfig)
add_subdirectory(include)
add_subdirectory(doc/man)
add_subdirectory(tests)
include(cmake/CPackConfig.cmake)
include(CPack)