Skip to content

Commit f93adb9

Browse files
Fixes for project compilation
- Cleanup for CMakeLists.txt - [doc] Added list of cmake path variables - Fixed stlink-gui install path (Closes stlink-org#1270) (Closes stlink-org#1271) - Replaced path variable for chips directory
1 parent ff81148 commit f93adb9

File tree

10 files changed

+83
-48
lines changed

10 files changed

+83
-48
lines changed

CMakeLists.txt

+70-35
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,69 @@ set(CMAKE_C_STANDARD 11)
1313
set(CMAKE_C_STANDARD_REQUIRED ON)
1414
set(CMAKE_C_EXTENSIONS ON)
1515

16+
###
17+
#
18+
# Default cmake directories:
19+
#
20+
# | Target Type | GNUInstallDirs Variable | Built-In Default |
21+
# | --- | --- | --- |
22+
# | RUNTIME | ${CMAKE_INSTALL_BINDIR} | bin |
23+
# | LIBRARY | ${CMAKE_INSTALL_LIBDIR} | lib |
24+
# | ARCHIVE | ${CMAKE_INSTALL_LIBDIR} | lib |
25+
# | PRIVATE_HEADER | ${CMAKE_INSTALL_INCLUDEDIR} | include |
26+
# | PUBLIC_HEADER | ${CMAKE_INSTALL_INCLUDEDIR} | include |
27+
# | FILE_SET (type HEADERS) | ${CMAKE_INSTALL_INCLUDEDIR} | include |
28+
#
29+
# | TYPE Argument | GNUInstallDirs Variable | Built-In Default |
30+
# | --- | --- | --- |
31+
# | BIN | ${CMAKE_INSTALL_BINDIR} | bin |
32+
# | SBIN | ${CMAKE_INSTALL_SBINDIR} | sbin |
33+
# | LIB | ${CMAKE_INSTALL_LIBDIR} | lib |
34+
# | INCLUDE | ${CMAKE_INSTALL_INCLUDEDIR} | include |
35+
# | SYSCONF | ${CMAKE_INSTALL_SYSCONFDIR} | etc |
36+
# | SHAREDSTATE | ${CMAKE_INSTALL_SHARESTATEDIR} | com |
37+
# | LOCALSTATE | ${CMAKE_INSTALL_LOCALSTATEDIR} | var |
38+
# | RUNSTATE | ${CMAKE_INSTALL_RUNSTATEDIR} | <LOCALSTATE dir>/run |
39+
# | DATA | ${CMAKE_INSTALL_DATADIR} | <DATAROOT dir> |
40+
# | INFO | ${CMAKE_INSTALL_INFODIR} | <DATAROOT dir>/info |
41+
# | LOCALE | ${CMAKE_INSTALL_LOCALEDIR} | <DATAROOT dir>/locale |
42+
# | MAN | ${CMAKE_INSTALL_MANDIR} | <DATAROOT dir>/man |
43+
# | DOC | ${CMAKE_INSTALL_DOCDIR} | <DATAROOT dir>/doc |
44+
#
45+
# ${CMAKE_BINARY_DIR}
46+
# This is the full path to the top level of the current CMake build tree.
47+
# For an in-source build, this would be the same as CMAKE_SOURCE_DIR.
48+
#
49+
# ${CMAKE_SOURCE_DIR}
50+
# This is the full path to the top level of the current CMake source tree.
51+
# For an in-source build, this would be the same as CMAKE_BINARY_DIR.
52+
#
53+
# ${CMAKE_CURRENT_BINARY_DIR}
54+
# The path to the binary directory currently being processed.
55+
# This is the full path to the build directory that is currently being processed by cmake.
56+
# Each directory added by add_subdirectory() will create a binary directory in the build tree,
57+
# and as it is being processed this variable will be set.
58+
# For in-source builds this is the current source directory being processed.
59+
#
60+
# ${CMAKE_CURRENT_SOURCE_DIR}
61+
# The path to the source directory currently being processed.
62+
# This is the full path to the source directory that is currently being processed by cmake.
63+
#
64+
###
65+
1666

1767
###
18-
# General project settings
68+
# General Project Settings
1969
###
2070

2171
project(stlink C)
2272
set(PROJECT_DESCRIPTION "Open source version of the STMicroelectronics ST-LINK Tools")
23-
include(GNUInstallDirs) # Define GNU standard installation directories
73+
include(${CMAKE_MODULE_PATH}/get_version.cmake) # Determine project version
2474

25-
## MCU configuration files
26-
set(CMAKE_CHIPS_SUBDIR stlink/chips)
27-
set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_CHIPS_SUBDIR})
28-
add_definitions( -DETC_STLINK_DIR="${CMAKE_CHIPS_DIR}" )
75+
include(GNUInstallDirs) # Define GNU standard installation directories
2976

