]> wagner.pp.ru Git - openssl-gost/engine.git/blobdiff - CMakeLists.txt
TRY_RUN should not be run when compiling cmake in CROSS_COMPILE
[openssl-gost/engine.git] / CMakeLists.txt
index 2af32486ff43b7dec27e6e77b3152e24e97429f8..a92e1b88613d385eb8a9f55558c6e0e7f1dbe92d 100644 (file)
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
+cmake_minimum_required(VERSION 3.18 FATAL_ERROR)
 project(gost-engine LANGUAGES C)
 
 include(GNUInstallDirs)
@@ -49,33 +49,37 @@ else()
  add_definitions(-DL_ENDIAN)
 endif()
 
-check_c_source_runs("
-  #ifdef _MSC_VER
-  # include <intrin.h>
-  #else
-  # include <x86intrin.h>
-  #endif
-  int main(void) {
-    unsigned long long x = -1, y = 1, r;
-    unsigned char cf;
-    cf = _addcarry_u64(1, x, y, &r);
-    return !(cf == 1 && r == 1);
-  }
-  " ADDCARRY_U64)
-if (ADDCARRY_U64)
-  add_definitions(-DHAVE_ADDCARRY_U64)
+if (NOT CMAKE_CROSSCOMPILING)
+  check_c_source_runs("
+    #ifdef _MSC_VER
+    # include <intrin.h>
+    #else
+    # include <x86intrin.h>
+    #endif
+    int main(void) {
+      unsigned long long x = -1, y = 1, r;
+      unsigned char cf;
+      cf = _addcarry_u64(1, x, y, &r);
+      return !(cf == 1 && r == 1);
+    }
+    " ADDCARRY_U64)
+  if (ADDCARRY_U64)
+    add_definitions(-DHAVE_ADDCARRY_U64)
+  endif()
 endif()
 
-check_c_source_runs("
-  int main(void) {
-    char buf[16] = { 0, 1, 2 };
-    int *p = (int *)(buf + 1);
-    int *q = (int *)(buf + 2);
-    return (*p == *q);
-  }
-  " RELAXED_ALIGNMENT)
-if (NOT RELAXED_ALIGNMENT)
-  add_definitions(-DSTRICT_ALIGNMENT)
+if (NOT CMAKE_CROSSCOMPILING)
+  check_c_source_runs("
+    int main(void) {
+      char buf[16] = { 0, 1, 2 };
+      int *p = (int *)(buf + 1);
+      int *q = (int *)(buf + 2);
+      return (*p == *q);
+    }
+    " RELAXED_ALIGNMENT)
+  if (NOT RELAXED_ALIGNMENT)
+    add_definitions(-DSTRICT_ALIGNMENT)
+  endif()
 endif()
 
 set(BIN_DIRECTORY bin)
@@ -178,53 +182,51 @@ set(GOST_ENGINE_SOURCE_FILES
         gost_md.c
         gost_md2012.c
         gost_pmeth.c
-        gost_omac.c
-        gost_omac_acpkm.c
         )
 
 add_executable(test_digest test_digest.c)
-target_link_libraries(test_digest gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(test_digest OpenSSL::Crypto)
 add_test(NAME digest
        COMMAND test_digest)
 
 add_executable(test_curves test_curves.c)
-target_link_libraries(test_curves gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(test_curves gost_engine OpenSSL::Crypto)
 add_test(NAME curves
        COMMAND test_curves)
 
 add_executable(test_params test_params.c)
-target_link_libraries(test_params gost_engine gost_core dl z pthread)
+target_link_libraries(test_params OpenSSL::Crypto)
 add_test(NAME parameters
        COMMAND test_params)
 
 add_executable(test_sign test_sign.c)
-target_link_libraries(test_sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(test_sign OpenSSL::Crypto)
 add_test(NAME sign/verify
        COMMAND test_sign)
 
 add_executable(test_tls test_tls.c)
-target_link_libraries(test_tls ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY} dl z pthread gost_engine gost_core)
+target_link_libraries(test_tls OpenSSL::SSL)
 add_test(NAME TLS
        COMMAND test_tls)
 
 add_executable(test_context test_context.c)
-target_link_libraries(test_context gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(test_context gost_engine OpenSSL::Crypto)
 add_test(NAME context
        COMMAND test_context)
 
 add_executable(test_grasshopper test_grasshopper.c)
-target_link_libraries(test_grasshopper gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(test_grasshopper gost_engine OpenSSL::Crypto)
 add_test(NAME grasshopper
        COMMAND test_grasshopper)
 
 add_executable(test_keyexpimp test_keyexpimp.c)
 #target_compile_definitions(test_keyexpimp PUBLIC -DOPENSSL_LOAD_CONF)
-target_link_libraries(test_keyexpimp gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(test_keyexpimp gost_engine OpenSSL::Crypto)
 add_test(NAME keyexpimp
        COMMAND test_keyexpimp)
 
 add_executable(test_gost89 test_gost89.c)
-target_link_libraries(test_gost89 gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(test_gost89 gost_core)
 add_test(NAME gost89
        COMMAND test_gost89)
 
@@ -243,7 +245,7 @@ if(NOT SKIP_PERL_TESTS)
 endif()
 
 add_executable(sign benchmark/sign.c)
-target_link_libraries(sign gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY} ${CLOCK_GETTIME_LIB} dl z pthread)
+target_link_libraries(sign gost_core ${CLOCK_GETTIME_LIB})
 
 # All that may need to load just built engine will have path to it defined.
 set(BINARY_TESTS_TARGETS
@@ -261,15 +263,16 @@ set_property(TARGET ${BINARY_TESTS_TARGETS} APPEND PROPERTY COMPILE_DEFINITIONS
 
 add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
 set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
+target_link_libraries(gost_core PRIVATE OpenSSL::Crypto)
 
 add_library(gost_engine SHARED ${GOST_ENGINE_SOURCE_FILES})
 set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost")
 set_target_properties(gost_engine PROPERTIES VERSION ${GOST_SOVERSION} SOVERSION ${GOST_SOVERSION})
-target_link_libraries(gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
+target_link_libraries(gost_engine PRIVATE gost_core)
 
 add_library(gost_engine_static STATIC ${GOST_ENGINE_SOURCE_FILES})
 set_target_properties(gost_engine_static PROPERTIES PREFIX "lib" PUBLIC_HEADER gost-engine.h OUTPUT_NAME "gost")
-target_link_libraries(gost_engine_static gost_core ${OPENSSL_CRYPTO_LIBRARY} dl pthread z)
+target_link_libraries(gost_engine_static PRIVATE gost_core)
 
 
 set(GOST_SUM_SOURCE_FILES
@@ -277,7 +280,7 @@ set(GOST_SUM_SOURCE_FILES
         )
 
 add_executable(gostsum ${GOST_SUM_SOURCE_FILES})
-target_link_libraries(gostsum gost_core ${OPENSSL_CRYPTO_LIBRARY} dl z pthread)
+target_link_libraries(gostsum gost_core)
 
 set(GOST_12_SUM_SOURCE_FILES
         gost12sum.c
@@ -296,7 +299,7 @@ add_custom_target(tcl_tests
     WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tcl_tests)
 
 add_executable(test_tlstree test_tlstree.c)
-target_link_libraries(test_tlstree PUBLIC ${OPENSSL_CRYPTO_LIBRARY})
+target_link_libraries(test_tlstree PUBLIC OpenSSL::Crypto)
 
 # install
 set(OPENSSL_MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)