Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Add CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslo committed Jul 22, 2018
1 parent 8619db8 commit 725c515
Show file tree
Hide file tree
Showing 29 changed files with 1,819 additions and 0 deletions.
535 changes: 535 additions & 0 deletions CMakeLists.txt

Large diffs are not rendered by default.

536 changes: 536 additions & 0 deletions cmake/HunterGate.cmake

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions cmake/module/libsodium_add_c_flag.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
include(CheckCCompilerFlag) # check_c_compiler_flag

function(libsodium_add_c_flag)
if("${ARGC}" STREQUAL "1")
set(flag "${ARGV0}")
set(var_name "")
elseif("${ARGC}" STREQUAL "2")
set(flag "${ARGV0}")
set(var_name "${ARGV1}")
else()
message(FATAL_ERROR "Unexpected: ${ARGC}")
endif()

unset(__libsodium_check CACHE)

message(STATUS "Check flag: '${flag}'")
check_c_compiler_flag(${flag} __libsodium_check)

if(__libsodium_check)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
set("${var_name}" TRUE PARENT_SCOPE)
else()
set("${var_name}" FALSE PARENT_SCOPE)
endif()

unset(__libsodium_check CACHE)
endfunction()
36 changes: 36 additions & 0 deletions cmake/module/libsodium_add_have_macro.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
include(CMakeParseArguments) # cmake_parse_arguments
include(CheckFunctionExists) # check_function_exists

function(libsodium_add_have_macro)
set(optional "")
set(one FUNCTION CMAKE_VAR CPP_MACRO)
set(multiple "")

# Introduce:
# * x_FUNCTION
# * x_CMAKE_VAR
# * x_CPP_MACRO
cmake_parse_arguments(x "${optional}" "${one}" "${multiple}" "${ARGV}")

if(NOT "${x_UNPARSED_ARGUMENTS}" STREQUAL "")
message(FATAL_ERROR "Unparsed arguments: ${x_UNPARSED_ARGUMENTS}")
endif()

if("${x_FUNCTION}" STREQUAL "")
message(FATAL_ERROR "FUNCTION required")
endif()

if("${x_CMAKE_VAR}" STREQUAL "")
message(FATAL_ERROR "CMAKE_VAR required")
endif()

if("${x_CPP_MACRO}" STREQUAL "")
message(FATAL_ERROR "CPP_MACRO required")
endif()

check_function_exists("${x_FUNCTION}" "${x_CMAKE_VAR}")

if(${x_CMAKE_VAR})
add_definitions("-D${x_CPP_MACRO}=1")
endif()
endfunction()
33 changes: 33 additions & 0 deletions cmake/module/libsodium_try_compile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include(CMakeParseArguments) # cmake_parse_arguments

function(libsodium_try_compile)
set(optional "")
set(one SOURCE CMAKE_VAR CPP_MACRO COMPILE_DEFINITIONS)
set(multiple "")

# Introduce:
# * x_SOURCE
# * x_CMAKE_VAR
# * x_CPP_MACRO
# * x_COMPILE_DEFINITIONS
cmake_parse_arguments(x "${optional}" "${one}" "${multiple}" "${ARGV}")

if(NOT "${x_UNPARSED_ARGUMENTS}" STREQUAL "")
message(FATAL_ERROR "Unparsed arguments: ${x_UNPARSED_ARGUMENTS}")
endif()

if("${x_CMAKE_VAR}" STREQUAL "")
message(FATAL_ERROR "CMAKE_VAR required")
endif()

try_compile(
${x_CMAKE_VAR}
"${CMAKE_CURRENT_BINARY_DIR}/try_compile"
"${CMAKE_CURRENT_LIST_DIR}/cmake/try_compile/${x_SOURCE}"
COMPILE_DEFINITIONS "${x_COMPILE_DEFINITIONS}"
)

if(${x_CMAKE_VAR} AND NOT "${x_CPP_MACRO}" STREQUAL "")
add_definitions("-D${x_CPP_MACRO}=1")
endif()
endfunction()
6 changes: 6 additions & 0 deletions cmake/template/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@PACKAGE_INIT@

find_package(Threads REQUIRED)

include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake")
check_required_components("@PROJECT_NAME@")
13 changes: 13 additions & 0 deletions cmake/try_compile/amd64_asm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
# error Windows x86_64 calling conventions are not supported yet
# endif
/* neat */
#else
# error !x86_64
#endif

void main()
{
__asm__("pxor %xmm12,%xmm6");
}
6 changes: 6 additions & 0 deletions cmake/try_compile/atomic_ops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main(void)
{
static volatile int _sodium_lock;
__sync_lock_test_and_set(&_sodium_lock, 1);
__sync_lock_release(&_sodium_lock);
}
14 changes: 14 additions & 0 deletions cmake/try_compile/avx2intrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifdef __native_client__
# error NativeClient detected - Avoiding AVX2 opcodes
#endif

#pragma GCC target("avx2")

#include <immintrin.h>

int main(void)
{
__m256 x = _mm256_set1_ps(3.14);
__m256 y = _mm256_permutevar8x32_ps(x, _mm256_set1_epi32(42));
return _mm256_movemask_ps(_mm256_cmp_ps(x, y, _CMP_NEQ_OQ));
}
13 changes: 13 additions & 0 deletions cmake/try_compile/avx512fintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifdef __native_client__
# error NativeClient detected - Avoiding AVX512F opcodes
#endif

