From: Yegor Yefremov Date: Mon, 11 Sep 2023 08:04:04 +0000 (+0200) Subject: CMake: make the project compatible with building as a subproject X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=commitdiff_plain;h=e7f734f82c69aea10f1f9bde57f228339fcb56f3 CMake: make the project compatible with building as a subproject Use CMAKE_CURRENT_*_DIR in the main CMakeLists.txt and PROJECT_*_DIR in the subdirectories. --- 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)