From 96148e79ef11e3735b18055db7ca047705b13421 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=84=B8=ED=9D=AC/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Principal=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Mon, 26 Feb 2018 19:46:54 +0900 Subject: [PATCH] Add cmake config and options (#14) * Add cmake config and options This will add cmake config and options for multi-arch and cross building for arm This will not affect current makefile build configuration * platform to os * fix for rootfs checking * separate os and arch * simplify folder --- CMakeLists.txt | 39 +++++++++++++++++++++++++++++++++++ arch/arm/config_armv7l-linux.cmake | 32 ++++++++++++++++++++++++++++ arch/arm/option_armv7l-linux.cmake | 18 ++++++++++++++++ arch/x86_64/config_x86_64-linux.cmake | 7 +++++++ arch/x86_64/option_x86_64-linux.cmake | 9 ++++++++ os/linux/option.cmake | 9 ++++++++ 6 files changed, 114 insertions(+) create mode 100644 arch/arm/config_armv7l-linux.cmake create mode 100644 arch/arm/option_armv7l-linux.cmake create mode 100644 arch/x86_64/config_x86_64-linux.cmake create mode 100644 arch/x86_64/option_x86_64-linux.cmake create mode 100644 os/linux/option.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e208dd..3d08d3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,5 +8,44 @@ else(CMAKE_VERSION VERSION_LESS 3.1.0) set(CMAKE_CXX_STANDARD 11) endif(CMAKE_VERSION VERSION_LESS 3.1.0) +# set host platform to build +if(NOT HOST_ARCH OR "${HOST_ARCH}" STREQUAL "") + set(HOST_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR}) +endif() + +if("${HOST_ARCH}" STREQUAL "x86_64") + set(HOST_ARCH_BASE ${HOST_ARCH}) +elseif("${HOST_ARCH}" STREQUAL "armv7l") + set(HOST_ARCH_BASE "arm") +else() + message(FATAL_ERROR "'${HOST_ARCH}' architecture is not supported") +endif() + +# TODO add Tizen +set(HOST_OS "linux") + +# host platform name +set(HOST_PLATFORM "${HOST_ARCH}-${HOST_OS}") + +# platform specific options +include("os/linux/generic/option_${HOST_OS}-generic.cmake") +include("arch/${HOST_ARCH_BASE}/option_${HOST_PLATFORM}.cmake") + +# add common flags +foreach(FLAG ${FLAGS_COMMON}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") +endforeach() + +# add c flags +foreach(FLAG ${FLAGS_CONLY}) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}") +endforeach() + +# add cxx flags +foreach(FLAG ${FLAGS_CXXONLY}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG}") +endforeach() + add_subdirectory(externals) add_subdirectory(tools) diff --git a/arch/arm/config_armv7l-linux.cmake b/arch/arm/config_armv7l-linux.cmake new file mode 100644 index 0000000..0080c9f --- /dev/null +++ b/arch/arm/config_armv7l-linux.cmake @@ -0,0 +1,32 @@ +# +# config for arm-linux +# +include(CMakeForceCompiler) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR armv7l) + +set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc) +set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++) + +# where is the target environment +set(ROOTFS_ARM $ENV{ROOTFS_ARM}) +if(NOT EXISTS "${ROOTFS_ARM}/lib/arm-linux-gnueabihf") + set(ROOTFS_ARM "${CMAKE_SOURCE_DIR}/tools/cross/rootfs/arm") +endif() + +set(CMAKE_FIND_ROOT_PATH ${ROOTFS_ARM}) +set(CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${ROOTFS_ARM}" + CACHE INTERNAL "" FORCE) +set(CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${ROOTFS_ARM}" + CACHE INTERNAL "" FORCE) + +# search for programs in the build host directories +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + +# for libraries and headers in the target directories +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) diff --git a/arch/arm/option_armv7l-linux.cmake b/arch/arm/option_armv7l-linux.cmake new file mode 100644 index 0000000..79e781e --- /dev/null +++ b/arch/arm/option_armv7l-linux.cmake @@ -0,0 +1,18 @@ +# +# armv7l linux compile options +# + +message(STATUS "Building for ARMv7l Linux") + +if(NOT EXISTS "${ROOTFS_ARM}/lib/arm-linux-gnueabihf") + message(FATAL_ERROR "Please prepare RootFS for ARM") +endif() + +# addition for arm-linux +set(FLAGS_COMMON ${FLAGS_COMMON} + "-mcpu=cortex-a7" + "-mfloat-abi=hard" + "-mfpu=neon-vfpv4" + "-funsafe-math-optimizations" + "-ftree-vectorize" + ) diff --git a/arch/x86_64/config_x86_64-linux.cmake b/arch/x86_64/config_x86_64-linux.cmake new file mode 100644 index 0000000..3dee876 --- /dev/null +++ b/arch/x86_64/config_x86_64-linux.cmake @@ -0,0 +1,7 @@ +# +# config for x86_64-linux +# +include(CMakeForceCompiler) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR x86_64) diff --git a/arch/x86_64/option_x86_64-linux.cmake b/arch/x86_64/option_x86_64-linux.cmake new file mode 100644 index 0000000..89c617d --- /dev/null +++ b/arch/x86_64/option_x86_64-linux.cmake @@ -0,0 +1,9 @@ +# +# x86_64 linux compile options +# +message(STATUS "Building for x86-64 Linux") + +# SIMD for x86 +set(FLAGS_COMMON ${FLAGS_COMMON} + "-msse4" + ) diff --git a/os/linux/option.cmake b/os/linux/option.cmake new file mode 100644 index 0000000..ea533ec --- /dev/null +++ b/os/linux/option.cmake @@ -0,0 +1,9 @@ +# +# linux common compile options +# + +# flags for build type: debug, release +set(CMAKE_C_FLAGS_DEBUG "-O0 -g -DDEBUG") +set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG") +set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG") +set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG") -- 2.7.4