#pragma GCC target("avx512f")

#include <immintrin.h>

int main(void)
{
__m512i x = _mm512_setzero_epi32();
__m512i y = _mm512_permutexvar_epi64(_mm512_setr_epi64(0, 1, 4, 5, 2, 3, 6, 7), x);
}
13 changes: 13 additions & 0 deletions cmake/try_compile/avx_asm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if defined(__amd64) || defined(__amd64__) || defined(__x86_64__)
# if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(_WIN32) || defined(_WIN64)
# error Windows x86_64 calling conventions are not supported yet
# endif
/* neat */
#else
# error !x86_64
#endif

void main()
{
__asm__ __volatile__ ("vpunpcklqdq %xmm0,%xmm13,%xmm0");
}
12 changes: 12 additions & 0 deletions cmake/try_compile/avxintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifdef __native_client__
# error NativeClient detected - Avoiding AVX opcodes
#endif

#pragma GCC target("avx")

#include <immintrin.h>

int main(void)
{
_mm256_zeroall();
}
8 changes: 8 additions & 0 deletions cmake/try_compile/cpuid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
void main()
{
unsigned int cpu_info[4];
__asm__ __volatile__ ("xchgl %%ebx, %k1; cpuid; xchgl %%ebx, %k1" :
"=a" (cpu_info[0]), "=&r" (cpu_info[1]),
"=c" (cpu_info[2]), "=d" (cpu_info[3]) :
"0" (0U), "2" (0U));
}
8 changes: 8 additions & 0 deletions cmake/try_compile/emmintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma GCC target("sse2")

#include <emmintrin.h>

int main(void)
{
__m128d x = _mm_setzero_pd();
}
8 changes: 8 additions & 0 deletions cmake/try_compile/limit_macros.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <limits.h>
#include <stdint.h>

void main()
{
(void) SIZE_MAX;
(void) UINT64_MAX;
}
7 changes: 7 additions & 0 deletions cmake/try_compile/memset.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <string.h>

int main(void)
{
char dummy[42];
(void) memset_s(dummy, (rsize_t) sizeof dummy, 0, (rsize_t) sizeof dummy);
}
7 changes: 7 additions & 0 deletions cmake/try_compile/native_client.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if !defined(__native_client__)
# error "__native_client__ not defined"
#endif

int main(void)
{
}
10 changes: 10 additions & 0 deletions cmake/try_compile/pmmintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma GCC target("sse3")

#include <pmmintrin.h>

int main(void)
{
__m128 x = _mm_addsub_ps(
_mm_cvtpd_ps(_mm_setzero_pd()), _mm_cvtpd_ps(_mm_setzero_pd())
);
}
13 changes: 13 additions & 0 deletions cmake/try_compile/rdrand.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifdef __native_client__
# error NativeClient detected - Avoiding RDRAND opcodes
#endif

#pragma GCC target("rdrnd")

#include <immintrin.h>

int main(void)
{
unsigned long long x;
_rdrand64_step(&x);
}
8 changes: 8 additions & 0 deletions cmake/try_compile/smmintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma GCC target("sse4.1")

#include <smmintrin.h>

int main(void)
{
__m128i x = _mm_minpos_epu16(_mm_setzero_si128());
}
30 changes: 30 additions & 0 deletions cmake/try_compile/ti_mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef __GNUC__
# error mode(TI) is a gcc extension
#endif

#if defined(__clang__) && !defined(__x86_64__)
# error clang doesn't properly compile smult_curve25519_donna_c64.c
#endif

#ifndef NATIVE_LITTLE_ENDIAN
# error donna_c64 currently requires a little endian CPU
#endif

#ifdef EMSCRIPTEN
# error emscripten currently supports only shift operations on integers \
# larger than 64 bits
#endif

#include <stdint.h>

typedef unsigned uint128_t __attribute__((mode(TI)));

void fcontract(uint128_t *t)
{
*t += 0x8000000000000 - 1;
}

void main()
{
(void) fcontract;
}
8 changes: 8 additions & 0 deletions cmake/try_compile/tmmintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma GCC target("ssse3")

#include <tmmintrin.h>

int main(void)
{
__m64 x = _mm_abs_pi32(_m_from_int(0));
}
2 changes: 2 additions & 0 deletions cmake/try_compile/weak_symbols.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__attribute__((weak)) void __dummy(void *x) { }
void f(void *x) { __dummy(x); }
14 changes: 14 additions & 0 deletions cmake/try_compile/wmmintrin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifdef __native_client__
# error NativeClient detected - Avoiding AESNI opcodes
#endif

#pragma GCC target("aes")
#pragma GCC target("pclmul")

#include <wmmintrin.h>

int main(void)
{
__m128i x = _mm_aesimc_si128(_mm_setzero_si128());
__m128i y = _mm_clmulepi64_si128(_mm_setzero_si128(), _mm_setzero_si128(), 0);
}
6 changes: 6 additions & 0 deletions cmake/try_compile/xgetbv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <intrin.h>

int main(void)
{
(void) _xgetbv(0);
}
Loading

0 comments on commit 725c515

Please sign in to comment.