diff --git a/CMakeLists.txt b/CMakeLists.txt index 4aac51c..9a3e063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,12 +66,16 @@ include_directories(include) include_directories(${PROJECT_BINARY_DIR}/include) include_directories(src/mingw) +### # Shared library -add_library(${PROJECT_NAME} SHARED +### +set(STLINK_LIB_SHARED ${PROJECT_NAME}-shared) + +add_library(${STLINK_LIB_SHARED} SHARED ${STLINK_HEADERS} # header files for ide projects generated by cmake ${STLINK_SOURCE} ) -target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY}) +target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY}) if (WIN32 OR MSYS OR MINGW) set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}) @@ -79,25 +83,27 @@ else() set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) endif() -set_target_properties(${PROJECT_NAME} +set_target_properties(${STLINK_LIB_SHARED} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${STLINK_SHARED_VERSION} ) +# Link shared library with apple OS libraries if (APPLE) find_library(ObjC objc) find_library(CoreFoundation CoreFoundation) find_library(IOKit IOKit) - target_link_libraries(${PROJECT_NAME} ${CoreFoundation} ${IOKit} ${ObjC}) + target_link_libraries(${STLINK_LIB_SHARED} ${CoreFoundation} ${IOKit} ${ObjC}) endif () -if(WIN32 OR MSYS OR MINGW) - target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY} wsock32 ws2_32) +# Link +if (WIN32 OR MSYS OR MINGW) + target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} wsock32 ws2_32) else() - target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARY}) + target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY}) endif() -install(TARGETS ${PROJECT_NAME} +install(TARGETS ${STLINK_LIB_SHARED} DESTINATION lib/${CMAKE_LIBRARY_PATH} ) @@ -110,7 +116,17 @@ add_library(${STLINK_LIB_STATIC} STATIC ${STLINK_HEADERS} # header files for ide projects generated by cmake ${STLINK_SOURCE} ) + target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY}) + +# Link shared library with apple OS libraries +if (APPLE) + find_library(ObjC objc) + find_library(CoreFoundation CoreFoundation) + find_library(IOKit IOKit) + target_link_libraries(${STLINK_LIB_STATIC} ${CoreFoundation} ${IOKit} ${ObjC}) +endif () + set_target_properties(${STLINK_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) install(TARGETS ${STLINK_LIB_STATIC} @@ -121,10 +137,18 @@ install(TARGETS ${STLINK_LIB_STATIC} # Tools ### add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c) -target_link_libraries(st-flash ${PROJECT_NAME}) +if (WIN32 OR APPLE) + target_link_libraries(st-flash ${STLINK_LIB_STATIC}) +else() + target_link_libraries(st-flash ${STLINK_LIB_SHARED}) +endif() add_executable(st-info src/tools/info.c) -target_link_libraries(st-info ${PROJECT_NAME}) +if (WIN32 OR APPLE) + target_link_libraries(st-info ${STLINK_LIB_STATIC}) +else() + target_link_libraries(st-info ${STLINK_LIB_SHARED}) +endif() install(TARGETS st-flash st-info RUNTIME DESTINATION bin diff --git a/cmake/CPackConfig.cmake b/cmake/CPackConfig.cmake index fb6bb1a..3dc2b6a 100644 --- a/cmake/CPackConfig.cmake +++ b/cmake/CPackConfig.cmake @@ -1,13 +1,14 @@ set (CPACK_PACKAGE_NAME ${PROJECT_NAME}) set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) set (CPACK_SET_DESTDIR "ON") -set (CPACK_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/cpack/staging") if (APPLE) set(CPACK_GENERATOR "ZIP") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/dist/osx") + set (CPACK_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/cpack/staging") set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/dist/osx") elseif (WIN32) set(CPACK_GENERATOR "ZIP") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/dist/windows") + set (CPACK_INSTALL_PREFIX "") set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/dist/windows") -endif() +endif() \ No newline at end of file diff --git a/doc/build_mingw.md b/doc/build_mingw.md deleted file mode 100644 index 6327b57..0000000 --- a/doc/build_mingw.md +++ /dev/null @@ -1,23 +0,0 @@ -Building with MinGW under Windows -================================= - -## Prequistes - -* 7Zip -* CMake 2.8 or higher -* MinGW64 GCC toolchain (5.3.0) - -## Installation - -1. Install 7Zip from http://www.7-zip.org -2. Install CMake from https://cmake.org/download -3. Install MinGW64 from https://sourceforge.net/projects/mingw-w64 (mingw-w64-install.exe) -4. Git clone or download stlink sourcefiles zip -5. Create build folder in source - -# Building - -Check and execute `\scripts\mingw64-build.bat` - -NOTE: when installing different toolchains make sure you edit the path in the `mingw64-build.bat` - the build script uses currently `C:\Program Files\mingw-w64\x86_64-5.3.0-win32-sjlj-rt_v4-rev0\mingw64\bin` diff --git a/doc/compiling.md b/doc/compiling.md index 5bac614..30f23b6 100644 --- a/doc/compiling.md +++ b/doc/compiling.md @@ -117,3 +117,25 @@ during installation you can use the following cmake options: $ cmake -DSTLINK_UDEV_RULES_DIR="/usr/lib/udev/rules.d" \ -DSTLINK_MODPROBED_DIR="/usr/lib/modprobe.d" .. ``` + +## Windows (MinGW64) + +### Prequistes + +* 7Zip +* CMake 2.8 or higher +* MinGW64 GCC toolchain (5.3.0) + +### Installation + +1. Install 7Zip from +2. Install CMake from +3. Install MinGW64 from (mingw-w64-install.exe) +4. Git clone or download stlink sourcefiles zip + +### Building + +Check and execute (in the script folder) `\scripts\mingw64-build.bat` + +NOTE: when installing different toolchains make sure you edit the path in the `mingw64-build.bat` + the build script uses currently `C:\Program Files\mingw-w64\x86_64-5.3.0-win32-sjlj-rt_v4-rev0\mingw64\bin` diff --git a/doc/man/CMakeLists.txt b/doc/man/CMakeLists.txt index 83bb008..949cd2f 100644 --- a/doc/man/CMakeLists.txt +++ b/doc/man/CMakeLists.txt @@ -30,7 +30,7 @@ foreach(manpage ${MANPAGES}) message(AUTHOR_WARNING "Manpage ${manpage} not generated") endif() - if (f) + if (f AND NOT WIN32) install(FILES ${f} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1) unset(f) endif() diff --git a/scripts/mingw64-build.bat b/scripts/mingw64-build.bat index 52c6fff..3f92ae8 100644 --- a/scripts/mingw64-build.bat +++ b/scripts/mingw64-build.bat @@ -1,4 +1,6 @@ @echo off set PATH=C:\Program Files (x86)\CMake\bin;C:\Program Files\CMake\bin;C:\Program Files\mingw-w64\x86_64-5.3.0-win32-sjlj-rt_v4-rev0\mingw64\bin;%PATH% cmake -G "MinGW Makefiles" .. -mingw32-make \ No newline at end of file +mingw32-make +mingw32-make install DESTDIR=_install +mingw32-make package diff --git a/src/gdbserver/CMakeLists.txt b/src/gdbserver/CMakeLists.txt index c6114f6..a41890c 100644 --- a/src/gdbserver/CMakeLists.txt +++ b/src/gdbserver/CMakeLists.txt @@ -4,7 +4,12 @@ add_executable(st-util gdb-remote.c gdb-server.h semihosting.c semihosting.h) -target_link_libraries(st-util ${PROJECT_NAME}) +if (WIN32 OR APPLE) + target_link_libraries(st-util ${STLINK_LIB_STATIC}) +else() + target_link_libraries(st-util ${STLINK_LIB_SHARED}) +endif() + install(TARGETS st-util RUNTIME DESTINATION bin ) diff --git a/src/gdbserver/Makefile b/src/gdbserver/Makefile deleted file mode 100644 index bd5c73d..0000000 --- a/src/gdbserver/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -PRG := st-util -OBJS = gdb-remote.o gdb-server.o - -CFLAGS+=-g -Wall -Werror -std=gnu99 -I../src -LDFLAGS=-L.. -lstlink - -# libusb location -LDFLAGS+=`pkg-config --libs libusb-1.0` -CFLAGS+=`pkg-config --cflags libusb-1.0` - -all: $(PRG) - -$(PRG): $(OBJS) ../libstlink.a - $(CC) -o $@ $^ $(LDFLAGS) - -clean: - rm -rf $(OBJS) - rm -rf $(PRG) - -.PHONY: clean all diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index fc51433..8df28ce 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,11 +5,11 @@ set(TESTS foreach(test ${TESTS}) add_executable(${test} ${test}.c) - add_dependencies(${test} ${PROJECT_NAME}) - target_link_libraries(${test} ${PROJECT_NAME}) + add_dependencies(${test} ${STLINK_LIB_STATIC}) + target_link_libraries(${test} ${STLINK_LIB_STATIC}) add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test}) endforeach() add_executable(flash flash.c "${CMAKE_SOURCE_DIR}/src/tools/flash_opts.c") -target_link_libraries(flash ${PROJECT_NAME}) +target_link_libraries(flash ${STLINK_LIB_STATIC}) add_test(flash ${CMAKE_CURRENT_BINARY_DIR}/flash)