Tweaks to build the whole project on Windows with CMake/MSVC 19 in 2026 - #305
Tweaks to build the whole project on Windows with CMake/MSVC 19 in 2026#305twdragon wants to merge 8 commits into
Conversation
twdragon
commented
Jul 30, 2026
- Fixed the PLC port definitions mistakenly left in the BSD section in the test program
- Added CMake tweaks to successfully build the project on Windows natively using git/MSVC/PowerShell
- Implemented TcAdsDll_ROOT CMake variable to let the build system catch the libraries from non-standard locations. Tested on non-native installation in Windows 10.0.19045 and SDK 10.0.26100.0
- Fixed the PLC port definitions mistakenly left in the BSD section
in the test program
- Added CMake tweaks to successfully build the project on Windows natively
using git/MSVC/PowerShell
- Implemented TcAdsDll_ROOT CMake variable to let the build system catch
the libraries from non-standard locations. Tested on non-native
installation in Windows 10.0.19045 and SDK 10.0.26100.0
|
Hello, I am not the maintainer, but I authored the FindTcAdsDll.cmake file that you are editing. I suggest that you should keep the support for finding TcAdsDll in old TwinCAT versions ? The way you are doing it is correct but will only work for the newest versions. The find_library and find_file PATHS argument take an array anyways. Additionally, since the default location is no longer C:/TwinCAT/.. in the new version so we can probably change it to something like this: if (WIN32 AND NOT DEFINED TcAdsDll_ROOT) Try them out, tell me if it works. |
|
@juarezr-mvtec thanks for the suggestion! Unfortunately, direct introduction of array-like path lists did not work, so I used separate variables. |
|
@juarezr-mvtec I will also try to fix the Linux pipeline, but I cannot promise to do it now, so likely it will be a separate PR |
|
Hello @twdragon The problem is that we are passing the variable PATHS with "" like : find_library(TcAdsDll_IMPLIB this makes find_library consider TcAdsDll_IMPLIB_DIR as a single string instead of a list. So removing the "" fixes the issue with passing multiple paths. I tested this on my setup (old version path) and this is working for me: I have not personally tested it but linux should work out of the box at least according to the maintainer (see #295). |
|
@juarezr-mvtec now it looks like: if (WIN32 AND NOT DEFINED TcAdsDll_ROOT)
# Typical install locations on Windows
list(APPEND _TcAdsDll_PATH
"$ENV{SystemDrive}/TwinCAT/AdsApi/TcAdsDll" # Old location (TwinCAT < 3.5)
"$ENV{ProgramFiles(x86)}/Beckhoff/TwinCAT/AdsApi/TcAdsDll" # New location (TwinCAT 3.5+)
)
else ()
set(_TcAdsDll_PATH)
endif ()
# Find the include headers
find_path(TcAdsDll_INCLUDE_DIR
NAMES TcAdsApi.h TcAdsDef.h
PATHS "${_TcAdsDll_PATH_OLD}" "${_TcAdsDll_PATH_NEW}"
PATH_SUFFIXES "Include" "include"
)
# Find all related files base on the include files location. This is done
# assuming that the files are ordered as install by TwinCat. If they are
# in some other configuration this will not work.
if (WIN32)
cmake_path(GET TcAdsDll_INCLUDE_DIR PARENT_PATH TcAdsDll_ROOT_DIR)
if (NOT TcAdsDll_FIND_QUIETLY)
message(STATUS "Searching TcAdsDll in ROOT ${TcAdsDll_ROOT_DIR}")
endif ()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TcAdsDll_IMPLIB_DIR "${TcAdsDll_ROOT_DIR}/Lib/x64")
list(APPEND TcAdsDll_DLL_DIR
"${TcAdsDll_ROOT_DIR}/x64"
"${TcAdsDll_ROOT_DIR}/../../Common64"
)
elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
set(TcAdsDll_IMPLIB_DIR "${TcAdsDll_ROOT_DIR}/Lib")
list(APPEND TcAdsDll_DLL_DIR
"${TcAdsDll_ROOT_DIR}"
"${TcAdsDll_ROOT_DIR}/../../Common32"
)
endif ()
find_library(TcAdsDll_IMPLIB
NAMES TcAdsDll.lib
PATHS ${TcAdsDll_IMPLIB_DIR}
NO_DEFAULT_PATH
)
find_file(TcAdsDll_LIBRARY
NAMES TcAdsDll.dll
PATHS ${TcAdsDll_DLL_DIR}
NO_DEFAULT_PATH
)
else ()
find_library(TcAdsDll_LIBRARY
NAMES TcAdsDll
)
endif ()Attested to work on Windows. Thanks again! |
|
@juarezr-mvtec I implemented and tested it, thanks again! |
|
@juarezr-mvtec I unfortunately don't have a different version of TwinCAT libraries on my workstation, so I cannot fully test the setup |
There was a problem hiding this comment.
Some more changes. With the changes this should work as expected.
I download the latest TwinCAT version and I tested this now with and without setting TcAdsDll_ROOT.
Once the changes are complete I will suggest that you SQUASH all of these changes into a single commit to keep a clean git history. :)
@juarezr-mvtec I will do)) I have not so much time to work on this repo, so I do quick and dirty |