From 6256055924e581eaaf5a4c177f031fe35c657319 Mon Sep 17 00:00:00 2001 From: myd7349 Date: Sat, 21 Sep 2019 14:24:04 +0800 Subject: [PATCH] improve CMakeLists.txt - add install target - add BUILD_TESTING option --- CMakeLists.txt | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3a1dbd0..a3b12b4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,31 @@ -PROJECT(kcp) CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -add_library(kcp STATIC ikcp.c) +project(kcp LANGUAGES C) -add_executable(kcp_test test.cpp) +include(CTest) +include(GNUInstallDirs) +add_library(kcp STATIC ikcp.c) +install(FILES ikcp.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(TARGETS kcp + EXPORT kcp-targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) +install(EXPORT kcp-targets + FILE kcp-config.cmake + NAMESPACE kcp:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kcp +) +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) + endif() +endif ()