From ead804ac3d641c842d6b24c1de7e1c235fee2448 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 11 May 2021 07:40:23 +0200 Subject: [PATCH] cmake: add public headers to project source files --- CMake/EnableDtrace.cmake | 14 +++++------ CMake/InstallPublicHeaders.cmake | 27 ++++++++++++--------- CMakeLists.txt | 2 +- include/CMakeLists.txt | 4 ++++ include/libhashkit-1.0/CMakeLists.txt | 4 +++- src/libhashkit/CMakeLists.txt | 7 +++++- src/libmemcached/CMakeLists.txt | 31 ++++++++++++++++--------- src/libmemcachedprotocol/CMakeLists.txt | 8 ++++++- src/libmemcachedutil/CMakeLists.txt | 10 +++++--- 9 files changed, 71 insertions(+), 36 deletions(-) diff --git a/CMake/EnableDtrace.cmake b/CMake/EnableDtrace.cmake index ea7499d7..add0d7fd 100644 --- a/CMake/EnableDtrace.cmake +++ b/CMake/EnableDtrace.cmake @@ -1,9 +1,8 @@ function(enable_dtrace_for TARGET PROBES_D PROBES_H) if(HAVE_DTRACE AND NOT CMAKE_CROSSCOMPILING) - target_sources(${TARGET} PRIVATE ${PROBES_H}) add_custom_command( OUTPUT - ${PROBES_H} + ${CMAKE_CURRENT_BINARY_DIR}/${PROBES_H} MAIN_DEPENDENCY ${PROBES_D} COMMAND @@ -11,20 +10,21 @@ function(enable_dtrace_for TARGET PROBES_D PROBES_H) ARGS -x nolibs -h -s ${CMAKE_CURRENT_SOURCE_DIR}/${PROBES_D} - -o ${PROBES_H} + -o ${CMAKE_CURRENT_BINARY_DIR}/${PROBES_H} ) + target_sources(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${PROBES_H}) if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") add_custom_command( OUTPUT - ${TARGET}_probes.o + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_probes.o MAIN_DEPENDENCY - ${PROBES_H} + ${CMAKE_CURRENT_BINARY_DIR}/${PROBES_H} COMMAND ${DTRACE_EXECUTABLE} ARGS -x nolibs -G -s ${CMAKE_CURRENT_SOURCE_DIR}/${PROBES_D} - -o ${TARGET}_probes.o + -o ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_probes.o ) target_sources(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_probes.o) set_source_files_properties(${TARGET}_probes.o PROPERTIES @@ -43,7 +43,7 @@ function(enable_dtrace_for TARGET PROBES_D PROBES_H) TARGET ${TARGET} PRE_LINK DEPENDS - ${PROBES_H} + ${CMAKE_CURRENT_BINARY_DIR}/${PROBES_H} COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET}.dir/${PROBES_C}.o COMMAND diff --git a/CMake/InstallPublicHeaders.cmake b/CMake/InstallPublicHeaders.cmake index 05629d67..7943ddb2 100644 --- a/CMake/InstallPublicHeaders.cmake +++ b/CMake/InstallPublicHeaders.cmake @@ -1,4 +1,4 @@ -function(install_public_headers DIRECTORY) +macro(install_public_headers DIRECTORY) # validate current directory string(FIND ${CMAKE_CURRENT_SOURCE_DIR} /include/ INCDIR REVERSE) string(FIND ${CMAKE_CURRENT_SOURCE_DIR} /src/ SRCDIR REVERSE) @@ -9,36 +9,41 @@ function(install_public_headers DIRECTORY) math(EXPR POSITION "${SRCDIR} + 5") endif() string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${POSITION} -1 CHKDIR) - if(NOT CHKDIR STREQUAL DIRECTORY) - message(SEND_ERROR "install_public_headers() directories do not match: ${CHKDIR} != ${DIRECTORY}") + if(NOT "${CHKDIR}" STREQUAL "${DIRECTORY}") + message(SEND_ERROR "install_public_headers() directories do not match: '${CHKDIR}' != '${DIRECTORY}'") set(ENV{INVALID_CONFIGURATION} 1) endif() endif() + string(REGEX MATCH "^[^/-]+" LIBRARY "${DIRECTORY}") + # validate public interface version - get_filename_component(TOP ${DIRECTORY} NAME) - string(FIND ${TOP} "-" DASH) + string(FIND "${DIRECTORY}" "-" DASH) if(DASH GREATER 0) - string(SUBSTRING ${TOP} 0 ${DASH} LIBRARY) - string(TOUPPER ${LIBRARY} LIBRARY_UCASE) + string(SUBSTRING "${DIRECTORY}" 0 ${DASH} LIBRARY_BASE) + string(TOUPPER ${LIBRARY_BASE} LIBRARY_UCASE) math(EXPR DASH "${DASH} + 1") - string(SUBSTRING ${TOP} ${DASH} -1 VERSION) + string(SUBSTRING "${DIRECTORY}" ${DASH} -1 VERSION) if(NOT ${LIBRARY_UCASE}_VERSION_INC VERSION_EQUAL ${VERSION}) - message(SEND_ERROR "${LIBRARY} public include directory version ${VERSION} != " ${${LIBRARY_UCASE}_VERSION_INC}) + message(SEND_ERROR "${LIBRARY_BASE} public include directory version ${VERSION} != " ${${LIBRARY_UCASE}_VERSION_INC}) set(ENV{INVALID_CONFIGURATION} 1) endif() endif() # change local includes to system includes - foreach(HEADER IN LISTS ARGN) + foreach(HEADER IN ITEMS ${ARGN}) if(HEADER MATCHES "^@") string(SUBSTRING ${HEADER} 1 -1 HEADER) configure_file(${HEADER}.in ${HEADER}) set(HEADER "${CMAKE_CURRENT_BINARY_DIR}/${HEADER}") + else() + set(HEADER "${CMAKE_CURRENT_SOURCE_DIR}/${HEADER}") endif() install(FILES ${HEADER} COMPONENT dev DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${DIRECTORY} ) + list(APPEND ${LIBRARY}_includes ${HEADER}) endforeach() -endfunction() + set(${LIBRARY}_includes "${${LIBRARY}_includes}" PARENT_SCOPE) +endmacro() diff --git a/CMakeLists.txt b/CMakeLists.txt index 171e2469..c476f76d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,9 +43,9 @@ if(NOT BUILD_DOCSONLY) memtouch ) + add_subdirectory(include) add_subdirectory(src) add_subdirectory(contrib) - add_subdirectory(include) add_subdirectory(support) # tests need c++17 support diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index bc3dadc5..a385e03c 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,5 +1,9 @@ add_subdirectory(libhashkit-1.0) +set(libhashkit_includes "${libhashkit_includes}" PARENT_SCOPE) add_subdirectory(libmemcached-1.0) +set(libmemcached_includes "${libmemcached_includes}" PARENT_SCOPE) add_subdirectory(libmemcachedutil-1.0) +set(libmemcachedutil_includes "${libmemcachedutil_includes}" PARENT_SCOPE) add_subdirectory(libmemcachedprotocol-0.0) +set(libmemcachedprotocol_includes "${libmemcachedprotocol_includes}" PARENT_SCOPE) diff --git a/include/libhashkit-1.0/CMakeLists.txt b/include/libhashkit-1.0/CMakeLists.txt index 24fefd57..39dabb29 100644 --- a/include/libhashkit-1.0/CMakeLists.txt +++ b/include/libhashkit-1.0/CMakeLists.txt @@ -1,5 +1,7 @@ -install_public_headers(libhashkit-1.0 +install_public_headers( + libhashkit-1.0 + @configure.h algorithm.h basic_string.h diff --git a/src/libhashkit/CMakeLists.txt b/src/libhashkit/CMakeLists.txt index 48a9a1b9..355afabb 100644 --- a/src/libhashkit/CMakeLists.txt +++ b/src/libhashkit/CMakeLists.txt @@ -1,4 +1,4 @@ -add_library(libhashkit SHARED +set(libhashkit_sources aes.cc algorithm.cc common.h @@ -22,6 +22,7 @@ add_library(libhashkit SHARED strerror.cc string.cc ) +add_library(libhashkit SHARED) add_library(hashkit ALIAS libhashkit) set_target_properties(libhashkit PROPERTIES CXX_STANDARD ${CXX_STANDARD} @@ -56,3 +57,7 @@ install_public_headers( hashkit.h ) + +target_sources(libhashkit PRIVATE + ${libhashkit_sources} + ${libhashkit_includes}) diff --git a/src/libmemcached/CMakeLists.txt b/src/libmemcached/CMakeLists.txt index ffa1c0ad..81d84638 100644 --- a/src/libmemcached/CMakeLists.txt +++ b/src/libmemcached/CMakeLists.txt @@ -1,9 +1,8 @@ - find_package(FLEX) find_package(BISON 2.3) if("${BISON_VERSION}" VERSION_GREATER_EQUAL 3.0) - set(BISON_WARNINGS -Wno-deprecated) + set(BISON_WARNINGS -Wno-deprecated) endif() file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/csl) @@ -11,21 +10,23 @@ bison_target(CSL_PARSER csl/parser.yy ${CMAKE_CURRENT_BINARY_DIR}/csl/parser.cc DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/csl/parser.h COMPILE_FLAGS ${BISON_WARNINGS} ) -set_source_files_properties(${BISON_CSL_PARSER_OUTPUTS} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_source_files_properties(${BISON_CSL_PARSER_OUTPUTS} PROPERTIES + SKIP_UNITY_BUILD_INCLUSION ON) if(NOT HAVE_UNISTD_H) - set(FLEX_FLAGS --nounistd) + set(FLEX_FLAGS --nounistd) endif() flex_target(CSL_SCANNER csl/scanner.l ${CMAKE_CURRENT_BINARY_DIR}/csl/scanner.cc DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/csl/scanner.h COMPILE_FLAGS "${FLEX_FLAGS}" ) -set_source_files_properties(${FLEX_CSL_SCANNER_OUTPUTS} PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) +set_source_files_properties(${FLEX_CSL_SCANNER_OUTPUTS} PROPERTIES + SKIP_UNITY_BUILD_INCLUSION ON) add_flex_bison_dependency(CSL_SCANNER CSL_PARSER) -set(LIBMEMCACHED_SOURCES +set(libmemcached_sources csl/context.cc - ${BISON_CSL_PARSER_OUTPUTS} ${FLEX_CSL_SCANNER_OUTPUTS} + ${BISON_CSL_PARSER_OUTPUTS} allocators.cc analyze.cc array.cc @@ -84,8 +85,7 @@ if(W_NO_DEPRECATED_REGISTER) ) endif() -add_library(libmemcached SHARED - ${LIBMEMCACHED_SOURCES}) +add_library(libmemcached SHARED) add_library(memcached ALIAS libmemcached) set_target_properties(libmemcached PROPERTIES CXX_STANDARD ${CXX_STANDARD} @@ -139,8 +139,13 @@ install_public_headers( util.h ) -add_library(libmemcachedinternal STATIC - ${LIBMEMCACHED_SOURCES}) +target_sources(libmemcached PRIVATE + ${libmemcached_sources} + ${libmemcached_includes}) + +# TODO: do we really need this? + +add_library(libmemcachedinternal STATIC) add_library(memcachedinternal ALIAS libmemcachedinternal) set_target_properties(libmemcachedinternal PROPERTIES CXX_STANDARD ${CXX_STANDARD} LIBRARY_OUTPUT_NAME memcachedinternal) target_compile_definitions(libmemcachedinternal PRIVATE -DBUILDING_LIBMEMCACHEDINTERNAL) @@ -169,3 +174,7 @@ enable_dtrace_for(libmemcachedinternal libmemcached_probes.d dtrace_probes.h) # let libmemcached depend on libmemcachedinternal to ensure that they do not # compete for the same generated dependencies add_dependencies(libmemcached libmemcachedinternal) + +target_sources(libmemcachedinternal PRIVATE + ${libmemcached_sources} + ${libmemcached_includes}) diff --git a/src/libmemcachedprotocol/CMakeLists.txt b/src/libmemcachedprotocol/CMakeLists.txt index 91bfe36c..b28afe72 100644 --- a/src/libmemcachedprotocol/CMakeLists.txt +++ b/src/libmemcachedprotocol/CMakeLists.txt @@ -1,6 +1,6 @@ check_include(umem.h) -add_library(libmemcachedprotocol SHARED +set(libmemcachedprotocol_sources ascii_handler.c binary_handler.c cache.c @@ -9,6 +9,7 @@ add_library(libmemcachedprotocol SHARED pedantic.c ../libmemcached/byteorder.cc ) +add_library(libmemcachedprotocol SHARED) add_library(memcachedprotocol ALIAS libmemcachedprotocol) set_target_properties(libmemcachedprotocol PROPERTIES CXX_STANDARD ${CXX_STANDARD} @@ -46,3 +47,8 @@ export(EXPORT libmemcachedprotocol-targets NAMESPACE libmemcached::) install(EXPORT libmemcachedprotocol-targets NAMESPACE libmemcached:: COMPONENT dev DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + +target_sources(libmemcachedprotocol PRIVATE + ${libmemcachedprotocol_sources} + ${libmemcachedprotocol_includes} + ) diff --git a/src/libmemcachedutil/CMakeLists.txt b/src/libmemcachedutil/CMakeLists.txt index d99b065e..78e87d30 100644 --- a/src/libmemcachedutil/CMakeLists.txt +++ b/src/libmemcachedutil/CMakeLists.txt @@ -1,5 +1,4 @@ - -add_library(libmemcachedutil SHARED +set(libmemcachedutil_sources ../libmemcached/backtrace.cc common.h flush.cc @@ -7,10 +6,11 @@ add_library(libmemcachedutil SHARED ping.cc version.cc ) +add_library(libmemcachedutil SHARED) +add_library(memcachedutil ALIAS libmemcachedutil) if(CMAKE_USE_PTHREADS_INIT) target_sources(libmemcachedutil PRIVATE pool.cc) endif() -add_library(memcachedutil ALIAS libmemcachedutil) set_target_properties(libmemcachedutil PROPERTIES CXX_STANDARD ${CXX_STANDARD} LIBRARY_OUTPUT_NAME memcachedutil @@ -49,3 +49,7 @@ export(EXPORT libmemcachedutil-targets NAMESPACE libmemcached::) install(EXPORT libmemcachedutil-targets NAMESPACE libmemcached:: COMPONENT dev DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + +target_sources(libmemcachedutil PRIVATE + ${libmemcachedutil_sources} + ${libmemcachedutil_includes}) -- 2.30.2