Skip to content

Commit 7621d26

Browse files
committed
export wepoll when fetched
1 parent 1fdf980 commit 7621d26

2 files changed

Lines changed: 49 additions & 18 deletions

File tree

CMakeLists.txt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,21 @@ if(WIN32)
4040

4141
# Build wepoll as a static library
4242
add_library(wepoll_lib STATIC ${wepoll_SOURCE_DIR}/wepoll.c)
43-
target_include_directories(wepoll_lib PUBLIC ${wepoll_SOURCE_DIR})
43+
target_include_directories(wepoll_lib PUBLIC
44+
$<BUILD_INTERFACE:${wepoll_SOURCE_DIR}>
45+
$<INSTALL_INTERFACE:include>
46+
)
47+
48+
# Set export properties
49+
set_target_properties(wepoll_lib PROPERTIES EXPORT_NAME wepoll)
4450

4551
# Create the wepoll::wepoll target
4652
add_library(wepoll::wepoll ALIAS wepoll_lib)
4753

4854
message(STATUS "wepoll: fetched and built from GitHub")
55+
56+
# Mark that we need to install wepoll
57+
set(SLICK_SOCKET_INSTALL_WEPOLL TRUE)
4958
endif()
5059
endif()
5160

@@ -129,10 +138,26 @@ endif()
129138
# Install headers
130139
install(DIRECTORY include/ DESTINATION include)
131140

141+
# Install wepoll headers if we fetched it
142+
if(SLICK_SOCKET_INSTALL_WEPOLL)
143+
install(FILES ${wepoll_SOURCE_DIR}/wepoll.h DESTINATION include)
144+
endif()
145+
132146
# Install library targets (header-only INTERFACE library)
133-
install(TARGETS slick-socket
134-
EXPORT slick-socketTargets
135-
)
147+
if(SLICK_SOCKET_INSTALL_WEPOLL)
148+
# Install both slick-socket and wepoll_lib
149+
install(TARGETS slick-socket wepoll_lib
150+
EXPORT slick-socketTargets
151+
ARCHIVE DESTINATION lib
152+
LIBRARY DESTINATION lib
153+
RUNTIME DESTINATION bin
154+
)
155+
else()
156+
# Install only slick-socket (wepoll is external)
157+
install(TARGETS slick-socket
158+
EXPORT slick-socketTargets
159+
)
160+
endif()
136161

137162
# Install CMake package configuration files
138163
include(CMakePackageConfigHelpers)

cmake/slick-socketConfig.cmake.in

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,35 @@
55

66
include(CMakeFindDependencyMacro)
77

8+
# Include the targets file (this provides slick::socket and possibly slick::wepoll)
9+
include("${CMAKE_CURRENT_LIST_DIR}/slick-socketTargets.cmake")
10+
811
# Platform-specific dependencies
912
if(WIN32)
1013
# Windows requires wepoll for epoll-like functionality
11-
# Check if wepoll::wepoll target already exists (from parent project)
14+
# Check if wepoll::wepoll target already exists (from parent project or our export)
1215
if(NOT TARGET wepoll::wepoll)
13-
# Find wepoll manually (vcpkg installations don't provide CMake config)
14-
find_path(WEPOLL_INCLUDE_DIR wepoll.h REQUIRED)
15-
find_library(WEPOLL_LIBRARY NAMES wepoll REQUIRED)
16+
# Check if we installed wepoll as part of slick-socket
17+
if(TARGET slick::wepoll)
18+
# Use the bundled wepoll that was fetched during build
19+
add_library(wepoll::wepoll ALIAS slick::wepoll)
20+
else()
21+
# Find wepoll manually (vcpkg installations don't provide CMake config)
22+
find_path(WEPOLL_INCLUDE_DIR wepoll.h REQUIRED)
23+
find_library(WEPOLL_LIBRARY NAMES wepoll REQUIRED)
1624

17-
if(WEPOLL_INCLUDE_DIR AND WEPOLL_LIBRARY)
18-
# Create an imported target for wepoll
19-
add_library(wepoll::wepoll STATIC IMPORTED)
20-
set_target_properties(wepoll::wepoll PROPERTIES
21-
IMPORTED_LOCATION "${WEPOLL_LIBRARY}"
22-
INTERFACE_INCLUDE_DIRECTORIES "${WEPOLL_INCLUDE_DIR}"
23-
)
25+
if(WEPOLL_INCLUDE_DIR AND WEPOLL_LIBRARY)
26+
# Create an imported target for wepoll
27+
add_library(wepoll::wepoll STATIC IMPORTED)
28+
set_target_properties(wepoll::wepoll PROPERTIES
29+
IMPORTED_LOCATION "${WEPOLL_LIBRARY}"
30+
INTERFACE_INCLUDE_DIRECTORIES "${WEPOLL_INCLUDE_DIR}"
31+
)
32+
endif()
2433
endif()
2534
endif()
2635
endif()
2736

28-
# Include the targets file
29-
include("${CMAKE_CURRENT_LIST_DIR}/slick-socketTargets.cmake")
30-
3137
# Set package variables
3238
set(slick-socket_VERSION @PROJECT_VERSION@)
3339
set(slick-socket_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)

0 commit comments

Comments
 (0)