From 9b00f4cf979ff2ed6d8d2f4ae6cfa431e9946a64 Mon Sep 17 00:00:00 2001 From: contradict Date: Tue, 17 May 2022 15:39:00 -0700 Subject: [PATCH 1/6] Generate EIPScannerConfig.cmake This file allows other projects to find_library(EIPScanner) and get the installed header and library locations. --- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++ EIPScannerConfig.cmake.in | 16 +++++++++++++++ EIPScannerConfigVersion.cmake.in | 13 ++++++++++++ src/CMakeLists.txt | 6 +++--- 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 EIPScannerConfig.cmake.in create mode 100644 EIPScannerConfigVersion.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 397ef55..7649fe6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,3 +31,37 @@ if (TEST_ENABLED) add_subdirectory(test) endif() +set(INSTALL_CMAKE_DIR share/EIPScanner/cmake CACHE PATH + "Installation directory for CMake files") +# ... for the build tree +set(INSTALL_INCLUDE_DIR include/EIPScanner CACHE PATH + "Installation directory for header files") +# ... for the build tree +set(INSTALL_LIB_DIR lib CACHE PATH + "Installation directory for header files") +# Make relative paths absolute (needed later on) +# foreach(p LIB BIN INCLUDE CMAKE) +foreach(p LIB INCLUDE CMAKE) + set(var INSTALL_${p}_DIR) + if(NOT IS_ABSOLUTE "${${var}}") + set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") + endif() +endforeach() + +file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" + "${INSTALL_INCLUDE_DIR}") +set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}") +configure_file(EIPScannerConfig.cmake.in + "${PROJECT_BINARY_DIR}/EIPScannerConfig.cmake" @ONLY) +# ... for the install tree +set(CONF_INCLUDE_DIRS "\${EIPSCANNER_CMAKE_DIR}/${REL_INCLUDE_DIR}") +configure_file(EIPScannerConfig.cmake.in + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/EIPScannerConfig.cmake" @ONLY) +# ... for both +configure_file(EIPScannerConfigVersion.cmake.in + "${PROJECT_BINARY_DIR}/EIPScannerConfigVersion.cmake" @ONLY) +# Install the EIPScannerConfig.cmake and EIPScannerConfigVersion.cmake +install(FILES + "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/EIPScannerConfig.cmake" + "${PROJECT_BINARY_DIR}/EIPScannerConfigVersion.cmake" + DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) diff --git a/EIPScannerConfig.cmake.in b/EIPScannerConfig.cmake.in new file mode 100644 index 0000000..21423e0 --- /dev/null +++ b/EIPScannerConfig.cmake.in @@ -0,0 +1,16 @@ +# - Config file for the EIPScanner package +# It defines the following variables +# EIPSCANNER_INCLUDE_DIRS - include directories for EIPScanner +# EIPSCANNER_LIBRARIES - libraries to link against +# EIPSCANNER_EXECUTABLE - the bar executable + +# Compute paths +get_filename_component(EIPSCANNER_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(EIPSCANNER_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") + +# Our library dependencies (contains definitions for IMPORTED targets) +# include("${EIPSCANNER_CMAKE_DIR}/EIPScannerTargets.cmake") + +# These are IMPORTED targets created by FooBarTargets.cmake +set(EIPSCANNER_LIBRARIES EIPScanner) +set(EIPSCANNER_LIBRARY_DIR "@INSTALL_LIB_DIR@") diff --git a/EIPScannerConfigVersion.cmake.in b/EIPScannerConfigVersion.cmake.in new file mode 100644 index 0000000..7d0e6ba --- /dev/null +++ b/EIPScannerConfigVersion.cmake.in @@ -0,0 +1,13 @@ +set(PACKAGE_VERSION "@EIPSCANNER_FULL_VERSION@") + +# Check whether the requested PACKAGE_FIND_VERSION is compatible +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6a58194..5d3e6ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,10 +66,10 @@ set_target_properties( install(TARGETS EIPScanner EIPScannerS LIBRARY - DESTINATION lib + DESTINATION ${INSTALL_LIB_DIR} ARCHIVE - DESTINATION lib) + DESTINATION ${INSTALL_LIB_DIR}) install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ - DESTINATION include/EIPScanner + DESTINATION "${INSTALL_INCLUDE_DIR}" FILES_MATCHING PATTERN "*.h*") From 4390a403e0b345932bf25536a9d827a3aa613028 Mon Sep 17 00:00:00 2001 From: contradict Date: Tue, 17 May 2022 16:32:27 -0700 Subject: [PATCH 2/6] Order matters! --- CMakeLists.txt | 18 +++++++++--------- src/CMakeLists.txt | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7649fe6..624731d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,15 +22,6 @@ if (WIN32) endif() endif() -add_subdirectory(src) -if (EXAMPLE_ENABLED) - add_subdirectory(examples) -endif() - -if (TEST_ENABLED) - add_subdirectory(test) -endif() - set(INSTALL_CMAKE_DIR share/EIPScanner/cmake CACHE PATH "Installation directory for CMake files") # ... for the build tree @@ -65,3 +56,12 @@ install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/EIPScannerConfig.cmake" "${PROJECT_BINARY_DIR}/EIPScannerConfigVersion.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) + +add_subdirectory(src) +if (EXAMPLE_ENABLED) + add_subdirectory(examples) +endif() + +if (TEST_ENABLED) + add_subdirectory(test) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d3e6ff..2e0dfe4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,10 +66,10 @@ set_target_properties( install(TARGETS EIPScanner EIPScannerS LIBRARY - DESTINATION ${INSTALL_LIB_DIR} + DESTINATION "${INSTALL_LIB_DIR}" ARCHIVE - DESTINATION ${INSTALL_LIB_DIR}) + DESTINATION "${INSTALL_LIB_DIR}") -install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ +install(DIRECTORY "${PROJECT_SOURCE_DIR}/src/" DESTINATION "${INSTALL_INCLUDE_DIR}" FILES_MATCHING PATTERN "*.h*") From f54279846c40638b6aeeb8b4f4ff78e65be28cc9 Mon Sep 17 00:00:00 2001 From: contradict Date: Wed, 18 May 2022 09:06:28 -0700 Subject: [PATCH 3/6] Correct project name. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 624731d..603c768 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,7 @@ set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}") configure_file(EIPScannerConfig.cmake.in "${PROJECT_BINARY_DIR}/EIPScannerConfig.cmake" @ONLY) # ... for the install tree -set(CONF_INCLUDE_DIRS "\${EIPSCANNER_CMAKE_DIR}/${REL_INCLUDE_DIR}") +set(CONF_INCLUDE_DIRS "\${EIPScanner_CMAKE_DIR}/${REL_INCLUDE_DIR}") configure_file(EIPScannerConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/EIPScannerConfig.cmake" @ONLY) # ... for both From e0c32f7e0171f914c5c88d8e6b81c691a3a85bc3 Mon Sep 17 00:00:00 2001 From: contradict Date: Wed, 18 May 2022 09:07:10 -0700 Subject: [PATCH 4/6] Project name fixes and error checking Check and normalize each include and library path. --- EIPScannerConfig.cmake.in | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/EIPScannerConfig.cmake.in b/EIPScannerConfig.cmake.in index 21423e0..d13a598 100644 --- a/EIPScannerConfig.cmake.in +++ b/EIPScannerConfig.cmake.in @@ -1,16 +1,38 @@ # - Config file for the EIPScanner package # It defines the following variables -# EIPSCANNER_INCLUDE_DIRS - include directories for EIPScanner -# EIPSCANNER_LIBRARIES - libraries to link against -# EIPSCANNER_EXECUTABLE - the bar executable +# EIPScanner_INCLUDE_DIRS - include directories for EIPScanner +# EIPscanner_LIBRARIES - libraries to link against +# EIPScanner_EXECUTABLE - the executable # Compute paths -get_filename_component(EIPSCANNER_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -set(EIPSCANNER_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") +get_filename_component(EIPScanner_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +set(_include_directories "@CONF_INCLUDE_DIRS@") +if(NOT _include_directories STREQUAL "") + foreach(_include_dir ${_include_directories}) + if(NOT IS_DIRECTORY "${_include_dir}") + message(WARNING "Package '@PROJECT_NAME@' exports the + include directory '${_include_dir}' which doesn't exist") + endif() + normalize_path(_include_dir "${_include_dir}") + list(APPEND @PROJECT_NAME@_INCLUDE_DIRS "${_include_dir}") + endforeach() +endif() # Our library dependencies (contains definitions for IMPORTED targets) # include("${EIPSCANNER_CMAKE_DIR}/EIPScannerTargets.cmake") # These are IMPORTED targets created by FooBarTargets.cmake -set(EIPSCANNER_LIBRARIES EIPScanner) -set(EIPSCANNER_LIBRARY_DIR "@INSTALL_LIB_DIR@") +set(EIPScanner_LIBRARIES EIPScanner) + +set(_lib_dirs "@INSTALL_LIB_DIR@") +if(NOT _lib_dirs STREQUAL "") + foreach(_lib_dir ${_lib_dirs}) + if(NOT IS_DIRECTORY "${_lib_dir}") + message(WARNING "Package '@PROJECT_NAME@' exports the + include directory '${_lib_dir}' which doesn't exist") + endif() + normalize_path(_lib_dir "${_lib_dir}") + list(APPEND @PROJECT_NAME@_LIBRARY_DIRS "${_lib_dir}") + endforeach() +endif() From b317dd5b0fc29837050bb1c3aaa107f624a7885c Mon Sep 17 00:00:00 2001 From: Lars Janssen Date: Tue, 1 Nov 2022 11:45:00 +0100 Subject: [PATCH 5/6] Do not normalize path --- EIPScannerConfig.cmake.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/EIPScannerConfig.cmake.in b/EIPScannerConfig.cmake.in index d13a598..306c847 100644 --- a/EIPScannerConfig.cmake.in +++ b/EIPScannerConfig.cmake.in @@ -14,7 +14,6 @@ if(NOT _include_directories STREQUAL "") message(WARNING "Package '@PROJECT_NAME@' exports the include directory '${_include_dir}' which doesn't exist") endif() - normalize_path(_include_dir "${_include_dir}") list(APPEND @PROJECT_NAME@_INCLUDE_DIRS "${_include_dir}") endforeach() endif() @@ -32,7 +31,6 @@ if(NOT _lib_dirs STREQUAL "") message(WARNING "Package '@PROJECT_NAME@' exports the include directory '${_lib_dir}' which doesn't exist") endif() - normalize_path(_lib_dir "${_lib_dir}") list(APPEND @PROJECT_NAME@_LIBRARY_DIRS "${_lib_dir}") endforeach() endif() From 9f3529facea674058110e674c99fb62188888dce Mon Sep 17 00:00:00 2001 From: Lars Janssen Date: Tue, 1 Nov 2022 11:45:14 +0100 Subject: [PATCH 6/6] Add package.xml for easy ROS compilation --- CMakeLists.txt | 4 ++++ package.xml | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 package.xml diff --git a/CMakeLists.txt b/CMakeLists.txt index 603c768..019a020 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,3 +65,7 @@ endif() if (TEST_ENABLED) add_subdirectory(test) endif() + +include(GNUInstallDirs) +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/package.xml + DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}) diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..a938f33 --- /dev/null +++ b/package.xml @@ -0,0 +1,22 @@ + + + + + + + EIPScanner + 1.3.0 + + Free implementation of EtherNet/IP in C++ + + + Aleksey Timin + + MIT + + cmake + + + cmake + + \ No newline at end of file