Skip to content

Commit 50e111d

Browse files
committed
Mongoose: Export targets instead of FindMongoose.cmake
1 parent 133b1db commit 50e111d

File tree

4 files changed

+166
-146
lines changed

4 files changed

+166
-146
lines changed

Example/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,15 @@ target_link_libraries ( my_cxx_static PUBLIC ${LDL_STATIC} )
305305
include_directories ( ${LDL_INCLUDE_DIR} )
306306

307307
# mongoose:
308-
target_link_libraries ( my PRIVATE ${MONGOOSE_LIBRARIES} )
309-
target_link_libraries ( my_static PUBLIC ${MONGOSE_STATIC} )
310-
target_link_libraries ( my_cxx PRIVATE ${MONGOOSE_LIBRARIES} )
311-
target_link_libraries ( my_cxx_static PUBLIC ${MONGOSE_STATIC} )
312-
include_directories ( ${MONGOOSE_INCLUDE_DIR} )
308+
target_link_libraries ( my PRIVATE mongoose )
309+
target_link_libraries ( my_cxx PRIVATE mongoose )
310+
if ( TARGET mongoose_static )
311+
target_link_libraries ( my_static PUBLIC mongoose_static )
312+
target_link_libraries ( my_cxx_static PUBLIC mongoose_static )
313+
else ( )
314+
target_link_libraries ( my_static PUBLIC mongoose )
315+
target_link_libraries ( my_cxx_static PUBLIC mongoose )
316+
endif ( )
313317

314318
# rbio:
315319
target_link_libraries ( my PRIVATE ${RBIO_LIBRARIES} )

Mongoose/CMakeLists.txt

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,15 @@ if ( NOT NSTATIC )
187187
OUTPUT_NAME mongoose_static )
188188
endif ( )
189189

