mirror of https://github.com/XS-MLVP/xcomm.git
restruct cmake
This commit is contained in:
parent
68f4562be2
commit
b000bb1c17
|
@ -1,40 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.15)
|
||||
project(xspcomm VERSION 0.0.1)
|
||||
|
||||
string(TOLOWER "$ENV{CMAKE_CXX_COMPILER}" cmake_cxx_compiler)
|
||||
if (NOT "${cmake_cxx_compiler}" STREQUAL "")
|
||||
set(CMAKE_CXX_COMPILER ${cmake_cxx_compiler})
|
||||
endif()
|
||||
|
||||
include(CheckIncludeFile)
|
||||
check_include_file("execinfo.h" HAVE_EXECINFO_H)
|
||||
if(HAVE_EXECINFO_H)
|
||||
add_definitions(-DHAVE_EXECINFO_H)
|
||||
else()
|
||||
message(WARNING "The <execinfo.h> not find, xutil.Assert will not print the call stack.")
|
||||
endif()
|
||||
|
||||
function(init_xspcomm)
|
||||
set(XSPCOMM_VERSION "${PROJECT_VERSION}" PARENT_SCOPE)
|
||||
add_definitions(-DXSPCOMM_VERSION="${PROJECT_VERSION}")
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++20" COMPILER_SUPPORTS_CXX20)
|
||||
if(COMPILER_SUPPORTS_CXX20)
|
||||
set(CMAKE_CXX_STANDARD 20 PARENT_SCOPE)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -std=c++20 -fcoroutines" PARENT_SCOPE)
|
||||
add_definitions(-DENABLE_XCOROUTINE=true)
|
||||
set(ENABLE_XCOROUTINE true PARENT_SCOPE)
|
||||
else()
|
||||
message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++20 support. If you need coroutines, please use a different C++ compiler.")
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -std=c++17" PARENT_SCOPE)
|
||||
add_definitions(-DENABLE_XCOROUTINE=false)
|
||||
set(ENABLE_XCOROUTINE false PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
|
||||
include(xcomm)
|
||||
init_xspcomm()
|
||||
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||
|
@ -43,19 +12,3 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
|
|||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
||||
add_subdirectory(swig)
|
||||
|
||||
add_custom_target(copy_xspcomm_include ALL
|
||||
VERBATIM
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}"
|
||||
COMMAND sed -i "s/XSPCOMM_VERSION/\"${PROJECT_VERSION}\"/g" ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/xspcomm/xutil.h
|
||||
COMMAND sed -i "s/ENABLE_XCOROUTINE/${ENABLE_XCOROUTINE}/g" ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/xspcomm/xclock.h
|
||||
COMMAND sed -i "s/ENABLE_XCOROUTINE/${ENABLE_XCOROUTINE}/g" ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/xspcomm/xcoroutine.h
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
)
|
||||
|
||||
install( DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/ DESTINATION include )
|
||||
install( TARGETS ${PROJECT_NAME} DESTINATION lib )
|
||||
install( DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/ DESTINATION share/picker/include )
|
||||
install( TARGETS ${PROJECT_NAME} DESTINATION share/picker/lib )
|
|
@ -0,0 +1,50 @@
|
|||
# Init function:
|
||||
# 1. set the project version
|
||||
# 2. set the compiler
|
||||
# 3. check the execinfo.h
|
||||
# 4. set the xspcomm version
|
||||
# 5. set the c++ standard
|
||||
# 6. set the xconfig.h
|
||||
|
||||
function(init_xspcomm)
|
||||
string(TOLOWER "$ENV{CMAKE_CXX_COMPILER}" cmake_cxx_compiler)
|
||||
if (NOT "${cmake_cxx_compiler}" STREQUAL "")
|
||||
set(CMAKE_CXX_COMPILER ${cmake_cxx_compiler} PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
string(TOLOWER "$ENV{CMAKE_C_COMPILER}" cmake_c_compiler)
|
||||
if (NOT "${cmake_c_compiler}" STREQUAL "")
|
||||
set(CMAKE_C_COMPILER ${cmake_cxx_compiler} PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
include(CheckIncludeFile)
|
||||
check_include_file("execinfo.h" HAVE_EXECINFO_H)
|
||||
if(HAVE_EXECINFO_H)
|
||||
add_definitions(-DHAVE_EXECINFO_H)
|
||||
else()
|
||||
message(WARNING "The <execinfo.h> not find, xutil.Assert will not print the call stack.")
|
||||
endif()
|
||||
|
||||
set(XSPCOMM_VERSION "${PROJECT_VERSION}" PARENT_SCOPE)
|
||||
add_definitions(-DXSPCOMM_VERSION="${PROJECT_VERSION}")
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++20" COMPILER_SUPPORTS_CXX20)
|
||||
if(COMPILER_SUPPORTS_CXX20)
|
||||
set(CMAKE_CXX_STANDARD 20 PARENT_SCOPE)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -std=c++20 -fcoroutines" PARENT_SCOPE)
|
||||
add_definitions(-DENABLE_XCOROUTINE=true)
|
||||
set(ENABLE_XCOROUTINE "true")
|
||||
else()
|
||||
message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++20 support. If you need coroutines, please use a different C++ compiler.")
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -std=c++17" PARENT_SCOPE)
|
||||
add_definitions(-DENABLE_XCOROUTINE=false)
|
||||
set(ENABLE_XCOROUTINE "false")
|
||||
endif()
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/xspcomm/xconfig.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/xspcomm/xconfig.h)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||
endfunction()
|
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#define XSPCOMM_VERSION "@PROJECT_VERSION@"
|
||||
#define ENABLE_XCOROUTINE @ENABLE_XCOROUTINE@
|
||||
#define HAVE_EXECINFO_H @HAVE_EXECINFO_H@
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __xspcomm_xutil_h__
|
||||
#define __xspcomm_xutil_h__
|
||||
|
||||
#include "xspcomm/xconfig.h"
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
|
|
@ -47,3 +47,17 @@ add_custom_target(
|
|||
)
|
||||
|
||||
endif()
|
||||
|
||||
add_custom_target(copy_xspcomm_include ALL
|
||||
VERBATIM
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../include"
|
||||
"${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}"
|
||||
DEPENDS ${PROJECT_NAME}
|
||||
)
|
||||
|
||||
# install C++ headers and libraries
|
||||
install( DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/ DESTINATION include )
|
||||
install( TARGETS ${PROJECT_NAME} DESTINATION lib )
|
||||
install( DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/ DESTINATION share/picker/include )
|
||||
install( TARGETS ${PROJECT_NAME} DESTINATION share/picker/lib )
|
||||
|
|
Loading…
Reference in New Issue