Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7336da1

Browse filesBrowse files
committed
make FindCairo.cmake export an IMPORTED target
FindCairo.cmake will now create an 'IMPORTED' CMake target, with build settings assigned to it via CMake target-properties. This change also, somewhat inadvertently, fixes a bug whereby vcpkg wasn't installing Cairo's .dll file alongside Debug-built .exe files, as the Release/non-Debug version of Cairo was getting linked to. vcpkg adds a post-link step to executables to install these .dll files. Debug-built io2d apps were linking to the Release copy of Cairo, which was confusing vcpkg. In more detail, this involved a vcpkg script, "<vcpkg-root>\scripts\buildsystems\msbuild\applocal.ps1", only looking in "<vcpkg-root>\debug\bin\" for .dll files to copy, as opposed to either "<vcpkg-root>\debug\bin\" or "<vcpkg-root>\bin\".
1 parent 9dc5834 commit 7336da1
Copy full SHA for 7336da1

File tree

Expand file treeCollapse file tree

2 files changed

+84
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+84
-3
lines changed

‎P0267_RefImpl/P0267_RefImpl/cairo/CMakeLists.txt

Copy file name to clipboardExpand all lines: P0267_RefImpl/P0267_RefImpl/cairo/CMakeLists.txt
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ target_include_directories(io2d_cairo PUBLIC
2323

2424
target_compile_features(io2d_cairo PUBLIC cxx_std_17)
2525

26-
target_link_libraries(io2d_cairo PUBLIC io2d_core)
26+
target_link_libraries(io2d_cairo PUBLIC io2d_core Cairo::Cairo)
2727

2828
if(MSVC)
2929
find_path(GRAPHICSMAGICK_INCLUDE_DIR magick/api.h)
@@ -36,9 +36,9 @@ else() # Linux
3636
find_library(GRAPHICSMAGICK_LIB GraphicsMagick)
3737
endif()
3838

39-
target_include_directories(io2d_cairo SYSTEM PUBLIC ${CAIRO_INCLUDE_DIRS} ${GRAPHICSMAGICK_INCLUDE_DIR})
39+
target_include_directories(io2d_cairo SYSTEM PUBLIC ${GRAPHICSMAGICK_INCLUDE_DIR})
4040

41-
target_link_libraries(io2d_cairo PUBLIC ${CAIRO_LIBRARIES} ${GRAPHICSMAGICK_LIB})
41+
target_link_libraries(io2d_cairo PUBLIC ${GRAPHICSMAGICK_LIB})
4242

4343

4444
install(

‎cmake/FindCairo.cmake

Copy file name to clipboardExpand all lines: cmake/FindCairo.cmake
+81Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,39 @@ find_library(CAIRO_LIBRARIES
4343
HINTS ${PC_CAIRO_LIBDIR}
4444
${PC_CAIRO_LIBRARY_DIRS}
4545
)
46+
find_library(CAIRO_LIBRARIES_DEBUG
47+
NAMES cairod
48+
HINTS ${PC_CAIRO_LIBDIR}
49+
${PC_CAIRO_LIBRARY_DIRS}
50+
)
51+
52+
if (CAIRO_INCLUDE_DIRS)
53+
set(_CAIRO_PATH ${CAIRO_INCLUDE_DIRS})
54+
while(TRUE)
55+
get_filename_component(_CAIRO_PATH_PART ${_CAIRO_PATH} NAME)
56+
string(TOLOWER ${_CAIRO_PATH_PART} _CAIRO_PATH_PART)
57+
if (${_CAIRO_PATH_PART} STREQUAL "cairo" OR ${_CAIRO_PATH_PART} STREQUAL "include")
58+
get_filename_component(_CAIRO_PATH ${_CAIRO_PATH} DIRECTORY)
59+
continue()
60+
endif()
61+
if (NOT (${_CAIRO_PATH} STREQUAL ""))
62+
set(CAIRO_PATH ${_CAIRO_PATH})
63+
set(CAIRO_PATH ${CAIRO_PATH} PARENT_SCOPE)
64+
endif()
65+
break()
66+
endwhile()
67+
endif()
68+
69+
find_file(CAIRO_DLL
70+
NAMES cairo.dll
71+
HINTS ${CAIRO_PATH}
72+
PATH_SUFFIXES bin
73+
)
74+
find_file(CAIRO_DLL_DEBUG
75+
NAMES cairod.dll
76+
HINTS ${CAIRO_PATH}
77+
PATH_SUFFIXES debug/bin
78+
)
4679

4780
if (CAIRO_INCLUDE_DIRS)
4881
if (EXISTS "${CAIRO_INCLUDE_DIRS}/cairo-version.h")
@@ -72,4 +105,52 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(Cairo REQUIRED_VARS CAIRO_INCLUDE_DIRS CAIRO_L
72105
mark_as_advanced(
73106
CAIRO_INCLUDE_DIRS
74107
CAIRO_LIBRARIES
108+
CAIRO_LIBRARIES_DEBUG
75109
)
110+
111+
# Create CMake targets
112+
if (CAIRO_FOUND AND NOT TARGET Cairo::Cairo)
113+
if (CAIRO_DLL)
114+
# Not using 'SHARED' when Cairo is available through a .dll can
115+
# cause build issues with MSVC, at least when trying to link against
116+
# a vcpkg-provided copy of "cairod".
117+
add_library(Cairo::Cairo SHARED IMPORTED)
118+
else()
119+
add_library(Cairo::Cairo UNKNOWN IMPORTED)
120+
endif()
121+
122+
set_target_properties(Cairo::Cairo PROPERTIES
123+
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
124+
INTERFACE_INCLUDE_DIRECTORIES ${CAIRO_INCLUDE_DIRS}
125+
)
126+
127+
if(CAIRO_DLL)
128+
# When using a .dll, the location of *both( the .dll file, and its .lib,
129+
# needs to be specified to CMake. The path to the .dll goes into
130+
# IMPORTED_LOCATION(_*), whereas the path to the .lib goes into
131+
# IMPORTED_IMPLIB(_*).
132+
set_target_properties(Cairo::Cairo PROPERTIES
133+
IMPORTED_LOCATION ${CAIRO_DLL}
134+
IMPORTED_IMPLIB ${CAIRO_LIBRARIES}
135+
)
136+
if (CAIRO_DLL_DEBUG)
137+
set_target_properties(Cairo::Cairo PROPERTIES
138+
IMPORTED_LOCATION_DEBUG ${CAIRO_DLL_DEBUG}
139+
)
140+
endif()
141+
if (CAIRO_LIBRARIES_DEBUG)
142+
set_target_properties(Cairo::Cairo PROPERTIES
143+
IMPORTED_IMPLIB_DEBUG ${CAIRO_LIBRARIES_DEBUG}
144+
)
145+
endif()
146+
else()
147+
set_target_properties(Cairo::Cairo PROPERTIES
148+
IMPORTED_LOCATION ${CAIRO_LIBRARIES}
149+
)
150+
if (CAIRO_LIBRARIES_DEBUG)
151+
set_target_properties(Cairo::Cairo PROPERTIES
152+
IMPORTED_LOCATION_DEBUG ${CAIRO_LIBRARIES_DEBUG}
153+
)
154+
endif()
155+
endif()
156+
endif()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.