Skip to content

Commit

Permalink
Merge pull request #1016 from leapmotion/upd-standard
Browse files Browse the repository at this point in the history
Upd standard
  • Loading branch information
jdonald authored May 25, 2017
2 parents 5eadbe2 + c75630a commit c0f9657
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 57 deletions.
80 changes: 41 additions & 39 deletions standard/StandardProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ include(CMakeParseArguments) # Backwards compatibility

# This must be a macro since project defines scope-local variables
# that we generally rely on being in the root context.
# IMPORTANT: Note that if there is no *direct* call to 'project' in the root CMakeLists.txt
# file, CMake will automatically inject one with the default languages of C and CXX.
# This will cause the toolchain file to be parsed multiple times, and will
# make much of the work done in standard_project_preinit useless.
macro(standard_project project_name)
cmake_parse_arguments(standard "" "VERSION" "LANGUAGES" ${ARGN})

if(NOT standard_VERSION)
message(FATAL_ERROR "Standard compliant projects must specify a version")
endif()
Expand Down Expand Up @@ -50,26 +55,26 @@ function(standard_project_preinit)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release." FORCE)
endif()

# These do not strictly *have* to be set prior to project, but they can be so we will
# Need to classify the architecture before we run anything else, this lets us easily
# configure the find version file based on what the architecture was actually built to
# be.
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(standard_BUILD_ARM ON PARENT_SCOPE)
set(standard_BUILD_ARCHITECTURES "arm" PARENT_SCOPE)
set(standard_BUILD_64 OFF PARENT_SCOPE)
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64;i386")
set(standard_BUILD_ARCHITECTURES x64 x86 PARENT_SCOPE)
set(standard_BUILD_64 ON PARENT_SCOPE)
elseif(CMAKE_SIZEOF_VOID_P STREQUAL 4)
set(standard_BUILD_ARCHITECTURES "x86" PARENT_SCOPE)
set(standard_BUILD_64 OFF PARENT_SCOPE)
else()
set(standard_BUILD_ARCHITECTURES "x64" PARENT_SCOPE)
set(standard_BUILD_64 ON PARENT_SCOPE)
if(APPLE AND NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm"))
if(NOT CMAKE_OSX_SYSROOT)
# CLANG_VERSION requires a sysroot to obtain, so resort to execute_process() here
execute_process(COMMAND clang -v ERROR_VARIABLE _clang_version)
if(_clang_version MATCHES "clang-7")
set(_developer_sdk_version 10.11)
elseif(_clang_version MATCHES "clang-8")
set(_developer_sdk_version 10.12)
endif()
if(_developer_sdk_version)
set(CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_developer_sdk_version}.sdk" CACHE STRING "Mac OS X build environment" FORCE)
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Mac OS X deployment target" FORCE)
endif()
endif()
endif()
endif()
message(STATUS "Using architecture: ${standard_BUILD_ARCHITECTURES}")
endfunction()

function(standard_project_postinit)
# All of our binaries go to one place: The binaries output directory. We only want to tinker
# with this if we're building by ourselves, otherwise we just do whatever the enclosing project
# wants us to do.
Expand Down Expand Up @@ -108,34 +113,31 @@ function(standard_project_preinit)
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
set(CMAKE_CXX_EXTENSIONS OFF PARENT_SCOPE)

if(APPLE AND NOT (CMAKE_SYSTEM_PROCESSOR STREQUAL "arm"))
if(NOT CMAKE_OSX_SYSROOT)
# CLANG_VERSION requires a sysroot to obtain, so resort to execute_process() here
execute_process(COMMAND clang -v ERROR_VARIABLE _clang_version)
if(_clang_version MATCHES "clang-7")
set(_developer_sdk_version 10.11)
elseif(_clang_version MATCHES "clang-8")
set(_developer_sdk_version 10.12)
endif()
if(_developer_sdk_version)
set(CMAKE_OSX_SYSROOT "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${_developer_sdk_version}.sdk" CACHE STRING "Mac OS X build environment" FORCE)
if(NOT CMAKE_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.9" CACHE STRING "Mac OS X deployment target" FORCE)
endif()
endif()
endif()
endif()

# CMAKE_OSX_DEPLOYMENT_TARGET < 10.9 implies -stdlib=libstdc++, which doesn't have
# complete C++11 support. Override with libc++
if(DEFINED CMAKE_OSX_DEPLOYMENT_TARGET AND CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.9)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" PARENT_SCOPE)
endif()

endfunction()
# CMAKE_SYSTEM_PROCESSOR is set by the toolchain, so must happen strictly after project()
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(standard_BUILD_ARCHITECTURES "aarch64" PARENT_SCOPE)
set(standard_BUILD_64 ON PARENT_SCOPE)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(standard_BUILD_ARCHITECTURES "arm" PARENT_SCOPE)
set(standard_BUILD_64 OFF PARENT_SCOPE)
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64;i386")
set(standard_BUILD_ARCHITECTURES x64 x86 PARENT_SCOPE)
set(standard_BUILD_64 ON PARENT_SCOPE)
elseif(CMAKE_SIZEOF_VOID_P STREQUAL 4)
set(standard_BUILD_ARCHITECTURES "x86" PARENT_SCOPE)
set(standard_BUILD_64 OFF PARENT_SCOPE)
else()
set(standard_BUILD_ARCHITECTURES "x64" PARENT_SCOPE)
set(standard_BUILD_64 ON PARENT_SCOPE)
endif()
message(STATUS "Using architecture: ${standard_BUILD_ARCHITECTURES}")

function(standard_project_postinit)
# Post-initialization steps. All of these depend on project() having been called.
include(CTest)

if(CMAKE_COMPILER_IS_GNUCC)
Expand Down
9 changes: 7 additions & 2 deletions standard/standard-configVersion.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ if(DEFINED @ARG_NAME@_ARCHITECTURE)
foreach(i IN LISTS @ARG_NAME@_ARCHITECTURE)
string(REGEX MATCH "amd64|x86_64|x64" @ARG_NAME@_is_x64 ${i})
string(REGEX MATCH "i386|x86" @ARG_NAME@_is_x86 ${i})
string(REGEX MATCH "arm" @ARG_NAME@_is_arm ${i})
string(REGEX MATCH "arm$" @ARG_NAME@_is_arm ${i})
string(REGEX MATCH "arm64|aarch64" @ARG_NAME@_is_aarch64)

# Classify
if(@ARG_NAME@_is_x86)
Expand All @@ -25,13 +26,17 @@ if(DEFINED @ARG_NAME@_ARCHITECTURE)
list(APPEND @ARG_NAME@_ARCHITECTURES x64)
elseif(@ARG_NAME@_is_arm)
list(APPEND @ARG_NAME@_ARCHITECTURES arm)
elseif(@ARG_NAME@_is_aarch64)
list(APPEND @ARG_NAME@_ARCHITECTURES aarch64)
else()
message(WARNING "Unrecognized architecture ${i}")
endif()
endforeach()
else()
# Try to infer what the user wants
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(@ARG_NAME@_ARCHITECTURES aarch64)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(@ARG_NAME@_ARCHITECTURES arm)
elseif(CMAKE_SIZEOF_VOID_P EQUAL "8")
set(@ARG_NAME@_ARCHITECTURES x64)
Expand Down
8 changes: 3 additions & 5 deletions standard/toolchain-android.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_VERSION 1)

# For reasons beyond my comprehension, this file is parsed multiple times
# and in some of them, cache variables are not preserved so we have to store
# this in an environmental variable...
# Deal with weirdnesses caused by our standard_project setup. See
# notes in StandardProject.cmake
if(NOT LLVM_ANDROID_TOOLCHAIN_DIR)
set(LLVM_ANDROID_TOOLCHAIN_DIR $ENV{LLVM_ANDROID_TOOLCHAIN_DIR})
else()
Expand All @@ -21,7 +19,7 @@ if(NOT ANDROID_NDK_ROOT)
message(FATAL_ERROR "ANDROID_NDK_ROOT could not be located. Have you installed the NDK?")
endif()

set(ANDROID_COMMON_FLAGS " --sysroot=${ANDROID_NDK_ROOT}/sysroot -B${ANDROID_NDK_ROOT} ")
set(ANDROID_COMMON_FLAGS " --sysroot=${ANDROID_NDK_ROOT}/sysroot -B${ANDROID_NDK_ROOT} -pie ")
set(CMAKE_C_COMPILER ${ANDROID_NDK_ROOT}/bin/${ANDROID_NDK_TOOL_PREFIX}-gcc${_exe_suffix} CACHE FILEPATH "C Compiler" FORCE)
set(CMAKE_CXX_COMPILER ${ANDROID_NDK_ROOT}/bin/${ANDROID_NDK_TOOL_PREFIX}-g++${_exe_suffix} CACHE FILEPATH "C++ Compiler" FORCE)
set(ANDROID_STRIP_COMMAND ${ANDROID_NDK_ROOT}/bin/${ANDROID_NDK_TOOL_PREFIX}-strip)
Expand Down
1 change: 1 addition & 0 deletions standard/toolchain-android32.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set(ARM_TARGET "armeabi-v7a")
set(ANDROID_NDK_TOOL_PREFIX arm-linux-androideabi)
set(CMAKE_SYSTEM_PROCESSOR arm)
include(${CMAKE_CURRENT_LIST_DIR}/toolchain-android.cmake)
1 change: 1 addition & 0 deletions standard/toolchain-android64.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set(ANDROID_NDK_TOOL_PREFIX aarch64-linux-android)
set(_ndk_suffix -4.9-aarch64)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
include(${CMAKE_CURRENT_LIST_DIR}/toolchain-android.cmake)
5 changes: 0 additions & 5 deletions standard/toolchain-arm32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${config} config)
string(CONCAT CMAKE_${config}_POSTFIX "${CMAKE_${config}_POSTFIX}" "64")
endforeach()
7 changes: 1 addition & 6 deletions standard/toolchain-arm64.cmake
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_C_COMPILER /usr/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/aarch64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${config} config)
string(CONCAT CMAKE_${config}_POSTFIX "${CMAKE_${config}_POSTFIX}" "64")
endforeach()

0 comments on commit c0f9657

Please sign in to comment.