cmake

cmake_minimum_required(VERSION 3.0.0)

if( CMAKE_COMPILER_IS_GNUCXX )

    #Get compiler version.

    execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion

                    OUTPUT_VARIABLE GNUCXX_VERSION )

    #-Werror=* was introduced -after- GCC 4.1.2

    if( GNUCXX_VERSION VERSION_GREATER 4.1.2 )

        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=strict-aliasing")

    endif()

endif( CMAKE_COMPILER_IS_GNUCXX )

include(CheckIncludeFileCXX)

include(CheckTypeSize)

include(CheckStructHasMember)

include(CheckCXXSymbolExists)

check_include_file_cxx(clocale HAVE_CLOCALE)

check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV)

if(CMAKE_VERSION VERSION_LESS 3.0.0)

    # The "LANGUAGE CXX" parameter is not supported in CMake versions below 3,

    # so the C compiler and header has to be used.

    check_include_file(locale.h HAVE_LOCALE_H)

    set(CMAKE_EXTRA_INCLUDE_FILES locale.h)

    check_type_size("struct lconv" LCONV_SIZE)

    unset(CMAKE_EXTRA_INCLUDE_FILES)

    check_struct_has_member("struct lconv" decimal_point locale.h HAVE_DECIMAL_POINT)

else()

    set(CMAKE_EXTRA_INCLUDE_FILES clocale)

    check_type_size(lconv LCONV_SIZE LANGUAGE CXX)

    unset(CMAKE_EXTRA_INCLUDE_FILES)

    check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)

endif()

project("gnssparser")

SET(MODULE_NAME gnssparser)

enable_testing()

if(DEBUG_FLAG)

    SET(DEBUG_FLAG "-g")

    SET(BUILD_CONFIGURATION_ "debug")

else()

    SET(DEBUG_FLAG "-DNDEBUG")

    SET(BUILD_CONFIGURATION "release")

endif()

set (C_CPP_FLAGS_ "${C_CPP_FLAGS_} -static-libstdc++ -std=c++14 -pthread -fPIC -Wl,--no-undefined -O3 ${DEBUG_FLAG}")

#set (C_CPP_FLAGS_ "${C_CPP_FLAGS_} -static-libstdc++ -std=c++14 -pthread -fPIC -Wl,--no-undefined -O3 -DUSE_COMMON_LIB ${DEBUG_FLAG} ${OS_FLAG} ${HCI_WARNINGS_SETTING}")

set (CMAKE_BUILD_TYPE "Debug")

set (CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb")

set (CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

set(CPACK_PROJECT_NAME ${PROJECT_NAME})

set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

set(MYINCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include)

set(PROJECTINCLUDE ${PROJECT_SOURCE_DIR}/include)

set(SYSINCLUDE /usr/include  /usr/local/lib)

include_directories(${SYSINCLUDE} ${PROJECTINCLUDE} ${MYINCLUDE})#添加头文件目录 -l

link_directories(${PROJECT_SOURCE_DIR}/lib ${CMAKE_CURRENT_SOURCE_DIR}/lib /usr/lib) #指定要链接的库文件的路径 -L

#source_group( "Public API" FILES ${PUBLIC_HEADERS} )

#add_library(xxx_lib ${PUBLIC_HEADERS} ${xxx_sources})

#set_target_properties( xxx_lib PROPERTIES VERSION ${xxx_VERSION} SOVERSION ${xxx_SOVERSION})

#set_target_properties( xxx_lib PROPERTIES OUTPUT_NAME xxxcpp

#                      DEBUG_OUTPUT_NAME xxxcpp${DEBUG_LIBNAME_SUFFIX} )

#set_target_properties( xxx_lib PROPERTIES POSITION_INDEPENDENT_CODE ON)

#add_library(${MODULE_NAME} SHARED  ${PROJECT_SOURCE_DIR})  #动态库,自定义,编译进代码

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)# 设置可执行文件的输出路径(EXCUTABLE_OUTPUT_PATH是全局变量)

set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")# 设置库文件的输出路径(LIBRARY_OUTPUT_PATH是全局变量)

#add_library(baz STATIC IMPORTED)  #静态库,自定义,编译进代码auto

#set_target_properties(baz PROPERTIES

    #IMPORTED_LOCATION_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/libbaz.a

    #IMPORTED_LOCATION_DEBUG  ${CMAKE_CURRENT_SOURCE_DIR}/libbazd.a)

#add_library(native-lib  SHARED  IMPORTED ) #动态库,自定义,auto编译进代码

#add_library(dbciterator SHARED  ${PROJECT_SOURCE_DIR}/source/dbciterator.c)  #静态库,自定义,编译进代码

#set_target_properties( native-lib PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libnative-lib.so )#指名第三方库的绝对路径

#add_library(native2-lib SHARED src/main/cpp/native2-lib.cpp )

#target_link_libraries(native2-lib native-lib ${log-lib} )

SET(TUSLIBS  libcommu_c.so libprotobuf.so libprotomsg.so)

SET(SYSLIBS  pthread  librt.so)

SET(PRJLIBS  car_cloud  caster json nmeaparser serial)

add_subdirectory(car_cloud) #添加子目录

add_subdirectory(caster) #添加子目录

add_subdirectory(json) #添加子目录

add_subdirectory(nmeaparser) #添加子目录

add_subdirectory(serial) #添加子目录

aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRCS)

add_executable(${PROJECT_NAME} ${DIR_SRCS})

target_link_libraries(${MODULE_NAME} ${PRJLIBS} ${TUSLIBS} ${SYSLIBS})

你可能感兴趣的:(cmake)