This repository contains various CMake utility modules associated with the Solar platform integration and utility library for Qt.
Here is a list of the CMake modules available and the functionality they provide:
CMake currently lacks a built-in way to detect the architecture (i386, x86_64, armv7, etc.) of the target platform.
- target_architecture(<output_var>): sets output_var to the processor architecture of the target platform. This function works even when cross compiling as it invokes the compiler itself and uses some preprocessor trickery to determine the architecture by checking for the precense of C symbols such as
__i386__
and__ARM_ARCH_7__
.
OS X / PowerPC note: this function causes CMake to throw an error if any of the architectures passed toCMAKE_OSX_ARCHITECTURES
are invalid. Currently the list of valid architectures includes only i386 and x86_64, since Apple has not officially supported PowerPC development since the OS X 10.5 SDK. However if you're feeling adventurous, you can set the CMake variableppc_support
to TRUE before including this module, and ppc and ppc64 will be accepted as valid architectures.
There is an Python script included (test.py) that can be used to test this module (and others) with various generators and ensure that the correct results are returned.
Provides various Git-related functions.
-
git_shorttag(<rev_id>): retrieves the short tag of the HEAD commit and stores the result in rev_id. This can be useful for generating package filenames or in a config.h header.
-
git_append_shorttag(<var_name>): calls git_shorttag and appends "git-" and the result to the given variable. This is useful for generating version numbers. For example if var_name contains "1.0.2", it will contain something like "1.0.2-git0a1b2c" after calling this function.
Provides various Qt-related functions.
-
qt_transform_sources(<output_var> <sources>): operates on a list of source files and executes all necessary commands to run the various Qt programs such as rcc, uic, moc and lrelease making the use of Qt within CMake very transparent. Files are also grouped into different folders in the IDE for easier code navigation and sorted alphabetically. Simply call
qt_transform_sources(my_sources "${my_sources}")
to process the source list for any target. -
use_qt_sdk_locations(): adds some extra paths to CMAKE_PREFIX_PATHS allowing CMake to find Qt installations in the Qt SDK for Windows folders. This is a macro.
Provides various utility functions…
-
group_by_folder(<relative_to_folder> <files>): Groups a list of source files according to their directory hierarchy
relative_to_folder should be the prefix to strip of the beginning of each file path before doing categorization.
files should be a list of absolute paths to be grouped.
For example, given the file path: /Developer/Sources/solar-cmake/foo/bar/test.c, if relative_to_folder is set to /Developer/Sources/solar-cmake, the IDE folder name of the file test.c will be set to "foo\\bar". -
is_symbol_defined(<output_variable> <symbol>): Determines whether the current C compiler defines the given preprocessor symbol and stores the result in output_variable.
This function utilizes try_compile and some preprocessor trickery to determine whether the given symbol is defined. For example, after calling is_symbol_defined(is_64_bit __x86_64__), the variable is_64_bit will be set to TRUE if compiling for a 64-bit environment.
To include all modules, simply include Solar.cmake. This file also sets several variables after inclusion:
-
From
target_architecture
...CMAKE_TARGET_ARCHITECTURES
- contains either the name of the target architecture, or if building universal binaries on OS X, a list of target architecturesCMAKE_TARGET_ARCHITECTURE_UNIVERSAL
- TRUE ifCMAKE_TARGET_ARCHITECTURES
contains more than one architecture; FALSE in all other casesCMAKE_TARGET_ARCHITECTURE_CODE
- the string "universal" ifCMAKE_TARGET_ARCHITECTURE_UNIVERSAL
is TRUE, otherwise equivalent toCMAKE_TARGET_ARCHITECTURES
; this can be useful for filename generation
-
CMAKE_COMPILER_IS_CLANGXX
- TRUE if the current C/C++ compiler is Clang/LLVM -
CMAKE_USER_EXECUTABLE_SUFFIX
- .app on Apple platforms, otherwise equivalent toCMAKE_EXECUTABLE_SUFFIX
-
calls
use_qt_sdk_locations
If you've found a bug, please create an issue here on GitHub!
https://github.com/petroules/solar-cmake/issues
Q: System requirements?
A: CMake 2.6 (as far as I know) and Python 2.7 for the testing script.
Jake Petroules
Copyright (c) 2012 Petroules Corporation. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.