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)
|
||||
|
||||
if(DEFINED PROJECT_NAME)
|
||||
set(KCP_IS_TOP_PROJECT OFF)
|
||||
else()
|
||||
set(KCP_IS_TOP_PROJECT ON)
|
||||
endif()
|
||||
|
||||
project(kcp LANGUAGES C)
|
||||
|
||||
include(CTest)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
|
||||
option(KCP_BUILD_SHARED_LIBS "Build KCP as a shared lib" OFF)
|
||||
option(KCP_BUILD_INSTALL "Build install target" ${KCP_IS_TOP_PROJECT})
|
||||
option(KCP_BUILD_TESTS "Build tests" ${KCP_IS_TOP_PROJECT})
|
||||
|
||||
if(KCP_BUILD_SHARED_LIBS)
|
||||
if(WIN32)
|
||||
set(exports_def_file "${CMAKE_CURRENT_BINARY_DIR}/exports.def")
|
||||
set(exports_def_contents
|
||||
if(BUILD_SHARED_LIBS AND WIN32)
|
||||
set(exports_def_file "${CMAKE_CURRENT_BINARY_DIR}/exports.def")
|
||||
set(exports_def_contents
|
||||
"EXPORTS
|
||||
ikcp_create
|
||||
ikcp_release
|
||||
@ -38,39 +30,31 @@ if(KCP_BUILD_SHARED_LIBS)
|
||||
ikcp_getconv
|
||||
")
|
||||
|
||||
file(WRITE "${exports_def_file}" "${exports_def_contents}")
|
||||
add_library(kcp SHARED ikcp.h ikcp.c "${exports_def_file}")
|
||||
else()
|
||||
add_library(kcp SHARED ikcp.h ikcp.c)
|
||||
endif()
|
||||
file(WRITE "${exports_def_file}" "${exports_def_contents}")
|
||||
add_library(kcp ikcp.c "${exports_def_file}")
|
||||
else()
|
||||
add_library(kcp STATIC ikcp.h ikcp.c)
|
||||
add_library(kcp ikcp.c)
|
||||
endif()
|
||||
|
||||
if(KCP_BUILD_INSTALL)
|
||||
include(GNUInstallDirs)
|
||||
install(FILES ikcp.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
|
||||
|
||||
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
|
||||
EXPORT kcp-targets
|
||||
PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
|
||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
|
||||
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
||||
)
|
||||
install(EXPORT kcp-targets
|
||||
FILE kcp-config.cmake
|
||||
NAMESPACE kcp::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kcp
|
||||
)
|
||||
|
||||
install(EXPORT kcp-targets
|
||||
FILE kcp-config.cmake
|
||||
NAMESPACE kcp::
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kcp
|
||||
)
|
||||
endif()
|
||||
|
||||
if(KCP_BUILD_TESTS)
|
||||
if(BUILD_TESTING)
|
||||
enable_language(CXX)
|
||||
|
||||
|
||||
add_executable(kcp_test test.cpp)
|
||||
if(MSVC AND NOT (MSVC_VERSION LESS 1900))
|
||||
target_compile_options(kcp_test PRIVATE /utf-8)
|
||||
|
Loading…
Reference in New Issue
Block a user