Bump the minimum required CMake to 3.7. CMake 3.1 is required for the `CMAKE_C_STANDARD` and `CMAKE_C_STANDARD_REQUIRED` options to take effect. Relying on CMake to control the compiler this way allows us to avoid having to rebuild the logic for detecting the appropriate flags and ensuring that the compiler is able to support the necessary language version.
The `COMPILE_LANGUAGE` generator expression was introduced in CMake 3.3.
Debian Jessie has an older CMake version bundled, which prevents
building on that platform without manually building CMake. This
uses a more error-prone mechanism of requiring the commonmark developer
to explicitly invoke `cmark_add_compile_options` on the target to ensure
that the flags are propagated for the targets without using the
generator expression. Adding the options unconditionally prevents using
CMark in a build with a non-C programming language.
Fixes: #384
This reverts a change by @compnerd in commit
b6ffaca93e.
We don't want this for api_tests, as it triggers this warning:
```
CMake Warning (dev) at api_test/CMakeLists.txt:1 (add_executable):
Policy CMP0063 is not set: Honor visibility properties for all target
types. Run "cmake --help-policy CMP0063" for policy details. Use the
cmake_policy command to set the policy and suppress this warning.
Target "api_test" of type "EXECUTABLE" has the following visibility
properties set for C:
C_VISIBILITY_PRESET
For compatibility CMake is not honoring them for this target.
This warning is for project developers. Use -Wno-dev to suppress it.
```
man pages are extremely useful, but are not generally available on
Windows. This changes the install condition to check for the Windows
cross-compile rather than the toolchain in use. It is possible to build
for Windows using clang in the GNU driver.
* build: inline a variable
* build: use `LINKER_LANGUAGE` property for C++ runtime
Rather than explicitly name the C++ runtime, use the `LINKER_LANGUAGE`
property to use the driver to spell the C++ runtime appropriately.
* build: use CMake to control C standard
Rather than use compiler specific flags to control the language
standard, indicate to CMake the desired standard.
* build: use the correct variable
These flags are being applied to the *C* compiler, check the C compiler,
not the C++ compiler.
* build: loosen the compiler check
This loosens the compiler identifier check to enable matching AppleClang
which is the identifier for the Xcode compiler.
* build: hoist shared flags to top-level CMakeLists
This hoists the common shared flags handling to the top-level CMakeLists
from sub-layers. This prevents the duplication of the handling.
* build: remove duplicated flags
This is unnecessary, `/TP` is forced on all MSVC builds, no need to
duplicate the flag for older versions.
* build: loosen C compiler identifier check
Loosen the check to a match rather than equality check, this allows it
to match AppleClang which is the identifier for the Apple vended clang
compiler part of Xcode.
* build: use `add_compile_options`
Use `add_compile_options` rather than modify `CMAKE_C_FLAGS`. The
latter is meant to be only modified by the user, not the package
developer.
* build: hoist sanitizer flags to global state
This moves the CMAKE_C_FLAGS handling to the top-level and uses
`add_compile_options` rather than modifying the user controlled flags.
* build: hoist `-fvisibilty` flags to top-level
These are global settings, hoist them to the top level.
* build: hoist the debug flag handling
Use a generator expression and hoist the flag handling for the debug
build.
* build: hoist the profile flag handling
This is a global flag, hoist it to the top level and use
`add_compile_options` rather than modify the user controlled flags.
* build: remove incorrect variable handling
This seemed to be attempting to set the linker not the linker flags for
the profile configuration. This variable is not used, do not set it.
* build: remove unused CMake includes
In the file CMakeLists.txt, the required version should be placed to top line. The information could not used at CMake/Modules/CYGWIN.cmake under Cygwin.