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

Updates from standard #974

Merged
merged 19 commits into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a48dd9b
these variables do not need to be set by the version.config file.
Jun 1, 2016
9041be7
CMAKE_BINARY_DIR may contain spaces
codemercenary Jun 18, 2016
e970347
Merge pull request #2 from leapmotion/fix-quotedstr
yeswalrus Jun 18, 2016
06986c0
Pull in Changes from https://github.com/leapmotion/leapserial/pull/110
Aug 1, 2016
98793e6
Add separate function, standard_project_preinit and _postinit for peo…
Aug 1, 2016
a4f6e2c
Merge pull request #5 from leapmotion/standard-project
codemercenary Aug 1, 2016
30a9b6e
remove unnessecary and incorrect set of CMAKE_C_FLAGS and CMAKE_CXX_F…
Aug 10, 2016
61f387e
Merge pull request #6 from leapmotion/remove-unused-cmake
codemercenary Aug 10, 2016
adc8379
remove unnecessary conditional
Aug 10, 2016
ee0d9b8
Merge pull request #7 from leapmotion/fix-pic
codemercenary Aug 10, 2016
682555e
Update README.md with StandardPackage description
yeswalrus Aug 10, 2016
a9221ce
Merge pull request #8 from leapmotion/upd-readme
codemercenary Aug 10, 2016
66b6bec
fix scope problem with StandardProject
Aug 10, 2016
2bf5bdc
Merge pull request #9 from leapmotion/fix-standardproject
codemercenary Aug 10, 2016
2660f83
Merge remote-tracking branch 'standard/master' into upd-standard
Aug 10, 2016
9b204f2
replace set_standard_output_variables with standard_project
Aug 10, 2016
4690ba4
the escape quote must be recursively escaped since it gets re-parsed …
Aug 11, 2016
0cfc7f8
Merge pull request #10 from leapmotion/fix-combined-installer
yeswalrus Aug 11, 2016
6001a45
Merge remote-tracking branch 'standard/master' into upd-standard
Aug 11, 2016
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
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
cmake_minimum_required(VERSION 3.4)
include(version.cmake)
project(Autowiring VERSION ${autowiring_VERSION})
include("standard/Standard.cmake")

standard_project(Autowiring VERSION ${autowiring_VERSION})

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules")
include(AddPCH)
include(ConditionalSources)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Standard calls
set_standard_output_variables()

# We have unit test projects via googletest, they're added in the places where they are defined
enable_testing()

