From d1e1942154655d715942303ce368c77d37f772c8 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Fri, 25 Oct 2024 09:45:44 -0500 Subject: [PATCH] feat(lib): Update how includes are installed and handle non-standard externals better (#339) * feat(lib): Update how includes are installed and handle non-standard externals better * further cleanup into reusable functions --- lib/CMakeLists.txt | 24 ++++++------------------ lib/espp.cmake | 35 ++++++++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index e3e5907c5..1c6797560 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_COLOR_MAKEFILE ON) include(espp.cmake) -include_directories(${ESPP_INCLUDES}) +include_directories(${ESPP_INCLUDE_DIRS}) set(LINK_ARG "--whole-archive") @@ -41,22 +41,10 @@ target_compile_features(${TARGET_NAME} PRIVATE cxx_std_20) # install build output and headers install(TARGETS ${TARGET_NAME} ARCHIVE DESTINATION ${PROJECT_SOURCE_DIR}/pc) -install(DIRECTORY ${ESPP_INCLUDES} DESTINATION ${PROJECT_SOURCE_DIR}/pc/) -# we have to make sure to install the magic_enum includes differently, since they're in different folders -install(DIRECTORY ${ESPP_EXTERNAL}/magic_enum/include/magic_enum/ DESTINATION ${PROJECT_SOURCE_DIR}/pc/include/) -# and we need to include the pybind11 library -add_subdirectory(pybind11) +espp_install_includes(${PROJECT_SOURCE_DIR}/pc) -# NOTE: this is an alternate WIP way -# python_add_library(_core MODULE -# ./python_bindings/module.cpp ./python_bindings/pybind_espp.cpp ${ESPP_SOURCES} WITH_SOABI) -# target_link_libraries(_core PRIVATE pybind11::headers) -# install(TARGETS _core DESTINATION ${PROJECT_SOURCE_DIR}/pc/) - -# Python binding -pybind11_add_module(espp ${ESPP_PYTHON_SOURCES}) -target_compile_features(espp PRIVATE cxx_std_20) -target_link_libraries(espp PRIVATE ${ESPP_EXTERNAL_LIBS}) -install(TARGETS espp - LIBRARY DESTINATION ${PROJECT_SOURCE_DIR}/pc/) +# Build and install the python binding, which is built using pybind11, so we +# need to include the pybind11 library +add_subdirectory(pybind11) +espp_install_python_module(${PROJECT_SOURCE_DIR}/pc) diff --git a/lib/espp.cmake b/lib/espp.cmake index 56f98e05f..776b13724 100644 --- a/lib/espp.cmake +++ b/lib/espp.cmake @@ -5,14 +5,19 @@ set(ESPP_EXTERNAL_INCLUDES ${ESPP_EXTERNAL}/alpaca/include ${ESPP_EXTERNAL}/cli/include ${ESPP_EXTERNAL}/csv2/include - ${ESPP_EXTERNAL}/hid-rp/hid-rp/ ${ESPP_EXTERNAL}/fmt/include - ${ESPP_EXTERNAL}/magic_enum/include/magic_enum/ ${ESPP_EXTERNAL}/tabulate/include ) +# NOTE: these are separate because they do not follow the standard format of +# having their include files be in the "include" directory, so when we install +# them we need to handle them separately +set(ESPP_EXTERNAL_INCLUDES_SEPARATE + ${ESPP_EXTERNAL}/hid-rp/hid-rp/ + ${ESPP_EXTERNAL}/magic_enum/include/magic_enum/ +) + set(ESPP_INCLUDES - ${ESPP_EXTERNAL_INCLUDES} ${ESPP_COMPONENTS}/base_component/include ${ESPP_COMPONENTS}/base_peripheral/include ${ESPP_COMPONENTS}/color/include @@ -59,6 +64,12 @@ set(ESPP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/espp.cpp ) +set(ESPP_INCLUDE_DIRS + ${ESPP_INCLUDES} + ${ESPP_EXTERNAL_INCLUDES} + ${ESPP_EXTERNAL_INCLUDES_SEPARATE} +) + # if we're on windows, we need to add wcswidth.c to the sources if(MSVC) list(APPEND ESPP_SOURCES ${CMAKE_CURRENT_LIST_DIR}/wcswidth.c) @@ -76,3 +87,21 @@ set(ESPP_PYTHON_SOURCES ${CMAKE_CURRENT_LIST_DIR}/python_bindings/pybind_espp.cpp ${ESPP_SOURCES} ) + +# make an espp_install_includes command that can be used by other scripts, where +# they just need to specify the folder they want to install into +function(espp_install_includes FOLDER) + install(DIRECTORY ${ESPP_INCLUDES} DESTINATION ${FOLDER}/) + install(DIRECTORY ${ESPP_EXTERNAL_INCLUDES} DESTINATION ${FOLDER}/) + install(DIRECTORY ${ESPP_EXTERNAL_INCLUDES_SEPARATE} DESTINATION ${FOLDER}/include/) +endfunction() + +# make an espp_install_python_module command that can be used by other scripts, where +# they just need to specify the folder they want to install into +function(espp_install_python_module FOLDER) + pybind11_add_module(espp ${ESPP_PYTHON_SOURCES}) + target_compile_features(espp PRIVATE cxx_std_20) + target_link_libraries(espp PRIVATE ${ESPP_EXTERNAL_LIBS}) + install(TARGETS espp + LIBRARY DESTINATION ${FOLDER}/) +endfunction()