190+
target_include_directories ( mongoose_static
191+
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Include>"
192+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" )
193+
190194
if ( TARGET suitesparseconfig_static )
191195
target_link_libraries ( mongoose_static PUBLIC suitesparseconfig_static )
192196
else ( )
193197
target_link_libraries ( mongoose_static PUBLIC suitesparseconfig )
194198
endif ( )
195-
196199
endif ( )
197200

198201
# Build the Mongoose library for dynamic linking
@@ -202,6 +205,10 @@ set_target_properties ( mongoose PROPERTIES
202205
OUTPUT_NAME mongoose
203206
WINDOWS_EXPORT_ALL_SYMBOLS ON )
204207

208+
target_include_directories ( mongoose
209+
INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Include>"
210+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>" )
211+
205212
target_link_libraries ( mongoose PRIVATE suitesparseconfig )
206213
target_include_directories ( mongoose PUBLIC "$<TARGET_PROPERTY:suitesparseconfig,INTERFACE_INCLUDE_DIRECTORIES>" )
207214

@@ -225,9 +232,9 @@ set_target_properties ( mongoose_static_dbg PROPERTIES
225232
OUTPUT_NAME mongoose_dbg )
226233

227234
if ( TARGET suitesparseconfig_static )
228-
target_link_libraries ( mongoose_dbg suitesparseconfig_static )
235+
target_link_libraries ( mongoose_static_dbg suitesparseconfig_static )
229236
else ( )
230-
target_link_libraries ( mongoose_dbg suitesparseconfig )
237+
target_link_libraries ( mongoose_static_dbg suitesparseconfig )
231238
endif ( )
232239

233240
# Build the Mongoose executable
@@ -440,20 +447,43 @@ add_custom_target(userguide
440447
# Mongoose installation location
441448
#-------------------------------------------------------------------------------
442449

450+
include ( CMakePackageConfigHelpers )
451+
443452
install ( TARGETS mongoose
453+
EXPORT MongooseTargets
444454
LIBRARY DESTINATION ${SUITESPARSE_LIBDIR}
445455
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR}
446456
RUNTIME DESTINATION ${SUITESPARSE_BINDIR}
447457
PUBLIC_HEADER DESTINATION ${SUITESPARSE_INCLUDEDIR} )
448458
if ( NOT NSTATIC )
449459
install ( TARGETS mongoose_static
460+
EXPORT MongooseTargets
450461
ARCHIVE DESTINATION ${SUITESPARSE_LIBDIR} )
451462
endif ( )
452463
install ( TARGETS mongoose_exe
453464
RUNTIME DESTINATION ${SUITESPARSE_BINDIR} )
454-
install ( FILES ${CMAKE_SOURCE_DIR}/cmake_modules/FindMongoose.cmake
455-
DESTINATION ${SUITESPARSE_LIBDIR}/cmake/SuiteSparse
456-
COMPONENT Development )
465+
466+
# create (temporary) export target file during build
467+
export ( EXPORT MongooseTargets
468+
FILE ${CMAKE_CURRENT_BINARY_DIR}/MongooseTargets.cmake )
469+
470+
# install export target, config and version files for find_package
471+
install ( EXPORT MongooseTargets
472+
DESTINATION ${SUITESPARSE_LIBDIR}/cmake/Mongoose )
473+
474+
configure_package_config_file (
475+
Config/MongooseConfig.cmake.in
476+
${CMAKE_CURRENT_BINARY_DIR}/MongooseConfig.cmake
477+
INSTALL_DESTINATION ${SUITESPARSE_LIBDIR}/cmake/Mongoose )
478+
479+
write_basic_package_version_file (
480+
${CMAKE_CURRENT_BINARY_DIR}/MongooseConfigVersion.cmake
481+
COMPATIBILITY SameMajorVersion )
482+
483+
install ( FILES
484+
${CMAKE_CURRENT_BINARY_DIR}/MongooseConfig.cmake
485+
${CMAKE_CURRENT_BINARY_DIR}/MongooseConfigVersion.cmake
486+
DESTINATION ${SUITESPARSE_LIBDIR}/cmake/Mongoose )
457487

458488
#-------------------------------------------------------------------------------
459489
# report status
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#-------------------------------------------------------------------------------
2+
# SuiteSparse/Mongoose/cmake_modules/MongooseConfig.cmake
3+
#-------------------------------------------------------------------------------
4+
5+
# The following copyright and license applies to just this file only, not to
6+
# the library itself:
7+
# MongooseConfig.cmake, Copyright (c) 2023, Timothy A. Davis. All Rights Reserved.
8+
# SPDX-License-Identifier: BSD-3-clause
9+
10+
#-------------------------------------------------------------------------------
11+
12+
# Finds the Mongoose include file and compiled library.
13+
# The following targets are defined:
14+
# mongoose - for the shared library (if available)
15+
# mongoose_static - for the static library (if available)
16+
17+
# For backward compatibility the following variables are set:
18+
19+
# MONGOOSE_INCLUDE_DIR - where to find Mongoose.hpp
20+
# MONGOOSE_LIBRARY - dynamic Mongoose library
21+
# MONGOOSE_STATIC - static Mongoose library
22+
# MONGOOSE_LIBRARIES - libraries when using Mongoose
23+
# MONGOOSE_FOUND - true if Mongoose found
24+
25+
# Set ``CMAKE_MODULE_PATH`` to the parent folder where this module file is
26+
# installed.
27+
28+
#-------------------------------------------------------------------------------
29+
30+
@PACKAGE_INIT@
31+
32+
set ( MONGOOSE_DATE "@Mongoose_DATE@" )
33+
set ( MONGOOSE_VERSION_MAJOR @Mongoose_VERSION_MAJOR@ )
34+
set ( MONGOOSE_VERSION_MINOR @Mongoose_VERSION_MINOR@ )
35+
set ( MONGOOSE_VERSION_PATCH @Mongoose_VERSION_PATCH@ )
36+
set ( MONGOOSE_VERSION "@Mongoose_VERSION_MAJOR@.@Mongoose_VERSION_MINOR@.@Mongoose_VERSION_PATCH@" )
37+
38+
include ( ${CMAKE_CURRENT_LIST_DIR}/MongooseTargets.cmake )
39+
40+
# The following is only for backward compatibility with FindMongoose.
41+
42+
set ( _target_shared mongoose )
43+
set ( _target_static mongoose_static )
44+
set ( _var_prefix "MONGOOSE" )
45+
46+
get_target_property ( ${_var_prefix}_INCLUDE_DIR ${_target_shared} INTERFACE_INCLUDE_DIRECTORIES )
47+
if ( ${_var_prefix}_INCLUDE_DIR )
48+
# First item in SuiteSparse targets contains the "main" header directory.
49+
list ( GET ${_var_prefix}_INCLUDE_DIR 0 ${_var_prefix}_INCLUDE_DIR )
50+
endif ( )
51+
get_target_property ( ${_var_prefix}_LIBRARY ${_target_shared} IMPORTED_IMPLIB )
52+
if ( NOT ${_var_prefix}_LIBRARY )
53+
get_target_property ( _library_chk ${_target_shared} IMPORTED_LOCATION )
54+
if ( EXISTS ${_library_chk} )
55+
set ( ${_var_prefix}_LIBRARY ${_library_chk} )
56+
endif ( )
57+
endif ( )
58+
if ( TARGET ${_target_static} )
59+
get_target_property ( ${_var_prefix}_STATIC ${_target_static} IMPORTED_LOCATION )
60+
endif ( )
61+
62+
# Check for most common build types
63+
set ( _config_types "Debug" "Release" "RelWithDebInfo" "MinSizeRel" )
64+
65+
get_property ( _isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
66+
if ( _isMultiConfig )
67+
# For multi-configuration generators (e.g., Visual Studio), prefer those
68+
# configurations.
69+
list ( PREPEND _config_types ${CMAKE_CONFIGURATION_TYPES} )
70+
else ( )
71+
# For single-configuration generators, prefer the current configuration.
72+
list ( PREPEND _config_types ${CMAKE_BUILD_TYPE} )
73+
endif ( )
74+
75+
list ( REMOVE_DUPLICATES _config_types )
76+
77+
foreach ( _config ${_config_types} )
78+
string ( TOUPPER ${_config} _uc_config )
79+
if ( NOT ${_var_prefix}_LIBRARY )
80+
get_target_property ( _library_chk ${_target_shared}
81+
IMPORTED_IMPLIB_${_uc_config} )
82+
if ( EXISTS ${_library_chk} )
83+
set ( ${_var_prefix}_LIBRARY ${_library_chk} )
84+
endif ( )
85+
endif ( )
86+
if ( NOT ${_var_prefix}_LIBRARY )
87+
get_target_property ( _library_chk ${_target_shared}
88+
IMPORTED_LOCATION_${_uc_config} )
89+
if ( EXISTS ${_library_chk} )
90+
set ( ${_var_prefix}_LIBRARY ${_library_chk} )
91+
endif ( )
92+
endif ( )
93+
if ( TARGET ${_target_static} AND NOT ${_var_prefix}_STATIC )
94+
get_target_property ( _library_chk ${_target_static}
95+
IMPORTED_LOCATION_${_uc_config} )
96+
if ( EXISTS ${_library_chk} )
97+
set ( ${_var_prefix}_STATIC ${_library_chk} )
98+
endif ( )
99+
endif ( )
100+
endforeach ( )
101+
102+
set ( MONGOOSE_LIBRARIES ${MONGOOSE_LIBRARY} )
103+
104+
macro ( suitesparse_check_exist _var _files )
105+
# ignore generator expressions
106+
string ( GENEX_STRIP "${_files}" _files2 )
107+
108+
foreach ( _file ${_files2} )
109+
if ( NOT EXISTS "${_file}" )
110+
message ( FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist!" )
111+
endif ( )
112+
endforeach ()
113+
endmacro ( )
114+
115+
suitesparse_check_exist ( MONGOOSE_INCLUDE_DIR ${MONGOOSE_INCLUDE_DIR} )
116+
suitesparse_check_exist ( MONGOOSE_LIBRARY ${MONGOOSE_LIBRARY} )
117+
118+
message ( STATUS "Mongoose version: ${MONGOOSE_VERSION}" )
119+
message ( STATUS "Mongoose include: ${MONGOOSE_INCLUDE_DIR}" )
120+
message ( STATUS "Mongoose library: ${MONGOOSE_LIBRARY}" )
121+
message ( STATUS "Mongoose static: ${MONGOOSE_STATIC}" )

Mongoose/cmake_modules/FindMongoose.cmake

Lines changed: 0 additions & 135 deletions
This file was deleted.

0 commit comments

Comments
 (0)