239 lines
7.9 KiB
CMake
239 lines
7.9 KiB
CMake
project(pip)
|
|
cmake_minimum_required(VERSION 2.6)
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
|
include(CheckFunctionExists)
|
|
|
|
# Version
|
|
file(READ "src/piversion.h" VERSION_OFFSET LIMIT 4 OFFSET 3)
|
|
file(READ "src/piversion.h" VERSION_MAJOR LIMIT 1 OFFSET ${VERSION_OFFSET})
|
|
file(READ "src/piversion.h" VERSION_OFFSET LIMIT 4 OFFSET 7)
|
|
file(READ "src/piversion.h" VERSION_MINOR LIMIT 1 OFFSET ${VERSION_OFFSET})
|
|
file(READ "src/piversion.h" VERSION_OFFSET LIMIT 4 OFFSET 11)
|
|
file(READ "src/piversion.h" VERSION_REVISION LIMIT 1 OFFSET ${VERSION_OFFSET})
|
|
file(STRINGS "src/piversion.h" VERSION_SUFFIX REGEX "\".*\"")
|
|
string(REGEX MATCH "\".*\"" VERSION_SUFFIX ${VERSION_SUFFIX})
|
|
string(LENGTH ${VERSION_SUFFIX} SL)
|
|
math(EXPR SL '${SL}-2')
|
|
string(SUBSTRING ${VERSION_SUFFIX} 1 ${SL} VERSION_SUFFIX)
|
|
string(LENGTH ${VERSION_MAJOR} SL)
|
|
math(EXPR SL '${SL}-1')
|
|
string(SUBSTRING ${VERSION_MAJOR} 0 ${SL} VERSION_MAJOR)
|
|
string(LENGTH ${VERSION_MINOR} SL)
|
|
math(EXPR SL '${SL}-1')
|
|
string(SUBSTRING ${VERSION_MINOR} 0 ${SL} VERSION_MINOR)
|
|
string(LENGTH ${VERSION_REVISION} SL)
|
|
math(EXPR SL '${SL}-1')
|
|
string(SUBSTRING ${VERSION_REVISION} 0 ${SL} VERSION_REVISION)
|
|
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION}")
|
|
set(SOVERSION ${VERSION})
|
|
message(STATUS "Building PIP version ${VERSION}${VERSION_SUFFIX}")
|
|
file(WRITE "src/pip_version_str.h" "// This file was generated by PIP CMake, don`t edit it!\n#define __PIP_VERSION_STR__ \"${VERSION}${VERSION_SUFFIX}\"\n")
|
|
|
|
#options
|
|
option(ICU "Unicode support" 1)
|
|
option(USB "USB support" 0)
|
|
option(STL "Building with STL containers" 0)
|
|
option(CRYPT "Crypt support" 0)
|
|
option(INTROSPECTION_CONTAINERS "Build with containers introspection" 0)
|
|
option(INTROSPECTION_THREADS "Build with threads introspection" 0)
|
|
option(LIB "System install" 1)
|
|
option(DEBUG "Build with -g3" 0)
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
set(LIBS)
|
|
if (DEBUG)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
|
endif ()
|
|
|
|
# Sources
|
|
set(PIP_FOLDERS "." "core" "containers" "thread" "system" "io" "console" "math" "code" "geo")
|
|
include_directories("src")
|
|
foreach(F ${PIP_FOLDERS})
|
|
include_directories("src/${F}")
|
|
file(GLOB HS "src/${F}/*.h")
|
|
file(GLOB CS "src/${F}/*.cpp")
|
|
list(APPEND HDRS ${HS})
|
|
list(APPEND CPPS ${CS})
|
|
endforeach(F)
|
|
|
|
# Check Bessel functions
|
|
set(CMAKE_REQUIRED_INCLUDES math.h)
|
|
set(CMAKE_REQUIRED_LIBRARIES m)
|
|
CHECK_FUNCTION_EXISTS(j0 PIP_MATH_J0)
|
|
CHECK_FUNCTION_EXISTS(j1 PIP_MATH_J1)
|
|
CHECK_FUNCTION_EXISTS(jn PIP_MATH_JN)
|
|
CHECK_FUNCTION_EXISTS(y0 PIP_MATH_Y0)
|
|
CHECK_FUNCTION_EXISTS(y1 PIP_MATH_Y1)
|
|
CHECK_FUNCTION_EXISTS(yn PIP_MATH_YN)
|
|
if (PIP_MATH_J0)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_MATH_J0")
|
|
endif ()
|
|
if (PIP_MATH_J1)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_MATH_J1")
|
|
endif ()
|
|
if (PIP_MATH_JN)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_MATH_JN")
|
|
endif ()
|
|
if (PIP_MATH_Y0)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_MATH_Y0")
|
|
endif ()
|
|
if (PIP_MATH_Y1)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_MATH_Y1")
|
|
endif ()
|
|
if (PIP_MATH_YN)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_MATH_YN")
|
|
endif ()
|
|
|
|
|
|
# Check if RT timers exists
|
|
set(CMAKE_REQUIRED_INCLUDES time.h)
|
|
if (DEFINED ENV{QNX_HOST})
|
|
set(CMAKE_REQUIRED_LIBRARIES )
|
|
else ()
|
|
set(CMAKE_REQUIRED_LIBRARIES rt)
|
|
endif ()
|
|
CHECK_FUNCTION_EXISTS(timer_create PIP_TIMER_RT_0)
|
|
CHECK_FUNCTION_EXISTS(timer_settime PIP_TIMER_RT_1)
|
|
CHECK_FUNCTION_EXISTS(timer_delete PIP_TIMER_RT_2)
|
|
if (PIP_TIMER_RT_0 AND PIP_TIMER_RT_1 AND PIP_TIMER_RT_2)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_TIMER_RT")
|
|
message(STATUS "Available timers: Thread, ThreadRT, Pool")
|
|
else ()
|
|
message(STATUS "Available timers: Thread, Pool")
|
|
endif ()
|
|
|
|
|
|
# Check if USB is on (to enable use "-DUSB=" argument of cmake)
|
|
if (USB)
|
|
message(STATUS "Building with USB support")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_USB")
|
|
list(APPEND LIBS usb)
|
|
else ()
|
|
message(STATUS "Building without USB support")
|
|
endif ()
|
|
|
|
|
|
# Check if STL containers is on (to enable use "-DSTL=" argument of cmake)
|
|
if (STL)
|
|
message(STATUS "Building with STL containers")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CONTAINERS_STL")
|
|
else ()
|
|
message(STATUS "Building with PIP containers")
|
|
endif ()
|
|
|
|
|
|
# Check if ICU used for PIString and PIChar
|
|
if (ICU)
|
|
message(STATUS "Building with ICU")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_ICU")
|
|
list(APPEND LIBS icuuc)
|
|
else ()
|
|
message(STATUS "Building without ICU, attention!")
|
|
endif ()
|
|
|
|
|
|
# Check if PIP support cryptographic encryption/decryption by using sodium library
|
|
if (CRYPT)
|
|
message(STATUS "Building with crypt support")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_CRYPT")
|
|
list(APPEND LIBS sodium)
|
|
else ()
|
|
message(STATUS "Building without crypt support")
|
|
endif ()
|
|
|
|
|
|
# Check if PIP should be built with containers introspection
|
|
if (INTROSPECTION_CONTAINERS)
|
|
message(STATUS "Building with containers introspection")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_CONTAINERS")
|
|
else ()
|
|
message(STATUS "Building without containers introspection")
|
|
endif ()
|
|
|
|
|
|
# Check if PIP should be built with threads introspection
|
|
if (INTROSPECTION_THREADS)
|
|
message(STATUS "Building with threads introspection")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPIP_INTROSPECTION_THREADS")
|
|
else ()
|
|
message(STATUS "Building without threads introspection")
|
|
endif ()
|
|
|
|
|
|
# Add library
|
|
if (APPLE)
|
|
add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE)
|
|
endif ()
|
|
if (WIN32)
|
|
list(APPEND LIBS ws2_32 iphlpapi psapi)
|
|
list(APPEND CPPS "pip_resource_win.rc")
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPSAPI_VERSION=1")
|
|
add_library(pip SHARED ${CPPS} ${HDRS})
|
|
if (${CMAKE_C_COMPILER} STREQUAL "cl")
|
|
include(GenerateExportHeader)
|
|
generate_export_header(pip)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /Ob2 /Ot")
|
|
else ()
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2")
|
|
endif ()
|
|
else ()
|
|
set(${CMAKE_CXX_FLAGS} "${CMAKE_CXX_FLAGS} -O2")
|
|
if (DEFINED ENV{QNX_HOST})
|
|
list(APPEND LIBS socket dl)
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth-32")
|
|
add_library(pip STATIC ${CPPS})
|
|
else ()
|
|
list(APPEND LIBS pthread dl util)
|
|
if (NOT APPLE)
|
|
list(APPEND LIBS rt)
|
|
endif()
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
|
add_library(pip SHARED ${CPPS})
|
|
endif ()
|
|
endif ()
|
|
target_link_libraries(pip ${LIBS})
|
|
|
|
# Test program
|
|
#find_package(Qt4 REQUIRED)
|
|
#include_directories(${QT_INCLUDES})
|
|
add_executable(pip_test "main.cpp" "ccm_kbd.cpp")
|
|
target_link_libraries(pip_test pip)# ${QT_QTCORE_LIBRARY})
|
|
|
|
# Install
|
|
# Check if system or local install will be used (to system install use "-DLIB=" argument of cmake)
|
|
if (LIB)
|
|
if (WIN32)
|
|
if (MINGW)
|
|
find_package(MinGW REQUIRED)
|
|
set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
|
|
install(FILES ${HDRS} DESTINATION ${MINGW_INCLUDE}/pip)
|
|
install(TARGETS pip DESTINATION ${MINGW_LIB})
|
|
install(TARGETS pip DESTINATION ${MINGW_BIN})
|
|
endif ()
|
|
else ()
|
|
set(CMAKE_INSTALL_PREFIX /usr)
|
|
install(FILES ${HDRS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/pip)
|
|
install(TARGETS pip DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
|
|
endif ()
|
|
message(STATUS "Install to system \"${CMAKE_INSTALL_PREFIX}\"")
|
|
# Precompiled header
|
|
#add_custom_target(pip_pch ALL COMMAND ${CMAKE_CXX_COMPILER} -O2 -fPIC -g3 ${CMAKE_INSTALL_PREFIX}/include/pip/pip.h DEPENDS pip SOURCES ${HDRS})
|
|
#list(APPEND HDRS "pip.h.gch")
|
|
file(GLOB CMAKES "*.cmake")
|
|
install(FILES ${CMAKES} DESTINATION ${CMAKE_ROOT}/Modules)
|
|
else ()
|
|
install(TARGETS pip DESTINATION bin)
|
|
message(STATUS "Install to local \"bin\"")
|
|
endif ()
|
|
|
|
# Auxiliary
|
|
add_subdirectory("src/auxiliary/piterminal")
|
|
|
|
# Utils
|
|
add_subdirectory("utils/system_test")
|
|
add_subdirectory("utils/remote_console")
|
|
add_subdirectory("utils/code_model_generator")
|
|
add_subdirectory("utils/system_daemon")
|
|
add_subdirectory("utils/udp_file_transfer")
|
|
add_subdirectory("utils/crypt_tool")
|