Skip to content

Commit

Permalink
Fixes for project compilation
Browse files Browse the repository at this point in the history
- Cleanup for CMakeLists.txt
- [doc] Added list of cmake path variables
- Fixed stlink-gui install path (Closes #1270) (Closes #1271)
- Replaced path variable for chips directory
  • Loading branch information
Nightwalker-87 committed Oct 23, 2022
1 parent ff81148 commit f93adb9
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 48 deletions.
105 changes: 70 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,69 @@ set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)

###
#
# Default cmake directories:
#
# | Target Type | GNUInstallDirs Variable | Built-In Default |
# | --- | --- | --- |
# | RUNTIME | ${CMAKE_INSTALL_BINDIR} | bin |
# | LIBRARY | ${CMAKE_INSTALL_LIBDIR} | lib |
# | ARCHIVE | ${CMAKE_INSTALL_LIBDIR} | lib |
# | PRIVATE_HEADER | ${CMAKE_INSTALL_INCLUDEDIR} | include |
# | PUBLIC_HEADER | ${CMAKE_INSTALL_INCLUDEDIR} | include |
# | FILE_SET (type HEADERS) | ${CMAKE_INSTALL_INCLUDEDIR} | include |
#
# | TYPE Argument | GNUInstallDirs Variable | Built-In Default |
# | --- | --- | --- |
# | BIN | ${CMAKE_INSTALL_BINDIR} | bin |
# | SBIN | ${CMAKE_INSTALL_SBINDIR} | sbin |
# | LIB | ${CMAKE_INSTALL_LIBDIR} | lib |
# | INCLUDE | ${CMAKE_INSTALL_INCLUDEDIR} | include |
# | SYSCONF | ${CMAKE_INSTALL_SYSCONFDIR} | etc |
# | SHAREDSTATE | ${CMAKE_INSTALL_SHARESTATEDIR} | com |
# | LOCALSTATE | ${CMAKE_INSTALL_LOCALSTATEDIR} | var |
# | RUNSTATE | ${CMAKE_INSTALL_RUNSTATEDIR} | <LOCALSTATE dir>/run |
# | DATA | ${CMAKE_INSTALL_DATADIR} | <DATAROOT dir> |
# | INFO | ${CMAKE_INSTALL_INFODIR} | <DATAROOT dir>/info |
# | LOCALE | ${CMAKE_INSTALL_LOCALEDIR} | <DATAROOT dir>/locale |
# | MAN | ${CMAKE_INSTALL_MANDIR} | <DATAROOT dir>/man |
# | DOC | ${CMAKE_INSTALL_DOCDIR} | <DATAROOT dir>/doc |
#
# ${CMAKE_BINARY_DIR}
# This is the full path to the top level of the current CMake build tree.
# For an in-source build, this would be the same as CMAKE_SOURCE_DIR.
#
# ${CMAKE_SOURCE_DIR}
# This is the full path to the top level of the current CMake source tree.
# For an in-source build, this would be the same as CMAKE_BINARY_DIR.
#
# ${CMAKE_CURRENT_BINARY_DIR}
# The path to the binary directory currently being processed.
# This is the full path to the build directory that is currently being processed by cmake.
# Each directory added by add_subdirectory() will create a binary directory in the build tree,
# and as it is being processed this variable will be set.
# For in-source builds this is the current source directory being processed.
#
# ${CMAKE_CURRENT_SOURCE_DIR}
# The path to the source directory currently being processed.
# This is the full path to the source directory that is currently being processed by cmake.
#
###


###
# General project settings
# General Project Settings
###

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

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

## Determine project version
include(${CMAKE_MODULE_PATH}/get_version.cmake)
# Define install directory /usr/share
set(CMAKE_INSTALL_SHAREDIR /usr/share/)

## Set C build flags
if (NOT MSVC)
Expand Down Expand Up @@ -178,8 +225,6 @@ endif ()
# Libraries
###

set(STLINK_LIBRARY_PATH ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Main library install directory")

# Set the environment variable LD_LIBRARY_PATH to point to /usr/local/lib (per default).
execute_process(COMMAND bash -c "export LD_LIBRARY_PATH=${CMAKE_INSTALL_LIBDIR}")

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

# Link shared library
if (APPLE) # ... with Apple macOS libraries
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
find_library(Security Security)
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB} ${ObjC} ${CoreFoundation} ${IOKit} ${Security})
elseif (WIN32) # ... with Windows libraries
if (WIN32) # ... with Windows libraries
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32)
else ()
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif ()

install(TARGETS ${STLINK_LIB_SHARED}
ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}
LIBRARY DESTINATION ${STLINK_LIBRARY_PATH}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

Expand Down Expand Up @@ -248,19 +287,13 @@ set_target_properties(${STLINK_LIB_STATIC} PROPERTIES
)

