Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake Enhancements #962

Merged
merged 4 commits into from
Jun 8, 2022
Merged

Conversation

mariusgreuel
Copy link
Contributor

This serves as a bucket for various CMake issues and wishes that came up recently.

I will merge myself.

@mcuee
Copy link
Collaborator

mcuee commented May 14, 2022

Tested with VS2019 for the option to link to shared library. Somehow the binary will use static link to the dependancies. I think this is the side effects of using external libraries. So it is not a real issue.

1> CMake generation started for configuration: 'x64-Debug'.
1> Found and using vcpkg toolchain file (C:/src/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake).
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\work\avr\avrdude_test\avrdude-fork\out\install\x64-Debug" -DUSE_EXTERNAL:BOOL="True" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" -DCMAKE_TOOLCHAIN_FILE="C:/src/vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake" "C:\work\avr\avrdude_test\avrdude-fork" 2>&1"
1> Working directory: C:\work\avr\avrdude_test\avrdude-fork\out\build\x64-Debug
1> [CMake] -- Fetching external libraries, please wait...
1> [CMake] -- Using external library 'libelf'
1> [CMake] -- Using external library 'libusb'
1> [CMake] -- Using external library 'libhidapi'
1> [CMake] -- Using external library 'libftdi'
1> [CMake] -- Configuration summary:
1> [CMake] -- ----------------------
1> [CMake] -- DO HAVE    libelf
1> [CMake] -- DO HAVE    libusb
1> [CMake] -- DON'T HAVE libusb_1_0
1> [CMake] -- DO HAVE    libhidapi
1> [CMake] -- DO HAVE    libftdi (but prefer to use libftdi1)
1> [CMake] -- DO HAVE    libftdi1
1> [CMake] -- DISABLED   doc
1> [CMake] -- DISABLED   parport
1> [CMake] -- DISABLED   linuxgpio
1> [CMake] -- DISABLED   linuxspi
1> [CMake] -- ----------------------
1> [CMake] -- Configuring done
1> [CMake] -- Generating done
1> [CMake] -- Build files have been written to: C:/work/avr/avrdude_test/avrdude-fork/out/build/x64-Debug
1> Extracted CMake variables.
1> Extracted source files and headers.
1> Extracted code model.
1> Extracted toolchain configurations.
1> Extracted includes paths.
1> CMake generation finished.