30-
## Determine project version
31-
include(${CMAKE_MODULE_PATH}/get_version.cmake)
77+
# Define install directory /usr/share
78+
set(CMAKE_INSTALL_SHAREDIR /usr/share/)
3279

3380
## Set C build flags
3481
if (NOT MSVC)
@@ -178,8 +225,6 @@ endif ()
178225
# Libraries
179226
###
180227

181-
set(STLINK_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Main library install directory")
182-
183228
# Set the environment variable LD_LIBRARY_PATH to point to /usr/local/lib (per default).
184229
execute_process(COMMAND bash -c "export LD_LIBRARY_PATH=${CMAKE_INSTALL_LIBDIR}")
185230

@@ -205,21 +250,15 @@ set_target_properties(${STLINK_LIB_SHARED} PROPERTIES
205250
)
206251

207252
# Link shared library
208-
if (APPLE) # ... with Apple macOS libraries
209-
find_library(ObjC objc)
210-
find_library(CoreFoundation CoreFoundation)
211-
find_library(IOKit IOKit)
212-
find_library(Security Security)
213-
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB} ${ObjC} ${CoreFoundation} ${IOKit} ${Security})
214-
elseif (WIN32) # ... with Windows libraries
253+
if (WIN32) # ... with Windows libraries
215254
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32)
216255
else ()
217256
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB})
218257
endif ()
219258

220259
install(TARGETS ${STLINK_LIB_SHARED}
221-
ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}
222-
LIBRARY DESTINATION ${STLINK_LIBRARY_PATH}
260+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
261+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
223262
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
224263
)
225264

@@ -248,19 +287,13 @@ set_target_properties(${STLINK_LIB_STATIC} PROPERTIES
248287
)
249288

250289
# Link static library
251-
if (APPLE) # ... with Apple macOS libraries
252-
find_library(ObjC objc)
253-
find_library(CoreFoundation CoreFoundation)
254-
find_library(IOKit IOKit)
255-
find_library(Security Security)
256-
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB} ${ObjC} ${CoreFoundation} ${IOKit} ${Security})
257-
elseif (WIN32) # ... with Windows libraries
290+
if (WIN32) # ... with Windows libraries
258291
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32)
259292
else ()
260293
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB})
261294
endif ()
262295

263-
install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH})
296+
install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
264297

265298

266299
###
@@ -284,7 +317,7 @@ add_executable(st-info ${ST-INFO_SOURCES})
284317
add_executable(st-util ${ST-UTIL_SOURCES})
285318
add_executable(st-trace ${ST-TRACE_SOURCES})
286319

287-
if (WIN32 OR APPLE)
320+
if (WIN32)
288321
target_link_libraries(st-flash ${STLINK_LIB_STATIC} ${SSP_LIB})
289322
target_link_libraries(st-info ${STLINK_LIB_STATIC} ${SSP_LIB})
290323
target_link_libraries(st-util ${STLINK_LIB_STATIC} ${SSP_LIB})
@@ -301,10 +334,6 @@ install(TARGETS st-info DESTINATION ${CMAKE_INSTALL_BINDIR})
301334
install(TARGETS st-util DESTINATION ${CMAKE_INSTALL_BINDIR})
302335
install(TARGETS st-trace DESTINATION ${CMAKE_INSTALL_BINDIR})
303336

304-
# Install MCU configuration files
305-
file(GLOB CHIP_FILES ${CMAKE_SOURCE_DIR}/config/chips/*.chip)
306-
install(FILES ${CHIP_FILES} DESTINATION ${CMAKE_CHIPS_DIR})
307-
308337

309338
###
310339
# Device configuration (Linux only)
@@ -326,13 +355,19 @@ endif ()
326355
# Additional build tasks
327356
###
328357

329-
add_subdirectory(src/stlink-gui) # contains subordinate CMakeLists to build GUI
330-
add_subdirectory(tests) # contains subordinate CMakeLists to build test executables
331-
add_subdirectory(cmake/packaging) # contains subordinate CMakeLists to build packages
358+
# MCU configuration files
359+
set(CMAKE_CHIPS_DIR ${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME}/chips)
360+
add_definitions( -DSTLINK_CHIPS_DIR="${CMAKE_CHIPS_DIR}" )
361+
file(GLOB CHIP_FILES ${CMAKE_SOURCE_DIR}/config/chips/*.chip)
362+
install(FILES ${CHIP_FILES} DESTINATION ${CMAKE_CHIPS_DIR})
332363

364+
# Documentation / manpages
333365
option(STLINK_GENERATE_MANPAGES "Generate manpages with pandoc" OFF)
334366
add_subdirectory(doc/man) # contains subordinate CMakeLists to generate manpages
335367

368+
add_subdirectory(src/stlink-gui) # contains subordinate CMakeLists to build GUI
369+
add_subdirectory(tests) # contains subordinate CMakeLists to build test executables
370+
add_subdirectory(cmake/packaging) # contains subordinate CMakeLists to build packages
336371

337372
###
338373
# Uninstall target

cmake/packaging/cpack_config.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (WIN32 AND (NOT EXISTS "/etc/debian_version")) # Wi
2020
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32")
2121
set(CPACK_INSTALL_PREFIX "")
2222

23-
elseif (WIN32) # Windows cross-build on Debian/Ubuntu
23+
elseif (WIN32) # Windows cross-build on Debian/Ubuntu
2424
set(CPACK_GENERATOR "ZIP")
2525
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${TOOLCHAIN_PREFIX}")
2626
set(CPACK_INSTALL_PREFIX "")

doc/man/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ foreach (manpage ${MANPAGES})
3030
endif ()
3131

3232
if (f AND NOT WIN32)
33-
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/man/man1)
33+
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_DATADIR}/man/man1)
3434
unset(f)
3535
endif ()
3636
endforeach ()

src/st-flash/flash.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int main(int ac, char** av) {
6262
}
6363

6464
printf("st-flash %s\n", STLINK_VERSION);
65-
init_chipids (ETC_STLINK_DIR);
65+
init_chipids (STLINK_CHIPS_DIR);
6666

6767
sl = stlink_open_usb(o.log_level, o.connect, (char *)o.serial, o.freq);
6868

src/st-info/info.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int print_data(int ac, char **av) {
6868
return(0);
6969
}
7070

71-
init_chipids(ETC_STLINK_DIR);
71+
init_chipids(STLINK_CHIPS_DIR);
7272

7373
for (int i=2; i<ac; i++) {
7474

src/st-trace/trace.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ int main(int argc, char **argv) {
547547
usage();
548548
return APP_RESULT_INVALID_PARAMS;
549549
}
550-
init_chipids (ETC_STLINK_DIR);
550+
init_chipids (STLINK_CHIPS_DIR);
551551

552552
DLOG("show_help = %s\n", settings.show_help ? "true" : "false");
553553
DLOG("show_version = %s\n", settings.show_version ? "true" : "false");

src/st-util/gdb-server.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int main(int argc, char** argv) {
221221

222222
printf("st-util %s\n", STLINK_VERSION);
223223

224-
init_chipids (ETC_STLINK_DIR);
224+
init_chipids (STLINK_CHIPS_DIR);
225225

226226
sl = stlink_open_usb(state.logging_level, state.connect_mode, state.serialnumber, state.freq);
227227
if (sl == NULL) { return(1); }

src/stlink-gui/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ if (NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
1616

1717
# Install desktop application entry
1818
install(FILES stlink-gui.desktop
19-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
19+
DESTINATION ${CMAKE_INSTALL_SHAREDIR}/applications)
2020

2121
# Install icons
2222
install(FILES icons/stlink-gui.svg
23-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps)
23+
DESTINATION ${CMAKE_INSTALL_SHAREDIR}/icons/hicolor/scalable/apps)
2424

2525
set(GUI_SOURCES gui.c gui.h)
2626

@@ -33,10 +33,10 @@ if (NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
3333

3434
## stlink-gui
3535
add_executable(stlink-gui ${GUI_SOURCES})
36-
install(FILES stlink-gui.ui DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME})
36+
install(FILES stlink-gui.ui DESTINATION ${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME})
3737
set_target_properties(stlink-gui PROPERTIES
38-
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_FULL_DATAROOTDIR}/${PROJECT_NAME}")
38+
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME}")
3939
target_link_libraries(stlink-gui ${STLINK_LIB_SHARED} ${SSP_LIB} ${GTK3_LDFLAGS})
40-
install(TARGETS stlink-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
40+
install(TARGETS stlink-gui DESTINATION ${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME})
4141
endif ()
4242
endif ()

src/stlink-gui/gui.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,7 @@ int main(int argc, char **argv) {
883883

884884
gtk_init(&argc, &argv);
885885

886-
init_chipids (ETC_STLINK_DIR);
886+
init_chipids (STLINK_CHIPS_DIR);
887887

888888
gui = g_object_new(STLINK_TYPE_GUI, NULL);
889889
stlink_gui_build_ui(gui);

tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
set(TESTEXEC usb sg)
66

77
set(TEST_DEPENDENCY ${STLINK_LIB_SHARED})
8-
if (WIN32 OR APPLE)
8+
if (WIN32)
99
set(TEST_DEPENDENCY ${STLINK_LIB_STATIC})
1010
endif()
1111

0 commit comments

Comments
 (0)