Skip to content

Commit

Permalink
Refactoring for build settings
Browse files Browse the repository at this point in the history
Tidy up install paths & directories:
-> modprobe.d & udev rules
  (both are now ON per default on linux)
-> stlink-gui supplements
-> man pages
- Fixed paths according to GNUInstallDirs
- cmake: Restructured library config
- Test files & gui now use shared library
  • Loading branch information
Nightwalker-87 committed May 19, 2020
1 parent 1b3200d commit a937f9e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 81 deletions.
12 changes: 6 additions & 6 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ elif [ "$TRAVIS_OS_NAME" == "linux" ]; then
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$PWD/install $DIR
make && cd -

echo "--> Building Release..."
echo "--> Building Release with package..."
mkdir -p build/Release && cd build/Release
echo "-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install $DIR
make && make package && cd -
make package && cd -

elif [ "$TRAVIS_OS_NAME" == "osx" ]; then
brew install libusb
Expand All @@ -50,11 +50,11 @@ elif [ "$TRAVIS_OS_NAME" == "osx" ]; then
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$PWD/install $DIR
make && cd -

echo "--> Building Release..."
echo "--> Building Release with package..."
mkdir -p build/Release && cd build/Release
echo "-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install $DIR
make && make package && cd -
make package && cd -

else # local test-build
echo "--> Building Debug..."
Expand All @@ -63,9 +63,9 @@ else # local test-build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$PWD/install ../../
make && cd -

echo "--> Building Release..."
echo "--> Building Release with package..."
mkdir -p build/Release && cd build/Release
echo "-DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$PWD/install ../../
make && make package && cd -
make package && cd -
fi
85 changes: 30 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)


###
# General project settings
###
Expand All @@ -32,16 +31,7 @@ else ()
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG")
endif ()

## Set installation directories for libraries
if (IS_DIRECTORY ${LIB_INSTALL_DIR})
set(LIB_INSTALL_DIR ${LIB_INSTALL_DIR} CACHE PATH "Main library directory")
set(STLINK_LIBRARY_PATH "${LIB_INSTALL_DIR}")
else ()
set(LIB_INSTALL_DIR "lib" CACHE PATH "Main library directory")
set(STLINK_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}")
endif ()

## Set installation directories for header files
## Set installation directories for header files ### TODO: Clean this up...
if (IS_DIRECTORY ${INCLUDE_INSTALL_DIR})
set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR} CACHE PATH "Main include directory")
set(STLINK_INCLUDE_PATH "${INCLUDE_INSTALL_DIR}")
Expand Down Expand Up @@ -95,13 +85,14 @@ endif ()
include_directories(${LIBUSB_INCLUDE_DIR})

# ====
include_directories(include) ### TODO: Clean this up...
include_directories(${PROJECT_SOURCE_DIR}/include) ### TODO: Clean this up...
include_directories(${PROJECT_BINARY_DIR}/include/stlink)
include_directories(include/stlink)
include_directories(include/stlink/tools)
include_directories(${PROJECT_SOURCE_DIR}/include/stlink)
include_directories(${PROJECT_SOURCE_DIR}/include/stlink/tools)
# ====

include_directories(src)
include_directories(src/tools) ### TODO: Clean this up...

set(STLINK_HEADERS
include/stlink.h
Expand Down Expand Up @@ -145,29 +136,27 @@ if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
endif ()


###
# Libraries
###

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


###
# Shared library
###

# Set library name
if (NOT WIN32)
set(STLINK_LIB_SHARED ${PROJECT_NAME})
else (WIN32)
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}
)
add_library(${STLINK_LIB_SHARED} SHARED ${STLINK_HEADERS} ${STLINK_SOURCE})

set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})

message(STATUS "STLINK_LIB_SHARED: ${STLINK_LIB_SHARED}")
message(STATUS "PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}")
message(STATUS "VERSION: ${STLINK_SHARED_VERSION}")
Expand All @@ -176,6 +165,7 @@ set_target_properties(
${STLINK_LIB_SHARED} PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${STLINK_SHARED_VERSION}
OUTPUT_NAME ${PROJECT_NAME}
)

# Link shared library
Expand All @@ -197,19 +187,12 @@ install(TARGETS ${STLINK_LIB_SHARED} DESTINATION ${STLINK_LIBRARY_PATH})
# Static library
###

# Install static library per default
set(STLINK_STATIC_LIB ON CACHE BOOL "Install static lib")

# Set library name
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}
)
add_library(${STLINK_LIB_STATIC} STATIC ${STLINK_HEADERS} ${STLINK_SOURCE})

set(STLINK_STATIC_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})

message(STATUS "STLINK_LIB_STATIC: ${STLINK_LIB_STATIC}")
message(STATUS "PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}")
message(STATUS "VERSION: ${STLINK_STATIC_VERSION}")
Expand All @@ -233,9 +216,7 @@ else ()
target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB})
endif ()

if (STLINK_STATIC_LIB)
install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH})
endif ()
install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH})


###
Expand Down Expand Up @@ -263,30 +244,24 @@ else ()
target_link_libraries(st-util ${STLINK_LIB_SHARED} ${SSP_LIB})
endif ()

install(TARGETS st-flash DESTINATION bin)
install(TARGETS st-info DESTINATION bin)
install(TARGETS st-util DESTINATION bin)
install(TARGETS st-flash DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS st-info DESTINATION ${CMAKE_INSTALL_BINDIR})
install(TARGETS st-util DESTINATION ${CMAKE_INSTALL_BINDIR})