>------ Build All started: Project: avrdude-fork, Configuration: x64-Debug ------
  [1/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\32.getshdr.c.obj
  [2/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\32.getphdr.c.obj
  [3/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\begin.c.obj
  [4/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\assert.c.obj
  [5/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\32.getehdr.c.obj
  [6/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\32.newphdr.c.obj
  [7/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\32.newehdr.c.obj
  [8/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\cook.c.obj
  [9/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\64.xlatetof.c.obj
  [10/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\32.xlatetof.c.obj
  [11/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\fill.c.obj
  [12/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\cntl.c.obj
  [13/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\end.c.obj
  [14/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\flag.c.obj
  [15/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\gelfehdr.c.obj
  [16/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\errmsg.c.obj
  [17/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\errno.c.obj
  [18/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\data.c.obj
  [19/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\gelftrans.c.obj
  [20/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\checksum.c.obj
  [21/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\gelfphdr.c.obj
  [22/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\getaroff.c.obj
  [23/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\getdata.c.obj
  [24/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\getarhdr.c.obj
  [25/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\gelfshdr.c.obj
  [26/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\getbase.c.obj
  [27/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\getident.c.obj
  [28/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\hash.c.obj
  [29/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\getarsym.c.obj
  [30/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\getscn.c.obj
  [31/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\memset.c.obj
  [32/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\kind.c.obj
  [33/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\input.c.obj
  [34/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\nlist.c.obj
  [35/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\newscn.c.obj
  [36/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\newdata.c.obj
  [37/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\ndxscn.c.obj
  [38/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\next.c.obj
  [39/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\nextscn.c.obj
  [40/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\rand.c.obj
  [41/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\swap64.c.obj
  [42/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\strptr.c.obj
  [43/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\opt.delscn.c.obj
  [44/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\update.c.obj
  [45/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\rawfile.c.obj
  [46/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\rawdata.c.obj
  [47/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\verdef_32_tof.c.obj
  [48/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\verdef_32_tom.c.obj
  [49/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\verdef_64_tof.c.obj
  [50/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\version.c.obj
  [51/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\x.remscn.c.obj
  [52/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\verdef_64_tom.c.obj
  [53/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\x.movscn.c.obj
  [54/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\x.elfext.c.obj
  [55/131] Building C object _deps\libelf-build\CMakeFiles\libelf.dir\src\32.fsize.c.obj
  [56/131] Building C object _deps\libusb-build\CMakeFiles\libusb.dir\src\usb.c.obj
  [57/131] Building C object _deps\libusb-build\CMakeFiles\libusb.dir\src\descriptors.c.obj
  [58/131] Linking C static library _deps\libelf-build\libelf.lib
  [59/131] Building CXX object _deps\libftdi-build\CMakeFiles\libftdi.dir\src\ftdi.cpp.obj
  [60/131] Linking CXX static library _deps\libftdi-build\libftdi.lib
  [61/131] Building CXX object _deps\libusb-build\CMakeFiles\libusb.dir\src\windows.cpp.obj
  [62/131] Building C object _deps\libusb-build\CMakeFiles\libusb.dir\src\error.c.obj
  [63/131] Building C object _deps\libusb-build\CMakeFiles\libusb.dir\src\registry.c.obj
  [64/131] Building C object _deps\libhidapi-build\CMakeFiles\libhidapi.dir\src\hid.c.obj
  [65/131] Linking CXX static library _deps\libusb-build\libusb.lib
  [66/131] Linking C static library _deps\libhidapi-build\libhidapi.lib
  [67/131] [FLEX][Parser] Building scanner with win_flex 2.6.4
  [68/131] [BISON][Parser] Building parser with bison 3.7.4
  [69/131] Building C object src\CMakeFiles\libavrdude.dir\arduino.c.obj
  [70/131] Building C object src\CMakeFiles\libavrdude.dir\avr910.c.obj
  [71/131] Building C object src\CMakeFiles\libavrdude.dir\avrftdi_tpi.c.obj
  [72/131] Building C object src\CMakeFiles\libavrdude.dir\avr.c.obj
  [73/131] Building C object src\CMakeFiles\libavrdude.dir\fileio.c.obj
  [74/131] Building C object src\CMakeFiles\libavrdude.dir\dfu.c.obj
  [75/131] Building C object src\CMakeFiles\libavrdude.dir\ft245r.c.obj
  [76/131] Building C object src\CMakeFiles\libavrdude.dir\flip2.c.obj
  [77/131] Building C object src\CMakeFiles\libavrdude.dir\jtagmkI.c.obj
  [78/131] Building C object src\CMakeFiles\libavrdude.dir\avrftdi.c.obj
  [79/131] Building C object src\CMakeFiles\libavrdude.dir\crc16.c.obj
  [80/131] Building C object src\CMakeFiles\libavrdude.dir\buspirate.c.obj
  [81/131] Building C object src\CMakeFiles\libavrdude.dir\config.c.obj
  [82/131] Building C object src\CMakeFiles\libavrdude.dir\flip1.c.obj
  [83/131] Building C object src\CMakeFiles\libavrdude.dir\butterfly.c.obj
  [84/131] Building C object src\CMakeFiles\libavrdude.dir\avrpart.c.obj
  [85/131] Building C object src\CMakeFiles\libavrdude.dir\micronucleus.c.obj
  [86/131] Building C object src\CMakeFiles\libavrdude.dir\ppi.c.obj
  [87/131] Building C object src\CMakeFiles\libavrdude.dir\linuxspi.c.obj
  [88/131] Building C object src\CMakeFiles\libavrdude.dir\lists.c.obj
  [89/131] Building C object src\CMakeFiles\libavrdude.dir\linuxgpio.c.obj
  [90/131] Building C object src\CMakeFiles\libavrdude.dir\jtagmkII.c.obj
  [91/131] Building C object src\CMakeFiles\libavrdude.dir\jtag3.c.obj
  [92/131] Building C object src\CMakeFiles\libavrdude.dir\par.c.obj
  [93/131] Building C object src\CMakeFiles\libavrdude.dir\ser_posix.c.obj
  [94/131] Building C object src\CMakeFiles\libavrdude.dir\serbb_posix.c.obj
  [95/131] Building C object src\CMakeFiles\libavrdude.dir\pgm.c.obj
  [96/131] Building C object src\CMakeFiles\libavrdude.dir\pgm_type.c.obj
  [97/131] Building C object src\CMakeFiles\libavrdude.dir\pindefs.c.obj
  [98/131] Building C object src\CMakeFiles\libavrdude.dir\ppiwin.c.obj
  [99/131] Building C object src\CMakeFiles\libavrdude.dir\bitbang.c.obj
  [100/131] Building C object src\CMakeFiles\libavrdude.dir\ser_avrdoper.c.obj
  [101/131] Building C object src\CMakeFiles\libavrdude.dir\teensy.c.obj
  [102/131] Building C object src\CMakeFiles\libavrdude.dir\serialupdi.c.obj
  [103/131] Building C object src\CMakeFiles\libavrdude.dir\confwin.c.obj
  [104/131] Building C object src\CMakeFiles\libavrdude.dir\stk500generic.c.obj
  [105/131] Building C object src\CMakeFiles\libavrdude.dir\stk500.c.obj
  [106/131] Building C object src\CMakeFiles\libavrdude.dir\serbb_win32.c.obj
  [107/131] Building C object src\CMakeFiles\libavrdude.dir\pickit2.c.obj
  [108/131] Building C object src\CMakeFiles\libavrdude.dir\updi_link.c.obj
  [109/131] Building C object src\CMakeFiles\libavrdude.dir\stk500v2.c.obj
  [110/131] Building C object src\CMakeFiles\libavrdude.dir\usbtiny.c.obj
  [111/131] Building C object src\CMakeFiles\libavrdude.dir\updi_readwrite.c.obj
  [112/131] Building C object src\CMakeFiles\libavrdude.dir\updi_nvm.c.obj
  [113/131] Building C object src\CMakeFiles\libavrdude.dir\usbasp.c.obj
  [114/131] Building C object src\CMakeFiles\libavrdude.dir\updi_state.c.obj
  [115/131] Building C object src\CMakeFiles\libavrdude.dir\__\config_gram.c.obj
  [116/131] Building C object src\CMakeFiles\libavrdude.dir\usb_libusb.c.obj
  [117/131] Building C object src\CMakeFiles\libavrdude.dir\update.c.obj
  [118/131] Building C object src\CMakeFiles\libavrdude.dir\usb_hidapi.c.obj
  [119/131] Building C object src\CMakeFiles\libavrdude.dir\__\lexer.c.obj
  [120/131] Building C object src\CMakeFiles\libavrdude.dir\ser_win32.c.obj
  [121/131] Building C object src\CMakeFiles\libavrdude.dir\wiring.c.obj
  [122/131] Building C object src\CMakeFiles\libavrdude.dir\xbee.c.obj
  [123/131] Building C object src\CMakeFiles\avrdude.dir\term.c.obj
  [124/131] Building C object src\CMakeFiles\libavrdude.dir\msvc\gettimeofday.c.obj
  [125/131] Building C object src\CMakeFiles\avrdude.dir\main.c.obj
  [126/131] Building C object src\CMakeFiles\libavrdude.dir\msvc\getopt.c.obj
  [127/131] Building RC object src\CMakeFiles\avrdude.dir\windows.rc.res
  Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
  
  
  Copyright (C) Microsoft Corporation.  All rights reserved.
  
  
  
  
  [128/131] Building CXX object src\CMakeFiles\libavrdude.dir\msvc\usleep.cpp.obj
  [129/131] Building C object src\CMakeFiles\avrdude.dir\whereami.c.obj
  [130/131] Linking CXX static library src\libavrdude.lib
  [131/131] Linking CXX executable src\avrdude.exe

Build All succeeded.

PS C:\work\avr\avrdude_test\avrdude-fork> .\out\build\x64-Debug\src\avrdude.exe
Usage: avrdude.exe [options]
Options:
  -p <partno>                Required. Specify AVR device.
  -b <baudrate>              Override RS-232 baud rate.
  -B <bitclock>              Specify JTAG/STK500v2 bit clock period (us).
  -C <config-file>           Specify location of configuration file.
  -c <programmer>            Specify programmer type.
  -D                         Disable auto erase for flash memory
  -i <delay>                 ISP Clock Delay [in microseconds]
  -P <port>                  Specify connection port.
  -F                         Override invalid signature check.
  -e                         Perform a chip erase.
  -O                         Perform RC oscillator calibration (see AVR053).
  -U <memtype>:r|w|v:<filename>[:format]
                             Memory operation specification.
                             Multiple -U options are allowed, each request
                             is performed in the order specified.
  -n                         Do not write anything to the device.
  -V                         Do not verify.
  -t                         Enter terminal mode.
  -E <exitspec>[,<exitspec>] List programmer exit specifications.
  -x <extended_param>        Pass <extended_param> to programmer.
  -v                         Verbose output. -v -v for more.
  -q                         Quell progress output. -q -q for less.
  -l logfile                 Use logfile rather than stderr for diagnostics.
  -?                         Display this usage.

avrdude version 7.0-20220511 (65bb41f), URL: <https://github.com/avrdudes/avrdude>

@mcuee
Copy link
Collaborator

mcuee commented May 14, 2022

Under MSYS2 mingw64, this works perfectly fine.

/c/work/avr/avrdude_test/avrdude-fork/build_sharedlib
$  cmake -G "MSYS Makefiles" .. -DUSE_STATIC_LIBS="OFF" -DCMAKE_VERBOSE_MAKEFILE="ON"
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/msys64/usr/bin/git.exe (found version "2.36.1")
-- Found FLEX: C:/msys64/usr/bin/flex.exe (found version "2.6.4")
-- Found BISON: C:/msys64/usr/bin/bison.exe (found version "3.8.2")
-- Looking for libelf.h
-- Looking for libelf.h - found
-- Looking for libelf/libelf.h
-- Looking for libelf/libelf.h - found
-- Looking for usb.h
-- Looking for usb.h - not found
-- Looking for lusb0_usb.h
-- Looking for lusb0_usb.h - found
-- Looking for libusb.h
-- Looking for libusb.h - not found
-- Looking for libusb-1.0/libusb.h
-- Looking for libusb-1.0/libusb.h - found
-- Looking for hidapi/hidapi.h
-- Looking for hidapi/hidapi.h - found
-- Looking for ftdi_tcioflush
-- Looking for ftdi_tcioflush - found
-- Configuration summary:
-- ----------------------
-- DO HAVE    libelf
-- DO HAVE    libusb
-- DO HAVE    libusb_1_0
-- DO HAVE    libhidapi
-- DON'T HAVE libftdi
-- DO HAVE    libftdi1
-- DISABLED   doc
-- DISABLED   parport
-- DISABLED   linuxgpio
-- DISABLED   linuxspi
-- ----------------------
-- Configuring done
-- Generating done
-- Build files have been written to: C:/work/avr/avrdude_test/avrdude-fork/build_sharedlib

...
[100%] Linking C executable avrdude.exe
cd /C/work/avr/avrdude_test/avrdude-fork/build_sharedlib/src && /C/msys64/mingw64/bin/cmake.exe -E rm -f CMakeFiles/avrdude.dir/objects.a
cd /C/work/avr/avrdude_test/avrdude-fork/build_sharedlib/src && /C/msys64/mingw64/bin/ar.exe qc CMakeFiles/avrdude.dir/objects.a "CMakeFiles/avrdude.dir/main.c.obj" "CMakeFiles/avrdude.dir/term.c.obj" "CMakeFiles/avrdude.dir/whereami.c.obj" "CMakeFiles/avrdude.dir/windows.rc.obj"
cd /C/work/avr/avrdude_test/avrdude-fork/build_sharedlib/src && /C/msys64/mingw64/bin/gcc.exe -Wl,--whole-archive CMakeFiles/avrdude.dir/objects.a -Wl,--no-whole-archive -o avrdude.exe -Wl,--out-implib,libavrdude.dll.a -Wl,--major-image-version,0,--minor-image-version,0  libavrdude.a -lm /C/msys64/mingw64/lib/libelf.a /C/msys64/mingw64/lib/libusb.dll.a /C/msys64/mingw64/lib/libusb-1.0.dll.a /C/msys64/mingw64/lib/libhid.a /C/msys64/mingw64/lib/libhidapi.dll.a /C/msys64/mingw64/lib/libftdi1.dll.a /C/msys64/mingw64/lib/libreadline.dll.a -lsetupapi -lws2_32 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
make[2]: Leaving directory '/c/work/avr/avrdude_test/avrdude-fork/build_sharedlib'
[100%] Built target avrdude
make[1]: Leaving directory '/c/work/avr/avrdude_test/avrdude-fork/build_sharedlib'
/C/msys64/mingw64/bin/cmake.exe -E cmake_progress_start /C/work/avr/avrdude_test/avrdude-fork/build_sharedlib/CMakeFiles 0

Copy link
Collaborator

@mcuee mcuee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested under MSYS2 mingw64 and this works fine (both with static or shared dependancy lib linking). And it has fixed #959.

@mariusgreuel
Copy link
Contributor Author

Note that the CMake files now include the option USE_STATIC_LIBS, which people can use to select either static or dynamic linking. Note, however, that I leave the implementation for somebody else in a separate PR. The current implementation will not work for non-defaults, i.e. statically linking for Linux or dynamically on Windows.

@mariusgreuel mariusgreuel merged commit d9f8fde into avrdudes:main Jun 8, 2022
mariusgreuel added a commit that referenced this pull request Jun 10, 2022
@mcuee mcuee added the enhancement New feature or request label Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants