libftdi Archives

Subject: [PATCH v2 6/6] CMake: make the project compatible ´with building as a subproject

From: yegorslists@xxxxxxxxxxxxxx
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Cc: thomas.jarosch@xxxxxxxxxxxxx, Yegor Yefremov <yegorslists@xxxxxxxxxxxxxx>
Date: Mon, 11 Sep 2023 10:04:04 +0200
From: Yegor Yefremov <yegorslists@xxxxxxxxxxxxxx>

Use CMAKE_CURRENT_*_DIR in the mein CMakeLists.txt and PROJECT_*_DIR
in the subdirectories.
---
 CMakeLists.txt             | 14 +++++++-------
 examples/CMakeLists.txt    |  4 ++--
 ftdi_eeprom/CMakeLists.txt |  2 +-
 ftdipp/CMakeLists.txt      |  2 +-
 python/CMakeLists.txt      |  2 +-
 test/CMakeLists.txt        |  2 +-
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7f72e0c..6284c8d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,7 @@ set(MINOR_VERSION 5)
 set(PACKAGE libftdi1)
 set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION})
 set(VERSION ${VERSION_STRING})
-set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
+set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
 
 # Support new if() IN_LIST operator
 if(POLICY CMP0057)
@@ -117,7 +117,7 @@ if ( WIN32 )
   set ( CPACK_NSIS_MODIFY_PATH             ON )
 endif ()
 
-set(CPACK_RESOURCE_FILE_LICENSE        ${CMAKE_SOURCE_DIR}/LICENSE)
+set(CPACK_RESOURCE_FILE_LICENSE        ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
 
 set(CPACK_SOURCE_GENERATOR             TGZ)
 set(CPACK_SOURCE_IGNORE_FILES          "\\\\.git;~$;build/")
@@ -132,8 +132,8 @@ endif ()
 set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${VERSION_STRING})
 add_custom_target(dist
     COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
-            | bzip2 > ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
-    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+      | bzip2 > ${PROJECT_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
+    WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 
 add_subdirectory(src)
 add_subdirectory(packages)
@@ -176,9 +176,9 @@ if(${WIN32})
   set(libdir      ${CMAKE_INSTALL_PREFIX}/bin)
 endif(${WIN32})
 
-configure_file(${CMAKE_SOURCE_DIR}/libftdi1.pc.in 
${CMAKE_BINARY_DIR}/libftdi1.pc @ONLY)
-configure_file(${CMAKE_SOURCE_DIR}/libftdipp1.pc.in 
${CMAKE_BINARY_DIR}/libftdipp1.pc @ONLY)
-install(FILES ${CMAKE_BINARY_DIR}/libftdi1.pc ${CMAKE_BINARY_DIR}/libftdipp1.pc
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libftdi1.pc.in 
${CMAKE_CURRENT_BINARY_DIR}/libftdi1.pc @ONLY)
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libftdipp1.pc.in 
${CMAKE_CURRENT_BINARY_DIR}/libftdipp1.pc @ONLY)
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libftdi1.pc 
${CMAKE_CURRENT_BINARY_DIR}/libftdipp1.pc
         DESTINATION lib${LIB_SUFFIX}/pkgconfig)
 
 if (UNIX OR MINGW)
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 382cb33..9ec7bff 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -37,7 +37,7 @@ endif(NOT MINGW)
 
 # libftdi++ examples
 if( FTDIPP )
-  include_directories(BEFORE ${CMAKE_SOURCE_DIR}/ftdipp
+  include_directories(BEFORE ${PROJECT_SOURCE_DIR}/ftdipp
     ${Boost_INCLUDE_DIRS}
   )
 
@@ -49,4 +49,4 @@ if( FTDIPP )
 endif( FTDIPP )
 
 # Source includes
-include_directories(BEFORE ${CMAKE_SOURCE_DIR}/src)
+include_directories(BEFORE ${PROJECT_SOURCE_DIR}/src)
diff --git a/ftdi_eeprom/CMakeLists.txt b/ftdi_eeprom/CMakeLists.txt
index 8737c4b..525421e 100644
--- a/ftdi_eeprom/CMakeLists.txt
+++ b/ftdi_eeprom/CMakeLists.txt
@@ -27,7 +27,7 @@ set ( EEPROM_MAJOR_VERSION 0 )
 set ( EEPROM_MINOR_VERSION 17 )
 set ( EEPROM_VERSION_STRING ${EEPROM_MAJOR_VERSION}.${EEPROM_MINOR_VERSION} )
 
-include_directories ( BEFORE ${CMAKE_SOURCE_DIR}/src )
+include_directories ( BEFORE ${PROJECT_SOURCE_DIR}/src )
 include_directories ( BEFORE ${CMAKE_CURRENT_BINARY_DIR} )
 
 configure_file(
diff --git a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt
index fa2711f..5e23a07 100644
--- a/ftdipp/CMakeLists.txt
+++ b/ftdipp/CMakeLists.txt
@@ -5,7 +5,7 @@ set(cpp_headers ${CMAKE_CURRENT_SOURCE_DIR}/ftdi.hpp CACHE 
INTERNAL "List of cpp
 # Includes
 include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}
-  ${CMAKE_SOURCE_DIR}/src
+  ${PROJECT_SOURCE_DIR}/src
 )
 
 include_directories(${Boost_INCLUDE_DIRS})
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 6ab14cd..5e406ff 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -18,7 +18,7 @@ find_package ( PythonInterp REQUIRED )
 find_package ( PythonLibs REQUIRED )
 
 include ( UseSWIG )
-include_directories ( BEFORE ${CMAKE_SOURCE_DIR}/src )
+include_directories ( BEFORE ${PROJECT_SOURCE_DIR}/src )
 include_directories ( ${PYTHON_INCLUDE_DIRS} )
 link_directories ( ${CMAKE_CURRENT_BINARY_DIR}/../src )
 
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 392c910..c44c614 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -2,7 +2,7 @@ find_package(Boost COMPONENTS unit_test_framework REQUIRED)
 
 enable_testing()
 
-INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS})
+INCLUDE_DIRECTORIES(BEFORE ${PROJECT_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS})
 
 set(cpp_tests basic.cpp baudrate.cpp)
 
-- 
2.34.1


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread