Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMake standard #1001

Merged
merged 19 commits into from Sep 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 43 additions & 9 deletions standard/InstallHeaders.cmake
Expand Up @@ -15,7 +15,7 @@ function(install_headers)
set(multiValueArgs)

cmake_parse_arguments(opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

string(TOLOWER LOWERNAME CMAKE_PROJECT_NAME)
default_value(opt_DESTINATION include/${LOWERNAME})

Expand All @@ -28,15 +28,49 @@ function(install_headers)
if(NOT ${opt_NOEXCLUDE_STDAFX} AND ${src} STREQUAL "stdafx.h")
continue()
endif()

get_filename_component(src_ext ${src} EXT)
if(src_ext STREQUAL ".h")
get_filename_component(src_rel ${src} DIRECTORY)
install(
FILES ${src}
DESTINATION ${opt_DESTINATION}/${src_rel}
${opt_UNPARSED_ARGUMENTS}
)
if(NOT src_ext STREQUAL ".h")
continue()
endif()

# Need to make the path absolute. We first look in the source directory,
# then we look in the binary directory, but only if the path is relative.
if(NOT IS_ABSOLUTE ${src})
get_filename_component(src_src ${src} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
get_filename_component(src_bin ${src} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
if(EXISTS ${src_src})
set(src ${src_src})
elseif(EXISTS ${src_bin})
set(src ${src_bin})
else()
message(FATAL_ERROR "Could not find input header file ${src}")
endif()
endif()

# We find out what directory part the file is in, we want the shortest
# relative path on the assumption that the file will be most properly
# located in the directory whose relative address is the shortest.
file(RELATIVE_PATH src_rel ${CMAKE_CURRENT_SOURCE_DIR} ${src})
get_filename_component(src_rel ${src_rel} DIRECTORY)
if(src_rel)
string(LENGTH ${src_rel} src_rel_len)
set(actual_rel ${src_rel})
endif()

file(RELATIVE_PATH bin_rel ${CMAKE_CURRENT_BINARY_DIR} ${src})
get_filename_component(bin_rel ${bin_rel} DIRECTORY)
if(bin_rel)
string(LENGTH ${bin_rel} bin_rel_len)
if(src_rel AND bin_rel_len LESS src_rel_len)
set(actual_rel ${bin_rel})
endif()
endif()

get_filename_component(src_ext ${src} EXT)
install(
FILES ${src}
DESTINATION ${opt_DESTINATION}/${actual_rel}
${opt_UNPARSED_ARGUMENTS}
)
endforeach()
endfunction()
46 changes: 32 additions & 14 deletions standard/StandardProject.cmake
Expand Up @@ -4,7 +4,7 @@ in a particular order around project setup. This function wraps project() and
does the following:

* Changes CMake around so that the output variables follow the /bin and /lib output
directory convention popular on Gnu.
directory convention popular on GNU.
* Ensures that ARM and 64-bit code are built as position-independent code
* Verifies that the compiler actually supports C++11
* Sets the correct flags to enable C++11 on all platforms
Expand All @@ -14,10 +14,10 @@ does the following:
* Enforces the project has a VERSION set.
]]

include (CMakeParseArguments) #Backwards compatibilty
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.
# This must be a macro since project defines scope-local variables
# that we generally rely on being in the root context.
macro(standard_project project_name)
cmake_parse_arguments(standard "" "VERSION" "LANGUAGES" ${ARGN})
if(NOT standard_VERSION)
Expand Down Expand Up @@ -46,14 +46,14 @@ function(standard_project_preinit)
endif()
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
# 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 OFFPARENT_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)
Expand All @@ -66,7 +66,7 @@ function(standard_project_preinit)
endif()
message(STATUS "Using architecture: ${standard_BUILD_ARCHITECTURES}")

# All of our binaries go to one place: The binaries output directory. We only want to tinker
# 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.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin PARENT_SCOPE)
Expand All @@ -88,7 +88,7 @@ function(standard_project_preinit)
set(CMAKE_DEBUG_POSTFIX "d${CMAKE_DEBUG_POSTFIX}")
set(CMAKE_DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX} PARENT_SCOPE)

# 64-bit installations should suffix with 64 regardless of the CPU type (arm or intel)
# 64-bit installations should suffix with 64 regardless of the CPU type (ARM or Intel)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${config} config)
Expand All @@ -104,16 +104,34 @@ function(standard_project_preinit)
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
set(CMAKE_CXX_EXTENSIONS OFF PARENT_SCOPE)

#CMAKE_OSX_DEPLOYMENT_TARGET < 10.9 implies -stdlib=libstdc++, which doesn't have
#complete c++11 support. override with libc++
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 "macosx${_developer_sdk_version}" 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()

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

if(CMAKE_COMPILER_IS_GNUCC)
Expand Down
2 changes: 1 addition & 1 deletion standard/standard-configVersion.cmake.in
Expand Up @@ -73,7 +73,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
endif()
endif()

if(NOT @ARG_VERSION_PRERELEASE@ STREQUAL "") #handle prerelease versions
if(NOT @ARG_VERSION_PRERELEASE@ STREQUAL "") # handle prerelease versions
set(PACKAGE_FIND_VERSION_PRERELEASE "${@ARG_NAME@_FIND_VERSION_PRERELEASE}")
if(NOT PACKAGE_FIND_VERSION_PRERELEASE)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
Expand Down
8 changes: 4 additions & 4 deletions standard/toolchain-android.cmake
Expand Up @@ -2,17 +2,17 @@ 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...
# 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...
if(NOT LLVM_ANDROID_TOOLCHAIN_DIR)
set(LLVM_ANDROID_TOOLCHAIN_DIR $ENV{LLVM_ANDROID_TOOLCHAIN_DIR})
else()
set(ENV{LLVM_ANDROID_TOOLCHAIN_DIR} ${LLVM_ANDROID_TOOLCHAIN_DIR} CACHE PATH)
endif()

find_path(ANDROID_NDK_ROOT bin/${ANDROID_NDK_TOOL_PREFIX}-gcc${_exe_suffix} PATHS
${LLVM_ANDROID_TOOLCHAIN_DIR}${_ndk_suffix} #legacy variable
${LLVM_ANDROID_TOOLCHAIN_DIR}${_ndk_suffix} # legacy variable
/opt/android-standalone-toolchain${_ndk_suffix}
${LLVM_ANDROID_TOOLCHAIN_DIR}
/opt/android-standalone-toolchain
Expand Down