mirror of
https://github.com/skywind3000/kcp.git
synced 2024-12-25 22:50:09 +08:00
simplify
This commit is contained in:
parent
6900c9128e
commit
3c9fd966f9
@ -1,23 +1,15 @@
|
|||||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
|
||||||
|
|
||||||
if(DEFINED PROJECT_NAME)
|
|
||||||
set(KCP_IS_TOP_PROJECT OFF)
|
|
||||||
else()
|
|
||||||
set(KCP_IS_TOP_PROJECT ON)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
project(kcp LANGUAGES C)
|
project(kcp LANGUAGES C)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
cmake_policy(SET CMP0054 NEW)
|
cmake_policy(SET CMP0054 NEW)
|
||||||
|
|
||||||
option(KCP_BUILD_SHARED_LIBS "Build KCP as a shared lib" OFF)
|
if(BUILD_SHARED_LIBS AND WIN32)
|
||||||
option(KCP_BUILD_INSTALL "Build install target" ${KCP_IS_TOP_PROJECT})
|
set(exports_def_file "${CMAKE_CURRENT_BINARY_DIR}/exports.def")
|
||||||
option(KCP_BUILD_TESTS "Build tests" ${KCP_IS_TOP_PROJECT})
|
set(exports_def_contents
|
||||||
|
|
||||||
if(KCP_BUILD_SHARED_LIBS)
|
|
||||||
if(WIN32)
|
|
||||||
set(exports_def_file "${CMAKE_CURRENT_BINARY_DIR}/exports.def")
|
|
||||||
set(exports_def_contents
|
|
||||||
"EXPORTS
|
"EXPORTS
|
||||||
ikcp_create
|
ikcp_create
|
||||||
ikcp_release
|
ikcp_release
|
||||||
@ -38,39 +30,31 @@ if(KCP_BUILD_SHARED_LIBS)
|
|||||||
ikcp_getconv
|
ikcp_getconv
|
||||||
")
|
")
|
||||||
|
|
||||||
file(WRITE "${exports_def_file}" "${exports_def_contents}")
|
file(WRITE "${exports_def_file}" "${exports_def_contents}")
|
||||||
add_library(kcp SHARED ikcp.h ikcp.c "${exports_def_file}")
|
add_library(kcp ikcp.c "${exports_def_file}")
|
||||||
else()
|
|
||||||
add_library(kcp SHARED ikcp.h ikcp.c)
|
|
||||||
endif()
|
|
||||||
else()
|
else()
|
||||||
add_library(kcp STATIC ikcp.h ikcp.c)
|
add_library(kcp ikcp.c)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(KCP_BUILD_INSTALL)
|
install(FILES ikcp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||||
include(GNUInstallDirs)
|
|
||||||
|
|
||||||
set_target_properties(kcp PROPERTIES PUBLIC_HEADER ikcp.h)
|
install(TARGETS kcp
|
||||||
|
EXPORT kcp-targets
|
||||||
|
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||||
|
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||||
|
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||||
|
)
|
||||||
|
|
||||||
install(TARGETS kcp
|
install(EXPORT kcp-targets
|
||||||
EXPORT kcp-targets
|
FILE kcp-config.cmake
|
||||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
NAMESPACE kcp::
|
||||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kcp
|
||||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
)
|
||||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
|
||||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(EXPORT kcp-targets
|
if(BUILD_TESTING)
|
||||||
FILE kcp-config.cmake
|
|
||||||
NAMESPACE kcp::
|
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kcp
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(KCP_BUILD_TESTS)
|
|
||||||
enable_language(CXX)
|
enable_language(CXX)
|
||||||
|
|
||||||
add_executable(kcp_test test.cpp)
|
add_executable(kcp_test test.cpp)
|
||||||
if(MSVC AND NOT (MSVC_VERSION LESS 1900))
|
if(MSVC AND NOT (MSVC_VERSION LESS 1900))
|
||||||
target_compile_options(kcp_test PRIVATE /utf-8)
|
target_compile_options(kcp_test PRIVATE /utf-8)
|
||||||
|
Loading…
Reference in New Issue
Block a user