From 7ef06378aa16e210dc480ef5ae2bc12973becc0c Mon Sep 17 00:00:00 2001 From: nightwalker-87 <15526941+Nightwalker-87@users.noreply.github.com> Date: Tue, 19 May 2020 11:28:35 +0200 Subject: [PATCH] Refactoring for build settings 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 --- .travis.sh | 12 +-- CMakeLists.txt | 86 +++++++------------ {etc => config}/modprobe.d/stlink_v1.conf | 0 .../udev/rules.d/49-stlinkv1.rules | 0 .../udev/rules.d/49-stlinkv2-1.rules | 0 .../udev/rules.d/49-stlinkv2.rules | 0 .../udev/rules.d/49-stlinkv3.rules | 0 doc/man/CMakeLists.txt | 2 +- src/stlink-gui/CMakeLists.txt | 29 +++---- tests/CMakeLists.txt | 6 +- 10 files changed, 55 insertions(+), 80 deletions(-) rename {etc => config}/modprobe.d/stlink_v1.conf (100%) rename {etc => config}/udev/rules.d/49-stlinkv1.rules (100%) rename {etc => config}/udev/rules.d/49-stlinkv2-1.rules (100%) rename {etc => config}/udev/rules.d/49-stlinkv2.rules (100%) rename {etc => config}/udev/rules.d/49-stlinkv3.rules (100%) diff --git a/.travis.sh b/.travis.sh index 2c98a6e..cc0958b 100755 --- a/.travis.sh +++ b/.travis.sh @@ -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 @@ -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..." @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b3210d..dcdaf2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 ### @@ -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}") @@ -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 @@ -145,29 +136,30 @@ if (${CMAKE_BUILD_TYPE} MATCHES "Debug") 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}"") + + ### # 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}") @@ -176,6 +168,7 @@ set_target_properties( ${STLINK_LIB_SHARED} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${STLINK_SHARED_VERSION} + OUTPUT_NAME ${PROJECT_NAME} ) # Link shared library @@ -197,19 +190,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}") @@ -233,9 +219,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}) ### @@ -263,30 +247,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 () + ## Install modprobe.d conf files / rules to /usr/local/etc/stlink (default) + set(STLINK_MODPROBED_DIR "${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME}/modprobe.d" CACHE PATH "modprobe.d directory") + install(FILES ${CMAKE_SOURCE_DIR}/config/modprobe.d/stlink_v1.conf DESTINATION ${STLINK_MODPROBED_DIR}) - ## 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 udev rules files / rules to /usr/local/etc/stlink (default) + set(STLINK_UDEV_RULES_DIR "${CMAKE_INSTALL_SYSCONFDIR}/${PROJECT_NAME}/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 () diff --git a/etc/modprobe.d/stlink_v1.conf b/config/modprobe.d/stlink_v1.conf similarity index 100% rename from etc/modprobe.d/stlink_v1.conf rename to config/modprobe.d/stlink_v1.conf diff --git a/etc/udev/rules.d/49-stlinkv1.rules b/config/udev/rules.d/49-stlinkv1.rules similarity index 100% rename from etc/udev/rules.d/49-stlinkv1.rules rename to config/udev/rules.d/49-stlinkv1.rules diff --git a/etc/udev/rules.d/49-stlinkv2-1.rules b/config/udev/rules.d/49-stlinkv2-1.rules similarity index 100% rename from etc/udev/rules.d/49-stlinkv2-1.rules rename to config/udev/rules.d/49-stlinkv2-1.rules diff --git a/etc/udev/rules.d/49-stlinkv2.rules b/config/udev/rules.d/49-stlinkv2.rules similarity index 100% rename from etc/udev/rules.d/49-stlinkv2.rules rename to config/udev/rules.d/49-stlinkv2.rules diff --git a/etc/udev/rules.d/49-stlinkv3.rules b/config/udev/rules.d/49-stlinkv3.rules similarity index 100% rename from etc/udev/rules.d/49-stlinkv3.rules rename to config/udev/rules.d/49-stlinkv3.rules diff --git a/doc/man/CMakeLists.txt b/doc/man/CMakeLists.txt index 3646654..23da9e1 100644 --- a/doc/man/CMakeLists.txt +++ b/doc/man/CMakeLists.txt @@ -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 () diff --git a/src/stlink-gui/CMakeLists.txt b/src/stlink-gui/CMakeLists.txt index b5ef99d..c38fdad 100644 --- a/src/stlink-gui/CMakeLists.txt +++ b/src/stlink-gui/CMakeLists.txt @@ -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 () diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 40d2203..6e60fdd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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)