96 lines
2.6 KiB
CMake
96 lines
2.6 KiB
CMake
cmake_minimum_required(VERSION 3.15)
|
|
|
|
if(NOT DEFINED ETHERCAT_VERSION)
|
|
set(ETHERCAT_VERSION 0.0.0)
|
|
endif()
|
|
|
|
project(
|
|
ethercat
|
|
VERSION ${ETHERCAT_VERSION}
|
|
DESCRIPTION "IgH EtherCAT Master userspace client library"
|
|
LANGUAGES C)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
option(BUILD_SHARED_LIBS "Build shared library" ON)
|
|
set(EC_MAX_NUM_DEVICES
|
|
1
|
|
CACHE STRING
|
|
"Max number of Ethernet devices per master (must match kernel module)")
|
|
|
|
set(ETHERCAT_SOURCES
|
|
lib/common.c
|
|
lib/domain.c
|
|
lib/master.c
|
|
lib/reg_request.c
|
|
lib/sdo_request.c
|
|
lib/slave_config.c
|
|
lib/voe_handler.c)
|
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/soe_request.c")
|
|
list(APPEND ETHERCAT_SOURCES lib/soe_request.c)
|
|
endif()
|
|
|
|
set(ETHERCAT_PUBLIC_HEADERS
|
|
include/ecrt.h
|
|
include/ectty.h)
|
|
|
|
add_library(ethercat ${ETHERCAT_SOURCES})
|
|
add_library(EtherLab::ethercat ALIAS ethercat)
|
|
|
|
# The userspace library expects a few configure-time defines from autotools.
|
|
file(
|
|
WRITE ${CMAKE_CURRENT_BINARY_DIR}/config.h
|
|
"/* Generated by the Conan recipe. */\n"
|
|
"#ifndef CONFIG_H\n"
|
|
"#define CONFIG_H\n"
|
|
"#ifndef VERSION\n"
|
|
"#define VERSION \"${PROJECT_VERSION}\"\n"
|
|
"#endif\n"
|
|
"#ifndef REV\n"
|
|
"#define REV \"\"\n"
|
|
"#endif\n"
|
|
"#endif\n")
|
|
|
|
set_target_properties(
|
|
ethercat
|
|
PROPERTIES PUBLIC_HEADER "${ETHERCAT_PUBLIC_HEADERS}"
|
|
SOVERSION 1)
|
|
|
|
target_compile_definitions(
|
|
ethercat PRIVATE EC_MAX_NUM_DEVICES=${EC_MAX_NUM_DEVICES}
|
|
VERSION="${PROJECT_VERSION}" REV="")
|
|
|
|
target_compile_options(
|
|
ethercat PRIVATE -fno-strict-aliasing -Wall -Wmissing-prototypes)
|
|
|
|
target_include_directories(
|
|
ethercat
|
|
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}
|
|
${CMAKE_CURRENT_SOURCE_DIR}/lib
|
|
${CMAKE_CURRENT_SOURCE_DIR}/master)
|
|
|
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/lib/libethercat.map")
|
|
target_compile_definitions(ethercat PRIVATE ethercat_EXPORTS)
|
|
target_compile_options(ethercat PRIVATE -fvisibility=hidden)
|
|
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
|
|
target_link_options(
|
|
ethercat PRIVATE
|
|
"LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/lib/libethercat.map")
|
|
endif()
|
|
endif()
|
|
|
|
if(UNIX AND NOT APPLE)
|
|
target_link_libraries(ethercat PRIVATE rt)
|
|
endif()
|
|
|
|
install(
|
|
TARGETS ethercat
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|