Skip to content

Commit f482028

Browse files
authored
Merge pull request #380 from myd7349/cmake
improve CMakeLists.txt
2 parents fe306fc + 3c9fd96 commit f482028

File tree

1 file changed

+42
-14
lines changed

1 file changed

+42
-14
lines changed

CMakeLists.txt

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,49 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
22

33
project(kcp LANGUAGES C)
44

55
include(CTest)
66
include(GNUInstallDirs)
77

8-
add_library(kcp STATIC ikcp.c)
9-
add_library(kcp_shared SHARED ikcp.c)
10-
11-
set_property(TARGET kcp_shared PROPERTY LIBRARY_OUTPUT_NAME kcp)
12-
13-
install(FILES ikcp.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
14-
15-
install(TARGETS kcp_shared
8+
cmake_policy(SET CMP0054 NEW)
9+
10+
if(BUILD_SHARED_LIBS AND WIN32)
11+
set(exports_def_file "${CMAKE_CURRENT_BINARY_DIR}/exports.def")
12+
set(exports_def_contents
13+
"EXPORTS
14+
ikcp_create
15+
ikcp_release
16+
ikcp_setoutput
17+
ikcp_recv
18+
ikcp_send
19+
ikcp_update
20+
ikcp_check
21+
ikcp_input
22+
ikcp_flush
23+
ikcp_peeksize
24+
ikcp_setmtu
25+
ikcp_wndsize
26+
ikcp_waitsnd
27+
ikcp_nodelay
28+
ikcp_log
29+
ikcp_allocator
30+
ikcp_getconv
31+
")
32+
33+
file(WRITE "${exports_def_file}" "${exports_def_contents}")
34+
add_library(kcp ikcp.c "${exports_def_file}")
35+
else()
36+
add_library(kcp ikcp.c)
37+
endif()
38+
39+
install(FILES ikcp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
40+
41+
install(TARGETS kcp
1642
EXPORT kcp-targets
17-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
18-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
43+
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
44+
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
45+
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
46+
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
1947
)
2048

2149
install(EXPORT kcp-targets
@@ -24,11 +52,11 @@ install(EXPORT kcp-targets
2452
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kcp
2553
)
2654

27-
if (BUILD_TESTING)
55+
if(BUILD_TESTING)
2856
enable_language(CXX)
29-
57+
3058
add_executable(kcp_test test.cpp)
3159
if(MSVC AND NOT (MSVC_VERSION LESS 1900))
3260
target_compile_options(kcp_test PRIVATE /utf-8)
3361
endif()
34-
endif ()
62+
endif()

0 commit comments

Comments
 (0)