Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ build/
bld/
[Bb]in/
[Oo]bj/
[Ii]nstall/

# Visual Studo 2015 cache/options directory
.vs/
Expand Down
4 changes: 3 additions & 1 deletion AdsLibTestRef/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ using USHORT = unsigned short;
#define TCADSDLL_API
#define TCADSDLL_EXPORT
#define NULL nullptr
#define AMSPORT_R0_PLC_TC3 851
#else
#include <Windows.h>
#endif

#define AMSPORT_R0_PLC_TC3 851

#include <TcAdsDef.h>
#ifndef GLOBALERR_TARGET_PORT
#define GLOBALERR_TARGET_PORT 0x06
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ ninja -C example/build
# and run the example
./example/build/example
```
## On Windows with TwinCAT installed (PowerShell)
```ps1
mkdir build && cd build
# Use TcAdsDll_ROOT if AdsApi is installed somewhere in a different location
# Here it is taken from the TWINCAT_ADS_API_ROOT environment variable
cmake -DTcAdsDll_ROOT="$TWINCAT_ADS_API_ROOT" ..
cmake --build . --config Release --parallel ((Get-CimInstance –ClassName Win32_Processor).NumberOfLogicalProcessors | Measure-Object -Sum).Sum
```

Note: the name of the binaries which use the TwinCAT ADS Router have a different naming scheme

Expand Down
60 changes: 41 additions & 19 deletions cmake/FindTcAdsDll.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@ if (NOT WIN32)
message(WARNING "FindTcAdsDll.cmake only tested on WINDOWS")
endif ()

if (WIN32)
if (DEFINED TcAdsDll_ROOT)
set(_TcAdsDll_PATH "${TcAdsDll_ROOT}")
endif ()

if (WIN32 AND NOT DEFINED TcAdsDll_ROOT)
# Typical install locations on Windows
set(_TcAdsDll_PATH "$ENV{SystemDrive}/TwinCAT/AdsApi/TcAdsDll")
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 ()
# TODO: Linux not tested. Set additional known default locations to search.
set(_TcAdsDll_PATH)
endif ()
# Find the include headers

find_path(TcAdsDll_INCLUDE_DIR
NAMES TcAdsApi.h TcAdsDef.h
PATHS "${_TcAdsDll_PATH}"
PATHS ${_TcAdsDll_PATH}
PATH_SUFFIXES "Include" "include"
)
# Find all related files base on the include files location. This is done
Expand All @@ -39,41 +46,56 @@ find_path(TcAdsDll_INCLUDE_DIR
if (WIN32)
cmake_path(GET TcAdsDll_INCLUDE_DIR PARENT_PATH TcAdsDll_ROOT_DIR)
if (NOT TcAdsDll_FIND_QUIETLY)
message(STATUS "Looking for TcAdsDll in ROOT ${TcAdsDll_ROOT_DIR}")
message(STATUS "Searching TcAdsDll in ROOT ${TcAdsDll_ROOT_DIR}")
endif ()
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TcAdsDll_IMPLIB_DIR "${TcAdsDll_ROOT_DIR}/x64/lib")
set(TcAdsDll_DLL_DIR "${TcAdsDll_ROOT_DIR}/x64")
list(APPEND TcAdsDll_IMPLIB_DIR
"${TcAdsDll_ROOT_DIR}/x64/lib" # Old location (TwinCAT < 3.5)
"${TcAdsDll_ROOT_DIR}/Lib/x64" # New location (TwinCAT 3.5+)
)
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")
set(TcAdsDll_DLL_DIR "${TcAdsDll_ROOT_DIR}")
list(APPEND TcAdsDll_IMPLIB_DIR
"${TcAdsDll_ROOT_DIR}/lib" # Old location (TwinCAT < 3.5)
"${TcAdsDll_ROOT_DIR}/Lib" # New location (TwinCAT 3.5+)
)
list(APPEND TcAdsDll_DLL_DIR
"${TcAdsDll_ROOT_DIR}"
"${TcAdsDll_ROOT_DIR}/../../Common32"
)
endif ()
# Use NO_DEFAULT_PATH so that we only look in the provided location. If not set
# the find_library will find the 32 bit version first regardless of the config
# which leads to errors.
find_library(TcAdsDll_IMPLIB
NAMES TcAdsDll
PATHS "${TcAdsDll_IMPLIB_DIR}"
NAMES TcAdsDll.lib
PATHS ${TcAdsDll_IMPLIB_DIR}
NO_DEFAULT_PATH
)
find_file(TcAdsDll_LIBRARY
NAMES TcAdsDll.dll
PATHS "${TcAdsDll_DLL_DIR}"
PATHS ${TcAdsDll_DLL_DIR}
NO_DEFAULT_PATH
)
else ()
# TODO: Linux not tested. We just try to look for the library by name.
find_library(TcAdsDll_LIBRARY
NAMES TcAdsDll
)
endif ()


include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(TcAdsDll
Comment thread
twdragon marked this conversation as resolved.

if (WIN32)
find_package_handle_standard_args(TcAdsDll
REQUIRED_VARS TcAdsDll_INCLUDE_DIR TcAdsDll_LIBRARY TcAdsDll_IMPLIB
VERSION_VAR TcAdsDll_VERSION
)
else ()
find_package_handle_standard_args(TcAdsDll
REQUIRED_VARS TcAdsDll_INCLUDE_DIR TcAdsDll_LIBRARY
VERSION_VAR TcAdsDll_VERSION
)
)
endif ()

if (NOT TcAdsDll_FOUND)
if (NOT TcAdsDll_FIND_QUIETLY)
Expand Down