1
- cmake_minimum_required (VERSION 3.0.0 )
1
+ cmake_minimum_required (VERSION 3.8 )
2
2
project (io2d CXX)
3
- set (CMAKE_CXX_STANDARD 17)
4
3
5
4
# If there's no default backend we try to set it automatically
6
5
if ( NOT DEFINED IO2D_DEFAULT )
@@ -24,7 +23,11 @@ if( NOT DEFINED IO2D_ENABLED )
24
23
set (IO2D_ENABLED ${IO2D_DEFAULT} )
25
24
endif ()
26
25
27
- add_library (io2d
26
+ # Core library
27
+ # io2d_core contains backend-independent files. It is used by backends. You
28
+ # shouldn't directly link to this library.
29
+
30
+ add_library (io2d_core
28
31
rgba_color.cpp
29
32
xio2d.h
30
33
xbrushes.h
@@ -50,24 +53,53 @@ add_library(io2d
50
53
xinterchangebuffer.h
51
54
)
52
55
53
- target_include_directories (io2d PUBLIC
54
- ${CMAKE_CURRENT_SOURCE_DIR}
56
+ target_include_directories (io2d_core PUBLIC
57
+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} >
58
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
59
+ )
60
+
61
+ target_compile_features (io2d_core PUBLIC cxx_std_17)
62
+
63
+ install (
64
+ TARGETS io2d_core EXPORT io2d_targets
65
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
66
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
67
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
68
+ )
69
+
70
+ file (
71
+ GLOB IO2D_CORE_HEADERS
72
+ "${CMAKE_CURRENT_SOURCE_DIR} /*.h"
55
73
)
56
74
75
+ install (
76
+ FILES ${IO2D_CORE_HEADERS}
77
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
78
+ )
79
+
80
+ # User facing library
81
+ # io2d is a user facing interface library that depends on all enabled backends
82
+ # Usually, you want to link only to this library.
83
+
84
+ add_library (io2d INTERFACE )
57
85
58
86
# function that maps a backend name into it's path and library name
59
87
function (GET_BACKEND_INFO backend_name)
60
88
if ( ${backend_name} STREQUAL "COREGRAPHICS_MAC" )
61
- set (BACKEND_PATH coregraphics/mac PARENT_SCOPE)
89
+ set (BACKEND_PATH1 coregraphics PARENT_SCOPE)
90
+ set (BACKEND_PATH2 coregraphics/mac PARENT_SCOPE)
62
91
set (BACKEND_LIBRARY io2d_coregraphics_mac PARENT_SCOPE)
63
92
elseif ( ${backend_name} STREQUAL "COREGRAPHICS_IOS" )
64
- set (BACKEND_PATH coregraphics/ios PARENT_SCOPE)
93
+ set (BACKEND_PATH1 coregraphics PARENT_SCOPE)
94
+ set (BACKEND_PATH2 coregraphics/ios PARENT_SCOPE)
65
95
set (BACKEND_LIBRARY io2d_coregraphics_ios PARENT_SCOPE)
66
96
elseif ( ${backend_name} STREQUAL "CAIRO_XLIB" )
67
- set (BACKEND_PATH cairo/xlib PARENT_SCOPE)
97
+ set (BACKEND_PATH1 cairo PARENT_SCOPE)
98
+ set (BACKEND_PATH2 cairo/xlib PARENT_SCOPE)
68
99
set (BACKEND_LIBRARY io2d_cairo_xlib PARENT_SCOPE)
69
100
elseif ( ${backend_name} STREQUAL "CAIRO_WIN32" )
70
- set (BACKEND_PATH cairo/win32 PARENT_SCOPE)
101
+ set (BACKEND_PATH1 cairo PARENT_SCOPE)
102
+ set (BACKEND_PATH2 cairo/win32 PARENT_SCOPE)
71
103
set (BACKEND_LIBRARY io2d_cairo_win32 PARENT_SCOPE)
72
104
else ()
73
105
message ( FATAL_ERROR "GET_BACKEND_INFO: unknown backend name" )
@@ -77,31 +109,18 @@ endfunction(GET_BACKEND_INFO)
77
109
# fetch info about the default backend
78
110
GET_BACKEND_INFO(${IO2D_DEFAULT} )
79
111
80
- # add a search path depending on a default backend setting
81
- target_include_directories (io2d PUBLIC
82
- ${CMAKE_CURRENT_SOURCE_DIR} /${BACKEND_PATH}
83
- )
84
-
85
112
# add backends themselves
86
113
foreach (backend ${IO2D_ENABLED} )
87
114
GET_BACKEND_INFO(${backend} )
88
- add_subdirectory (${BACKEND_PATH} )
89
- target_link_libraries (io2d ${BACKEND_LIBRARY} )
115
+ add_subdirectory (${BACKEND_PATH1} )
116
+ add_subdirectory (${BACKEND_PATH2} )
117
+ target_link_libraries (io2d INTERFACE ${BACKEND_LIBRARY} )
90
118
endforeach (backend)
91
119
92
- # installation
93
- install (
94
- TARGETS io2d
95
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
96
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
97
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
98
- )
99
- file (
100
- GLOB IO2D_HEADERS
101
- "${CMAKE_CURRENT_SOURCE_DIR} /*.h"
102
- )
120
+ install (TARGETS io2d EXPORT io2d_targets)
103
121
104
- install (
105
- FILES ${IO2D_HEADERS}
106
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
122
+ install (EXPORT io2d_targets
123
+ FILE io2dConfig.cmake
124
+ NAMESPACE io2d::
125
+ DESTINATION lib/cmake/io2d
107
126
)
0 commit comments