File: CMakeLists.txt

package info (click to toggle)
stlink 1.5.0+ds-2~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 916 kB
  • sloc: ansic: 8,636; asm: 188; makefile: 43; sh: 25
file content (198 lines) | stat: -rw-r--r-- 5,207 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
cmake_minimum_required(VERSION 2.8.7)
set(CMAKE_USER_MAKE_RULES_OVERRIDE cmake/c_flag_overrides.cmake)
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")
set(LIB_INSTALL_DIR "lib" CACHE PATH "Main library directory")
set(STLINK_LIBRARY_PATH "${LIB_INSTALL_DIR}/${CMAKE_LIBRARY_PATH}" CACHE PATH "Target lib 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 AND NOT CMAKE_CROSSCOMPILING)
	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()

CHECK_INCLUDE_FILE(unistd.h STLINK_HAVE_UNISTD_H)
if (STLINK_HAVE_UNISTD_H)
	add_definitions(-DSTLINK_HAVE_UNISTD_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")
endif ()

include_directories(${LIBUSB_INCLUDE_DIR})
include_directories(include)
include_directories(${PROJECT_BINARY_DIR}/include)
include_directories(src/mingw)
if (MSVC)
	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 ()

###
# Shared library
###
if (NOT WIN32)
set(STLINK_LIB_SHARED ${PROJECT_NAME})
else ()
set(STLINK_LIB_SHARED ${PROJECT_NAME}-shared)
endif()

add_library(${STLINK_LIB_SHARED} SHARED
	${STLINK_HEADERS} # header files for ide projects generated by cmake
	${STLINK_SOURCE}
)
target_link_libraries(${STLINK_LIB_SHARED} ${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(${STLINK_LIB_SHARED}
	PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}
	VERSION ${STLINK_SHARED_VERSION}
)

# 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_SHARED} ${CoreFoundation} ${IOKit} ${ObjC})
endif()

if (WIN32 OR MSYS OR MINGW)
	target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} wsock32 ws2_32)
else()
	target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY})
endif()

install(TARGETS ${STLINK_LIB_SHARED}
	DESTINATION ${STLINK_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}
)

# 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})
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()

set_target_properties(${STLINK_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})

install(TARGETS ${STLINK_LIB_STATIC}
	ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}
)

###
# Tools
###
add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c)
if (WIN32 OR APPLE)
	target_link_libraries(st-flash ${STLINK_LIB_STATIC})
else()
	target_link_libraries(st-flash ${STLINK_LIB_SHARED})
endif()

add_executable(st-info src/tools/info.c)
if (WIN32 OR APPLE)
	target_link_libraries(st-info ${STLINK_LIB_STATIC})
else()
	target_link_libraries(st-info ${STLINK_LIB_SHARED})
endif()

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)