Skip to content

Commit

Permalink
feat(lib): Update how includes are installed and handle non-standard …
Browse files Browse the repository at this point in the history
…externals better (#339)

* feat(lib): Update how includes are installed and handle non-standard externals better

* further cleanup into reusable functions
  • Loading branch information
finger563 authored Oct 25, 2024
1 parent 58a8c25 commit d1e1942
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
24 changes: 6 additions & 18 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)
35 changes: 32 additions & 3 deletions lib/espp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()

0 comments on commit d1e1942

Please sign in to comment.