###
# udev and modprobe.d configuration
# Device configuration (Linux only)
###

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
## modprobe.d rules
set(STLINK_MODPROBED_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/modprobe.d" CACHE PATH "modprobe.d directory")
option(STLINK_INSTALL_MODPROBE_CONF "Install modprobe conf files" ON)
if (STLINK_INSTALL_MODPROBE_CONF)
install(FILES ${CMAKE_SOURCE_DIR}/etc/modprobe.d/stlink_v1.conf DESTINATION ${STLINK_MODPROBED_DIR}/)
endif ()

## udev rules
set(STLINK_UDEV_RULES_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/udev/rules.d" CACHE PATH "udev rules directory")
option(STLINK_INSTALL_UDEV_RULES "Install udev rules files" ON)
if (STLINK_INSTALL_UDEV_RULES)
file(GLOB RULES_FILES ${CMAKE_SOURCE_DIR}/etc/udev/rules.d/*.rules)
install(FILES ${RULES_FILES} DESTINATION ${STLINK_UDEV_RULES_DIR}/)
endif ()
## Install modprobe.d conf files / rules to ${CMAKE_INSTALL_PREFIX}/etc/stlink (default)
set(STLINK_MODPROBED_DIR "${CMAKE_INSTALL_SYSCONFDIR}/stlink/modprobe.d" CACHE PATH "modprobe.d directory")
install(FILES ${CMAKE_SOURCE_DIR}/config/modprobe.d/stlink_v1.conf DESTINATION ${STLINK_MODPROBED_DIR})

## Install udev rules files / rules to ${CMAKE_INSTALL_PREFIX}/etc/stlink (default)
set(STLINK_UDEV_RULES_DIR "${CMAKE_INSTALL_SYSCONFDIR}/stlink/udev/rules.d" CACHE PATH "udev rules directory")
file(GLOB RULES_FILES ${CMAKE_SOURCE_DIR}/config/udev/rules.d/*.rules)
install(FILES ${RULES_FILES} DESTINATION ${STLINK_UDEV_RULES_DIR})
endif ()


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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_MANDIR}/man1)
install(FILES ${f} DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/man/man1)
unset(f)
endif ()
endforeach ()
29 changes: 13 additions & 16 deletions src/stlink-gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,23 @@ set(GUI_SOURCES gui.c gui.h)

## stlink-gui-local
add_executable(stlink-gui-local ${GUI_SOURCES})
set_target_properties(
stlink-gui-local PROPERTIES
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
# Note: ${CMAKE_CURRENT_SOURCE_DIR} is src/stlink-gui
)
target_link_libraries(stlink-gui-local ${STLINK_LIB_STATIC} ${GTK3_LDFLAGS} ${SSP_LIB})
set_target_properties(stlink-gui-local PROPERTIES
# Note: ${CMAKE_CURRENT_SOURCE_DIR} is src/stlink-gui
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(stlink-gui-local ${STLINK_LIB_SHARED} ${SSP_LIB} ${GTK3_LDFLAGS})

## stlink-gui
add_executable(stlink-gui ${GUI_SOURCES})
set_target_properties(
stlink-gui PROPERTIES
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_PREFIX}/bin"
# Note: ${CMAKE_INSTALL_PREFIX} defaults to /usr/local
)
target_link_libraries(stlink-gui ${STLINK_LIB_STATIC} ${GTK3_LDFLAGS} ${SSP_LIB})
set_target_properties(stlink-gui PROPERTIES
COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_BINDIR}")
target_link_libraries(stlink-gui ${STLINK_LIB_SHARED} ${SSP_LIB} ${GTK3_LDFLAGS})

install(TARGETS stlink-gui DESTINATION bin)
install(FILES stlink-gui.ui DESTINATION bin)
install(TARGETS stlink-gui DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES stlink-gui.ui DESTINATION ${CMAKE_INSTALL_BINDIR})

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(FILES stlink-gui.desktop DESTINATION share/applications) # Install desktop application entry
install(FILES icons/stlink-gui.svg DESTINATION share/icons/hicolor/scalable/apps) # Install icon
# Install desktop application entry
install(FILES stlink-gui.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/applications)
# Install icons
install(FILES icons/stlink-gui.svg DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/icons/hicolor/scalable/apps)
endif ()
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ set(TESTEXEC usb sg)

foreach (test ${TESTEXEC})
add_executable(test-${test} ${test}.c)
add_dependencies(test-${test} ${STLINK_LIB_STATIC})
target_link_libraries(test-${test} ${STLINK_LIB_STATIC} ${SSP_LIB})
add_dependencies(test-${test} ${STLINK_LIB_SHARED})
target_link_libraries(test-${test} ${STLINK_LIB_SHARED} ${SSP_LIB})
add_test(test-${test} ${CMAKE_BINARY_DIR}/bin/test-${test})
endforeach ()

add_executable(test-flash flash.c "${CMAKE_SOURCE_DIR}/src/tools/flash_opts.c")
target_link_libraries(test-flash ${STLINK_LIB_STATIC} ${SSP_LIB})
target_link_libraries(test-flash ${STLINK_LIB_SHARED} ${SSP_LIB})
add_test(test-flash ${CMAKE_BINARY_DIR}/bin/test-flash)

0 comments on commit a937f9e

Please sign in to comment.