# Link static library
if (APPLE) # ... with Apple macOS libraries
find_library(ObjC objc)
find_library(CoreFoundation CoreFoundation)
find_library(IOKit IOKit)
find_library(Security Security)
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB} ${ObjC} ${CoreFoundation} ${IOKit} ${Security})
elseif (WIN32) # ... with Windows libraries
if (WIN32) # ... with Windows libraries
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB} wsock32 ws2_32)
else ()
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif ()

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


###
Expand All @@ -284,7 +317,7 @@ add_executable(st-info ${ST-INFO_SOURCES})
add_executable(st-util ${ST-UTIL_SOURCES})
add_executable(st-trace ${ST-TRACE_SOURCES})

if (WIN32 OR APPLE)
if (WIN32)
target_link_libraries(st-flash ${STLINK_LIB_STATIC} ${SSP_LIB})
target_link_libraries(st-info ${STLINK_LIB_STATIC} ${SSP_LIB})
target_link_libraries(st-util ${STLINK_LIB_STATIC} ${SSP_LIB})
Expand All @@ -301,10 +334,6 @@ install(TARGETS st-info DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS st-util DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS st-trace DESTINATION ${CMAKE_INSTALL_BINDIR})

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


###
# Device configuration (Linux only)
Expand All @@ -326,13 +355,19 @@ endif ()
# Additional build tasks
###

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

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

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

###
# Uninstall target
Expand Down
2 changes: 1 addition & 1 deletion cmake/packaging/cpack_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (WIN32 AND (NOT EXISTS "/etc/debian_version")) # Wi
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win32")
set(CPACK_INSTALL_PREFIX "")

elseif (WIN32) # Windows cross-build on Debian/Ubuntu
elseif (WIN32) # Windows cross-build on Debian/Ubuntu
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${TOOLCHAIN_PREFIX}")
set(CPACK_INSTALL_PREFIX "")
Expand Down
2 changes: 1 addition & 1 deletion doc/man/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ foreach (manpage ${MANPAGES})
endif ()

if (f AND NOT WIN32)
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/man/man1)
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_DATADIR}/man/man1)
unset(f)
endif ()
endforeach ()
2 changes: 1 addition & 1 deletion src/st-flash/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int main(int ac, char** av) {
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/st-info/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static int print_data(int ac, char **av) {
return(0);
}

init_chipids(ETC_STLINK_DIR);
init_chipids(STLINK_CHIPS_DIR);

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

Expand Down
2 changes: 1 addition & 1 deletion src/st-trace/trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ int main(int argc, char **argv) {
usage();
return APP_RESULT_INVALID_PARAMS;
}
init_chipids (ETC_STLINK_DIR);
init_chipids (STLINK_CHIPS_DIR);

DLOG("show_help = %s\n", settings.show_help ? "true" : "false");
DLOG("show_version = %s\n", settings.show_version ? "true" : "false");
Expand Down
2 changes: 1 addition & 1 deletion src/st-util/gdb-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ int main(int argc, char** argv) {

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

init_chipids (ETC_STLINK_DIR);
init_chipids (STLINK_CHIPS_DIR);

sl = stlink_open_usb(state.logging_level, state.connect_mode, state.serialnumber, state.freq);
if (sl == NULL) { return(1); }
Expand Down
10 changes: 5 additions & 5 deletions src/stlink-gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ if (NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)

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

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

set(GUI_SOURCES gui.c gui.h)

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

## stlink-gui
add_executable(stlink-gui ${GUI_SOURCES})
install(FILES stlink-gui.ui DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME})
install(FILES stlink-gui.ui DESTINATION ${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME})
set_target_properties(stlink-gui PROPERTIES
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_FULL_DATAROOTDIR}/${PROJECT_NAME}")
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME}")
target_link_libraries(stlink-gui ${STLINK_LIB_SHARED} ${SSP_LIB} ${GTK3_LDFLAGS})
install(TARGETS stlink-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS stlink-gui DESTINATION ${CMAKE_INSTALL_SHAREDIR}/${PROJECT_NAME})
endif ()
endif ()
2 changes: 1 addition & 1 deletion src/stlink-gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ int main(int argc, char **argv) {

gtk_init(&argc, &argv);

init_chipids (ETC_STLINK_DIR);
init_chipids (STLINK_CHIPS_DIR);

gui = g_object_new(STLINK_TYPE_GUI, NULL);
stlink_gui_build_ui(gui);
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
set(TESTEXEC usb sg)

set(TEST_DEPENDENCY ${STLINK_LIB_SHARED})
if (WIN32 OR APPLE)
if (WIN32)
set(TEST_DEPENDENCY ${STLINK_LIB_STATIC})
endif()

Expand Down

0 comments on commit f93adb9

Please sign in to comment.