diff --git a/.gitignore b/.gitignore index f073c90..8efc3ae 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ build/ bld/ [Bb]in/ [Oo]bj/ +[Ii]nstall/ # Visual Studo 2015 cache/options directory .vs/ diff --git a/AdsLibTestRef/main.cpp b/AdsLibTestRef/main.cpp index ed20966..2b42e7e 100644 --- a/AdsLibTestRef/main.cpp +++ b/AdsLibTestRef/main.cpp @@ -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 #endif + +#define AMSPORT_R0_PLC_TC3 851 + #include #ifndef GLOBALERR_TARGET_PORT #define GLOBALERR_TARGET_PORT 0x06 diff --git a/README.md b/README.md index cef41cf..1fdac4f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmake/FindTcAdsDll.cmake b/cmake/FindTcAdsDll.cmake index ee44c0a..c6e120e 100644 --- a/cmake/FindTcAdsDll.cmake +++ b/cmake/FindTcAdsDll.cmake @@ -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 @@ -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 + +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)