@@ -108,31 +108,35 @@ macro (sharg_config_error text)
108108 endif ()
109109endmacro ()
110110
111+ # ----------------------------------------------------------------------------
112+ # CPM
113+ # ----------------------------------------------------------------------------
114+
115+ # This will be true for git clones and source packages, but not for installed packages.
116+ if (EXISTS "${CMAKE_CURRENT_LIST_DIR} /CPM.cmake" )
117+ set (SHARG_HAS_CPM TRUE )
118+ else ()
119+ set (SHARG_HAS_CPM FALSE )
120+ endif ()
121+
122+ if (SHARG_HAS_CPM)
123+ set (CPM_INDENT " CMake Package Manager CPM: " )
124+ include ("${CMAKE_CURRENT_LIST_DIR} /CPM.cmake" )
125+ CPMUsePackageLock ("${CMAKE_CURRENT_LIST_DIR} /package-lock.cmake" )
126+ endif ()
127+
111128# ----------------------------------------------------------------------------
112129# Find SHARG include path
113130# ----------------------------------------------------------------------------
114131
115132# Note that sharg-config.cmake can be standalone and thus SHARG_CLONE_DIR might be empty.
116- # * `SHARG_CLONE_DIR` was already found in sharg-config-version.cmake
117133# * `SHARG_INCLUDE_DIR` was already found in sharg-config-version.cmake
118- find_path (SHARG_SUBMODULES_DIR
119- NAMES submodules/tool_description_lib
120- HINTS "${SHARG_CLONE_DIR} " "${SHARG_INCLUDE_DIR} /sharg" )
121-
122134if (SHARG_INCLUDE_DIR)
123135 sharg_config_print ("SHARG include dir found: ${SHARG_INCLUDE_DIR} " )
124136else ()
125137 sharg_config_error ("SHARG include directory could not be found (SHARG_INCLUDE_DIR: '${SHARG_INCLUDE_DIR} ')" )
126138endif ()
127139
128- # ----------------------------------------------------------------------------
129- # Detect if we are a clone of repository and if yes auto-add submodules
130- # ----------------------------------------------------------------------------
131-
132- if (SHARG_CLONE_DIR)
133- sharg_config_print ("Detected as running from a repository checkout…" )
134- endif ()
135-
136140# ----------------------------------------------------------------------------
137141# Options for CheckCXXSourceCompiles
138142# ----------------------------------------------------------------------------
@@ -206,22 +210,13 @@ endif ()
206210set (SHARG_USE_TDL FALSE )
207211
208212if (NOT SHARG_NO_TDL)
209- find_package (TDL QUIET HINTS ${SHARG_HINT_TDL} )
210-
211- if (NOT TDL_FOUND)
212- if (EXISTS ${SHARG_SUBMODULES_DIR} /submodules/tool_description_lib)
213- include (FetchContent)
214- FetchContent_Declare (tdl SOURCE_DIR ${SHARG_SUBMODULES_DIR} /submodules/tool_description_lib)
215- set (SHARG_LOG_LEVEL ${CMAKE_MESSAGE_LOG_LEVEL} )
216- set (CMAKE_MESSAGE_LOG_LEVEL "ERROR" )
217- option (INSTALL_TDL "Enable installation of TDL." ${INSTALL_SHARG} )
218- FetchContent_MakeAvailable (tdl)
219- set (CMAKE_MESSAGE_LOG_LEVEL ${SHARG_LOG_LEVEL} )
220- set (TDL_FOUND TRUE )
221- endif ()
213+ if (NOT SHARG_HAS_CPM)
214+ find_package (tdl QUIET )
215+ else ()
216+ CPMGetPackage (tdl)
222217 endif ()
223218
224- if (TDL_FOUND)
219+ if (TDL_FOUND OR tdl_ADDED )
225220 sharg_config_print ("Optional dependency: TDL found." )
226221 set (SHARG_USE_TDL TRUE )
227222 list (APPEND SHARG_LIBRARIES tdl::tdl)
@@ -323,12 +318,6 @@ if (SHARG_FOUND AND NOT TARGET sharg::sharg)
323318 target_link_libraries (sharg_sharg INTERFACE ${SHARG_LIBRARIES} )
324319 target_include_directories (sharg_sharg INTERFACE "${SHARG_INCLUDE_DIR} " )
325320 add_library (sharg::sharg ALIAS sharg_sharg)
326-
327- if (SHARG_USE_TDL)
328- # Include TDL as system header to suppress warnings.
329- get_target_property (tdl_include_dir tdl::tdl INTERFACE_INCLUDE_DIRECTORIES )
330- target_include_directories (sharg_sharg SYSTEM INTERFACE ${tdl_include_dir} )
331- endif ()
332321endif ()
333322
334323set (CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE} )
0 commit comments