-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathCMakeLists.txt
139 lines (114 loc) · 4.03 KB
/
CMakeLists.txt
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
project(stlink C)
cmake_minimum_required(VERSION 2.8.7)
include(CheckCCompilerFlag)
include(CheckIncludeFile)
find_package(PkgConfig)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")
find_package(LibUSB REQUIRED)
pkg_check_modules(gtk gtk+-3.0)
function(add_cflag_if_supported flag)
string(REPLACE "-" "_" flagclean ${flag})
string(REPLACE "=" "_" flagclean ${flagclean})
string(REPLACE "+" "_" flagclean ${flagclean})
string(REPLACE "," "_" flagclean ${flagclean})
string(TOUPPER ${flagclean} flagclean)
check_c_compiler_flag(${flag} C_SUPPORTS${flagclean})
if (C_SUPPORTS${flagclean})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
endif()
endfunction()
add_cflag_if_supported("-std=gnu99")
add_cflag_if_supported("-Wall")
add_cflag_if_supported("-Wextra")
add_cflag_if_supported("-Wshadow")
add_cflag_if_supported("-D_FORTIFY_SOURCE=2")
add_cflag_if_supported("-fstrict-aliasing")
add_cflag_if_supported("-Wformat")
add_cflag_if_supported("-Wformat-security")
add_cflag_if_supported("-Wmaybe-uninitialized")
add_cflag_if_supported("-Wmissing-variable-declarations")
add_cflag_if_supported("-Wshorten-64-to-32")
add_cflag_if_supported("-Wimplicit-function-declaration")
add_cflag_if_supported("-Wredundant-decls")
add_cflag_if_supported("-Wundef")
add_cflag_if_supported("-fPIC")
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
include(CTest)
add_cflag_if_supported("-ggdb")
add_cflag_if_supported("-O0")
elseif()
add_cflag_if_supported("-O2")
endif()
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()
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
)
include_directories(${LIBUSB_INCLUDE_DIR})
include_directories(include)
include_directories(src/mingw)
add_library(${PROJECT_NAME} STATIC
${STLINK_HEADERS} # header files for ide projects generated by cmake
${STLINK_SOURCE})
target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY})
if (APPLE)
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
target_link_libraries(${PROJECT_NAME} ${CoreFoundation} ${IOKit} ${ObjC})
endif()
add_executable(st-flash src/tools/flash.c)
target_link_libraries(st-flash ${PROJECT_NAME})
add_executable(st-info src/tools/info.c)
target_link_libraries(st-info ${PROJECT_NAME})
add_executable(st-util src/gdbserver/gdb-remote.c
src/gdbserver/gdb-remote.h
src/gdbserver/gdb-server.c
src/gdbserver/gdb-server.h)
target_link_libraries(st-util ${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} st-flash st-util st-info
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
)
if(NOT MINGW)
list(APPEND STLINK_SOURCE src/tools/term.c)
add_executable(st-term src/tools/term.c)
target_link_libraries(st-term ${PROJECT_NAME})
install(TARGETS st-term
RUNTIME DESTINATION bin)
endif()
if(gtk_FOUND)
include_directories(SYSTEM ${gtk_INCLUDE_DIRS})
set(GUI_SOURCES src/tools/gui/stlink-gui.c
src/tools/gui/stlink-gui.h)
add_executable(stlink-gui-local ${GUI_SOURCES})
set_target_properties(stlink-gui-local PROPERTIES
COMPILE_FLAGS -DSTLINK_UI_DIR=\\"${CMAKE_CURRENT_SOURCE_DIR}/gui\\")
target_link_libraries(stlink-gui-local stlink ${gtk_LDFLAGS})
set(INSTALLED_UI_DIR ${CMAKE_INSTALL_PREFIX}/share)
add_executable(stlink-gui ${GUI_SOURCES})
set_target_properties(stlink-gui PROPERTIES
COMPILE_FLAGS -DSTLINK_UI_DIR=\\"${INSTALLED_UI_DIR}\\")
target_link_libraries(stlink-gui stlink ${gtk_LDFLAGS})
install(TARGETS stlink-gui
RUNTIME DESTINATION bin)
install(FILES src/tools/gui/stlink-gui.ui
DESTINATION ${INSTALLED_UI_DIR})
endif()
add_subdirectory(tests)