aboutsummaryrefslogtreecommitdiff
path: root/CMakeModules
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-08-31 14:09:51 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-09-01 13:08:52 +0200
commit9d7701c370f06be663f2a485507d388ab5194ca8 (patch)
treeaea0b55017b7a6003dbd042cdb113ec6fb5ab2e9 /CMakeModules
parentd55e5c77d3cd2a1be150666e92e5b4f3b922f0fc (diff)
downloadcmix-9d7701c370f06be663f2a485507d388ab5194ca8.tar.gz
cmix-9d7701c370f06be663f2a485507d388ab5194ca8.tar.bz2
cmix-9d7701c370f06be663f2a485507d388ab5194ca8.zip
Added a CMake system to easily add and choose crypto implementations.
Diffstat (limited to 'CMakeModules')
-rw-r--r--CMakeModules/curve25519_implementations.cmake3
-rw-r--r--CMakeModules/get_target_name.cmake10
-rw-r--r--CMakeModules/implementations.cmake23
-rw-r--r--CMakeModules/rsa_implementations.cmake3
4 files changed, 39 insertions, 0 deletions
diff --git a/CMakeModules/curve25519_implementations.cmake b/CMakeModules/curve25519_implementations.cmake
new file mode 100644
index 0000000..6be8dca
--- /dev/null
+++ b/CMakeModules/curve25519_implementations.cmake
@@ -0,0 +1,3 @@
+include(implementations)
+
+DefineImplementations("curve25519")
diff --git a/CMakeModules/get_target_name.cmake b/CMakeModules/get_target_name.cmake
new file mode 100644
index 0000000..6e7c6fd
--- /dev/null
+++ b/CMakeModules/get_target_name.cmake
@@ -0,0 +1,10 @@
+
+function(get_target_name target_name)
+
+get_filename_component(implementation ${CMAKE_CURRENT_LIST_DIR} NAME)
+get_filename_component(implementation_path ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
+get_filename_component(algorithm ${implementation_path} NAME)
+
+set(${target_name} "${algorithm}-${implementation}" PARENT_SCOPE)
+
+endfunction(get_target_name)
diff --git a/CMakeModules/implementations.cmake b/CMakeModules/implementations.cmake
new file mode 100644
index 0000000..aa6a8bf
--- /dev/null
+++ b/CMakeModules/implementations.cmake
@@ -0,0 +1,23 @@
+function(DefineImplementations prefix)
+
+ FILE(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${prefix}/*)
+
+ set(implementations "")
+ foreach(child ${children})
+ IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${prefix}/${child})
+ LIST(APPEND implementations ${child})
+ ENDIF()
+ ENDFOREACH()
+
+ list(LENGTH implementations nr_implementations)
+
+ if(nr_implementations EQUAL 0)
+ message(FATAL_ERROR "Cannot call DefineImplementations with an empty implementations list.")
+ endif()
+
+ list(GET implementations 0 default)
+ set(${prefix}_implementations ${implementations} PARENT_SCOPE)
+ set(${prefix}_implementation "${default}" CACHE STRING "${prefix} implementation chosen at configure time")
+ set_property(CACHE ${prefix}_implementation PROPERTY STRINGS ${implementations})
+
+endfunction(DefineImplementations)
diff --git a/CMakeModules/rsa_implementations.cmake b/CMakeModules/rsa_implementations.cmake
new file mode 100644
index 0000000..171058f
--- /dev/null
+++ b/CMakeModules/rsa_implementations.cmake
@@ -0,0 +1,3 @@
+include(implementations)
+
+DefineImplementations("rsa")