summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeCommands/target_compile_features
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2013-11-04 00:15:43 (GMT)
committerStephen Kelly <steveire@gmail.com>2014-05-14 22:15:18 (GMT)
commite0890d03a48d12904ffe24aa94fb2847d8d5f4e7 (patch)
tree820631dcc5cd8c95111dbfa7d33e1a59d554f8a4 /Tests/CMakeCommands/target_compile_features
parent775458dede98d28fe81ac878541a6ead735443fc (diff)
downloadCMake-e0890d03a48d12904ffe24aa94fb2847d8d5f4e7.zip
CMake-e0890d03a48d12904ffe24aa94fb2847d8d5f4e7.tar.gz
CMake-e0890d03a48d12904ffe24aa94fb2847d8d5f4e7.tar.bz2
Features: Extend concept to C language.
Add properties and variables corresponding to CXX equivalents. Add features for c_function_prototypes (C90), c_restrict (C99), c_variadic_macros (C99) and c_static_assert (C11). This feature set can be extended later. Add a <PREFIX>_RESTRICT symbol define to WriteCompilerDetectionHeader to conditionally represent the c_restrict feature.
Diffstat (limited to 'Tests/CMakeCommands/target_compile_features')
-rw-r--r--Tests/CMakeCommands/target_compile_features/CMakeLists.txt42
-rw-r--r--Tests/CMakeCommands/target_compile_features/lib_restrict.c9
-rw-r--r--Tests/CMakeCommands/target_compile_features/lib_restrict.h7
-rw-r--r--Tests/CMakeCommands/target_compile_features/main.c12
-rw-r--r--Tests/CMakeCommands/target_compile_features/restrict_user.c14
5 files changed, 73 insertions, 11 deletions
diff --git a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
index 62e3ce0..9b35f27 100644
--- a/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
+++ b/Tests/CMakeCommands/target_compile_features/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0)
project(target_compile_features)
-if (NOT CMAKE_CXX_COMPILE_FEATURES)
+if (NOT CMAKE_CXX_COMPILE_FEATURES AND NOT CMAKE_C_COMPILE_FEATURES)
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test_dummy.cpp"
"int main(int,char**) { return 0; }\n"
)
@@ -11,15 +11,35 @@ endif()
set(CMAKE_VERBOSE_MAKEFILE ON)
-add_executable(target_compile_features main.cpp)
-target_compile_features(target_compile_features
- PRIVATE cxx_auto_type
-)
+if (CMAKE_C_COMPILE_FEATURES)
+ add_executable(target_compile_features main.c)
+ target_compile_features(target_compile_features
+ PRIVATE c_restrict
+ )
-add_library(lib_auto_type lib_auto_type.cpp)
-target_compile_features(lib_auto_type
- PUBLIC cxx_auto_type
-)
+ add_library(lib_restrict lib_restrict.c)
+ target_compile_features(lib_restrict
+ PUBLIC c_restrict
+ )
-add_executable(lib_user lib_user.cpp)
-target_link_libraries(lib_user lib_auto_type)
+ add_executable(restrict_user restrict_user.c)
+ target_link_libraries(restrict_user lib_restrict)
+endif()
+
+if (CMAKE_CXX_COMPILE_FEATURES)
+ if (CMAKE_C_COMPILE_FEATURES)
+ set(target_suffix _cxx)
+ endif()
+ add_executable(target_compile_features${target_suffix} main.cpp)
+ target_compile_features(target_compile_features${target_suffix}
+ PRIVATE cxx_auto_type
+ )
+
+ add_library(lib_auto_type lib_auto_type.cpp)
+ target_compile_features(lib_auto_type
+ PUBLIC cxx_auto_type
+ )
+
+ add_executable(lib_user lib_user.cpp)
+ target_link_libraries(lib_user lib_auto_type)
+endif()
diff --git a/Tests/CMakeCommands/target_compile_features/lib_restrict.c b/Tests/CMakeCommands/target_compile_features/lib_restrict.c
new file mode 100644
index 0000000..049c1b0
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_restrict.c
@@ -0,0 +1,9 @@
+
+#include "lib_restrict.h"
+
+int foo(int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/lib_restrict.h b/Tests/CMakeCommands/target_compile_features/lib_restrict.h
new file mode 100644
index 0000000..eca22be
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/lib_restrict.h
@@ -0,0 +1,7 @@
+
+#ifndef LIB_RESTRICT_H
+#define LIB_RESTRICT_H
+
+int foo(int * restrict a, int * restrict b);
+
+#endif
diff --git a/Tests/CMakeCommands/target_compile_features/main.c b/Tests/CMakeCommands/target_compile_features/main.c
new file mode 100644
index 0000000..831c5eb2
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/main.c
@@ -0,0 +1,12 @@
+
+int foo(int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return 0;
+}
+
+int main()
+{
+ return 0;
+}
diff --git a/Tests/CMakeCommands/target_compile_features/restrict_user.c b/Tests/CMakeCommands/target_compile_features/restrict_user.c
new file mode 100644
index 0000000..d47b847
--- /dev/null
+++ b/Tests/CMakeCommands/target_compile_features/restrict_user.c
@@ -0,0 +1,14 @@
+
+#include "lib_restrict.h"
+
+int bar(int * restrict a, int * restrict b)
+{
+ (void)a;
+ (void)b;
+ return foo(a, b);
+}
+
+int main()
+{
+ return 0;
+}