Skip to content

Commit

Permalink
[all] Externalize cxxopts (#4273)
Browse files Browse the repository at this point in the history
* Add possibility to use external package of cxxopts before trying fetch

* add a cmake option to allow or disable the fetching of dependencies

* List fetchable dependencies in cmake option comments.

* Apply suggestions from code review

Co-authored-by: erik pernod <[email protected]>

---------

Co-authored-by: erik pernod <[email protected]>
  • Loading branch information
olivier-roussel and epernod authored Nov 5, 2023
1 parent 3b40567 commit 22d783b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${LIBRARY_OUTPUT_DIRECTOR
# Option for packaging
option(SOFA_BUILD_RELEASE_PACKAGE "Run package specific configure" OFF)

# Option to allow some dependencies such as cxxopts to be fetched by cmake if
# the package is not found
option(SOFA_ALLOW_FETCH_DEPENDENCIES "Allow compatible dependencies to be fetched if the package is not found by cmake.
List of dependencies that can be fetched: cxxopts" ON)

# Option to accelerate the compilation
# see https://cmake.org/cmake/help/v3.16/command/target_precompile_headers.html
# and https://cmake.org/cmake/help/v3.16/prop_tgt/DISABLE_PRECOMPILE_HEADERS.html
Expand Down
29 changes: 16 additions & 13 deletions Sofa/GUI/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
cmake_minimum_required(VERSION 3.12)
project(Sofa.GUI.Common LANGUAGES CXX)

include(FetchContent)
FetchContent_Declare(cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts
GIT_TAG v3.1.1
)
find_package(cxxopts 3.1)
if(NOT cxxopts_FOUND AND SOFA_ALLOW_FETCH_DEPENDENCIES)
include(FetchContent)
FetchContent_Declare(cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts
GIT_TAG v3.1.1
)

FetchContent_GetProperties(cxxopts)
if(NOT cxxopts_POPULATED)
FetchContent_Populate(cxxopts)
FetchContent_GetProperties(cxxopts)
if(NOT cxxopts_POPULATED)
FetchContent_Populate(cxxopts)

set(CXXOPTS_BUILD_EXAMPLES OFF CACHE INTERNAL "")
set(CXXOPTS_BUILD_TESTS OFF CACHE INTERNAL "")
set(CXXOPTS_ENABLE_INSTALL ON CACHE INTERNAL "")
set(CXXOPTS_BUILD_EXAMPLES OFF CACHE INTERNAL "")
set(CXXOPTS_BUILD_TESTS OFF CACHE INTERNAL "")
set(CXXOPTS_ENABLE_INSTALL ON CACHE INTERNAL "")

add_subdirectory(${cxxopts_SOURCE_DIR} ${cxxopts_BINARY_DIR})
add_subdirectory(${cxxopts_SOURCE_DIR} ${cxxopts_BINARY_DIR})
endif()
endif()

set(SOFAGUICOMMON_ROOT src/sofa/gui/common)
Expand Down Expand Up @@ -84,7 +87,7 @@ target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Simulation.Common)
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Component.Setting)
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.Component.Collision.Response.Contact)
target_link_libraries(${PROJECT_NAME} PUBLIC Sofa.GUI.Component)
target_link_libraries(${PROJECT_NAME} PUBLIC cxxopts)
target_link_libraries(${PROJECT_NAME} PUBLIC cxxopts::cxxopts)

target_include_directories(${PROJECT_NAME} PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${COMPATSOFAGUICOMMON_ROOT}>")
target_include_directories(${PROJECT_NAME} PUBLIC "$<INSTALL_INTERFACE:include/${PROJECT_NAME}/${PROJECT_NAME}/compat>")
Expand Down

0 comments on commit 22d783b

Please sign in to comment.