Expand Down
6 changes: 3 additions & 3 deletions standard/CombinedInstaller.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function(combined_installer)
if(CMAKE_CONFIGURATION_TYPES)
default_value(ARG_CONFIGS ${CMAKE_CONFIGURATION_TYPES})
endif()
default_value(ARG_WIXFILE ${CMAKE_BINARY_DIR}/CMakeFiles/standard_WixFile.wxs)
default_value(ARG_WIXFILE "${CMAKE_BINARY_DIR}/CMakeFiles/standard_WixFile.wxs")
default_value(ARG_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
default_value(ARG_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")

Expand Down Expand Up @@ -113,13 +113,13 @@ function(combined_installer)
list(
APPEND
CPACK_INSTALL_COMMANDS
"${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --config ${ONE_CONFIG}"
"${CMAKE_COMMAND} --build \\\"${CMAKE_BINARY_DIR}\\\" --config ${ONE_CONFIG}"
"${CMAKE_COMMAND} -DBUILD_TYPE=${ONE_CONFIG} -P \\\"${SELF}/cmake_package.cmake\\\""
)
endforeach()
else()
set(CPACK_INSTALL_COMMANDS
"${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}"
"${CMAKE_COMMAND} --build \\\"${CMAKE_BINARY_DIR}\\\""
"${CMAKE_COMMAND} -P \\\"${SELF}/cmake_package.cmake\\\""
)
endif()
Expand Down
16 changes: 10 additions & 6 deletions standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@ Provides a sort of global header that can be used by all customers of this libra
include("standard/Standard.cmake")
```

### [SetStandardOutputVariables](SetStandardOutputVariables.cmake)
### [StandardProject](StandardProject.cmake)

There are a lot of options that have to be configured in order to get CMake building on all platforms with broadly compatible options for C++11. This file handles all of that work, but also handles the task of standardizing the build directories and making sure that your compiler of choice can actually handle C++11.

This module defines one function taking no arguments which should be invoked as so:
This module defines a wrapper around project, which is itself a wrapper around project() with a pre-initialization and post-initialization function called in the correct order. This is required because some variables must be set prior to the first call to project, while other settings are conditional based on information that is only available after.

```CMake
set_standard_output_variables()
standard_project(project VERSION version [LANGUAGES ...])
# OR
standard_project_preinit()
project(...)
standard_project_postinit()

# Now your source code
add_subdirectory(src)
Expand Down Expand Up @@ -61,8 +65,8 @@ This module ensures this by doing the following:
0. Figures out the architecture that you're targeting. Right now we support ARM, x86, and x64
0. Creates a file called `MyLibraryTargets.cmake` which includes all of the projects in your library which were installed with the cmake [`install`](https://cmake.org/cmake/help/v3.5/command/install.html) command.
0. Creates `projectname-config.cmake` which specifies the right include directories for installed and local builds, and brings in `MyLibraryTargets.cmake`
0. Creates `projectname-configVersion` which...
* ...uses semantic versioning to ensure that `find_package(mylibrary 2.0.2)` correctly matches version `2.0.5` but not version `1.9.2`
0. Creates `projectname-configVersion` which...
* ...uses semantic versioning to ensure that `find_package(mylibrary 2.0.2)` correctly matches version `2.0.5` but not version `1.9.2`
* ...validates architecture compatibility by not allowing an ARM build to accidentally link with an x86 library
* ...handles the case of fat binaries, where both x86 and x64 builds can link to the same spot

Expand All @@ -80,7 +84,7 @@ install(
CONFIGURATIONS ${CMAKE_CONFIGURATION_TYPES}
)
install_headers(TARGET MyLibrary)
generate_version()
generate_version()
```

### [CombinedInstaller](CombinedInstaller.cmake)
Expand Down
94 changes: 0 additions & 94 deletions standard/SetStandardOutputVariables.cmake

This file was deleted.

3 changes: 1 addition & 2 deletions standard/Standard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

# Need these for the rest of these scripts to work properly
include(CTest)
include(CheckTypeSize)

# Omnibus include file that brings in all standard CMake scripts
include(CombinedInstaller)
include(DefaultValue)
include(GenerateVersion)
include(SetStandardOutputVariables)
include(StandardProject)
include(InstallHeaders)
129 changes: 129 additions & 0 deletions standard/StandardProject.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#[[
Simple project setup. There's a fair amount of boiler plate that has to happen
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.
* 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
* Ensures compilation happens with visibility set to hidden by default
* Builds fat binaries on mac
* Sets standard_BUILD* variables for consumption later down the line.
* Enforces the project has a VERSION set.
]]

#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)
message(FATAL_ERROR "Standard compliant projects must specify a version")
endif()

set(_language_arg "")
if(standard_LANGUAGES)
set(_language_arg LANGUAGES ${standard_LANGUAGES})
endif()

standard_project_preinit()
project(${project_name} VERSION ${standard_VERSION} ${_language_arg})
standard_project_postinit()
endmacro()

function(standard_project_preinit)
# Pre-initialization steps - these variables must be set before the first call to
# project()
if(APPLE)
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(CMAKE_OSX_ARCHITECTURES "arm" CACHE STRING "Mac OS X build architectures")
else()
# Build Fat binaries on OSX by default
set(CMAKE_OSX_ARCHITECTURES "x86_64;i386" CACHE STRING "Mac OS X build architectures")
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
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm")
set(standard_BUILD_ARM ON CACHE INTERNAL "")
set(standard_BUILD_ARCHITECTURES "arm" CACHE INTERNAL "")
set(standard_BUILD_64 OFF CACHE INTERNAL "")
elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64;i386")
set(standard_BUILD_ARCHITECTURES x64 x86 CACHE INTERNAL "")
set(standard_BUILD_64 ON CACHE INTERNAL "")
elseif(CMAKE_SIZEOF_VOID_P STREQUAL 4)
set(standard_BUILD_ARCHITECTURES "x86" CACHE INTERNAL "")
set(standard_BUILD_64 OFF CACHE INTERNAL "")
else()
set(standard_BUILD_ARCHITECTURES "x64" CACHE INTERNAL "")
set(standard_BUILD_64 ON CACHE INTERNAL "")
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
# 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 CACHE INTERNAL "Executable Output directory")

# Libraries not only all wind up in the libraries directory, but we also keep them all together
# here by putting them in the same place, regardless of whether they are debug or release. This
# makes globbing them together much easier.
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "Shared Library output directory")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "Shared Library output directory")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "Shared Library output directory")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "Static Library output directory")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "Static Library output directory")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib CACHE INTERNAL "Static Library output directory")

# Postfix on all debug libraries should be "d"
set(CMAKE_DEBUG_POSTFIX d${CMAKE_DEBUG_POSTFIX} CACHE INTERNAL "Debug postfix")

# 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)
set(CMAKE_${config}_POSTFIX "${CMAKE_${config}_POSTFIX}64" CACHE INTERNAL "$[config} Postfix")
endforeach()
endif()

# We want Position independent code for all builds
set(CMAKE_POSITION_INDEPENDENT_CODE ON CACHE INTERNAL "Position-Independent Code")
endfunction()

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

include(CTest)

if(CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.8")
message(FATAL_ERROR "GCC version 4.8 minimum is required to build ${CMAKE_PROJECT_NAME}")
endif()
elseif (MSVC)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "18.0")
message(FATAL_ERROR "MSVC 2013 minimum is required to build ${CMAKE_PROJECT_NAME}")
endif()
endif()
message(STATUS "Compiler version ${CMAKE_CXX_COMPILER_VERSION}")

# Always use c++11 compiler with hidden visibility
if(NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility=hidden" CACHE INTERNAL "C++ Compiler Flags")
endif()

# Clang needs special additional flags to build with C++11
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
message(STATUS "AppleClang C++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++" CACHE INTERNAL "C++ Compiler Flags")
set(CMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++" CACHE INTERNAL "XCode Clang C++ STL Version")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Clang C++11")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}-lstdc++" CACHE INTERNAL "C++ EXE Linker Flags")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
message(STATUS "GCC C++11")
endif()
endfunction()
7 changes: 2 additions & 5 deletions standard/standard-configVersion.cmake.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
set(PACKAGE_VERSION "@ARG_VERSION@")
set(PACKAGE_VERSION_MAJOR "@ARG_VERSION_MAJOR@")
set(PACKAGE_VERSION_MINOR "@ARG_VERSION_MINOR@")
set(PACKAGE_VERSION_PATCH "@ARG_VERSION_PATCH@")

if(@ARG_NAME@_DEBUG)
message(STATUS "Debug mode on")
Expand Down Expand Up @@ -93,12 +90,12 @@ elseif(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
message(STATUS "Our version is less than the requested one, trivially incompatible")
endif()
set(PACKAGE_VERSION_COMPATIBLE FALSE)
elseif(NOT PACKAGE_FIND_VERSION_MINOR EQUAL PACKAGE_VERSION_MINOR)
elseif(NOT PACKAGE_FIND_VERSION_MINOR EQUAL "@ARG_VERSION_MINOR@")
if(@ARG_NAME@_DEBUG)
message(STATUS "Minor version mismatch, requested minor is ${PACKAGE_FIND_VERSION_MINOR}, this version is ${PACKAGE_VERSION_MINOR}")
endif()
set(PACKAGE_VERSION_COMPATIBLE FALSE)
elseif(NOT PACKAGE_FIND_VERSION_MAJOR EQUAL PACKAGE_VERSION_MAJOR)
elseif(NOT PACKAGE_FIND_VERSION_MAJOR EQUAL "@ARG_VERSION_MAJOR@")
if(@ARG_NAME@_DEBUG)
message(STATUS "Major version mismatch, failure.")
endif()
Expand Down
3 changes: 0 additions & 3 deletions standard/toolchain-arm32.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

list(APPEND CMAKE_CXX_FLAGS "-fPIC")
list(APPEND CMAKE_C_FLAGS "-fPIC")

foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
string(TOUPPER ${config} config)
string(CONCAT CMAKE_${config}_POSTFIX "${CMAKE_${config}_POSTFIX}" "64")
Expand Down
3 changes: 0 additions & 3 deletions standard/toolchain-arm64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

list(APPEND CMAKE_CXX_FLAGS "-fPIC")
list(APPEND CMAKE_C_FLAGS "-fPIC")

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