]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Add native Visual Studio 2015-2017 build support.
authorDmitry Ryazantsev <dimitriy.ryazantcev@gmail.com>
Tue, 9 Jan 2018 13:56:55 +0000 (15:56 +0200)
committerDmitry Ryazantsev <dimitriy.ryazantcev@gmail.com>
Wed, 10 Jan 2018 13:27:25 +0000 (15:27 +0200)
Add install via CMake.

CMakeLists.txt
INSTALL.md
READMEWIN.txt [deleted file]

index 72fef26583671c8da4e6344ca69a2d7a1ed2a254..295ca76145a302b7adf14e0fb238291123ca5500 100644 (file)
@@ -1,13 +1,23 @@
-cmake_minimum_required(VERSION 2.8)
-project(ccgost C)
+cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
+project(gost-engine LANGUAGES C)
+
+include(GNUInstallDirs)
+
+find_package(OpenSSL 1.1 REQUIRED)
+include_directories(${OPENSSL_INCLUDE_DIR})
 
 if (CMAKE_C_COMPILER_ID MATCHES "Clang")
-   message(STATUS "Using Clang and adding -Qunused-arguments flag")
-   set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Qunused-arguments")
+ add_compile_options(-Qunused-arguments)
+elseif(CMAKE_C_COMPILER_ID MATCHES "GNU")
+ add_compile_options(-O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb)
+elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+ add_definitions(-D_CRT_DEPRECATED_NO_WARNINGS)
+ add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
+ add_compile_options(/MP /WX /W4 /wd4100 /wd4267 /wd4206 /wd4706 /wd4244 /wd4115)
 endif()
 
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c98 -O3 -Werror -Qunused-arguments -Wno-unused-function -Wno-missing-braces -Wall")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -Werror -Wall -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -ggdb")
+set(CMAKE_C_STANDARD 90)
 
 include (TestBigEndian)
 TEST_BIG_ENDIAN(IS_BIG_ENDIAN)
@@ -15,8 +25,7 @@ if(IS_BIG_ENDIAN)
  message(STATUS "BIG_ENDIAN")
 else()
  message(STATUS "LITTLE_ENDIAN")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c98 -O3 -Werror -Wall")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DL_ENDIAN")
+ add_definitions(-DL_ENDIAN)
 endif()
 
 set(BIN_DIRECTORY bin)
@@ -80,47 +89,51 @@ set(GOST_EC_SOURCE_FILES
         )
 
 set(GOST_LIB_SOURCE_FILES
-        ${GOST_EC_SOURCE_FILES}
         ${GOST_89_SOURCE_FILES}
         ${GOST_HASH_SOURCE_FILES}
+        ${GOST_HASH_2012_SOURCE_FILES}
         ${GOST_GRASSHOPPER_SOURCE_FILES}
-        ${GOST_HASH_2012_SOURCE_FILES})
+        ${GOST_EC_SOURCE_FILES}
+        )
 
 set(GOST_ENGINE_SOURCE_FILES
         ${GOST_CORE_SOURCE_FILES}
         gost_ameth.c
         gost_md.c
         gost_md2012.c
-        gost_pmeth.c)
+        gost_pmeth.c
+        )
 
-add_library(gost STATIC ${GOST_LIB_SOURCE_FILES})
-set_target_properties(gost PROPERTIES POSITION_INDEPENDENT_CODE ON)
+add_library(gost_core STATIC ${GOST_LIB_SOURCE_FILES})
+set_target_properties(gost_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
 
 add_library(gost_engine MODULE ${GOST_ENGINE_SOURCE_FILES})
 set_target_properties(gost_engine PROPERTIES PREFIX "" OUTPUT_NAME "gost")
-
-target_link_libraries(gost_engine crypto gost)
-
-set(GOST_12_SUM_SOURCE_FILES
-        gost12sum.c
-        )
-
-add_executable(gost12sum ${GOST_12_SUM_SOURCE_FILES})
-
-target_link_libraries(gost12sum gost)
+target_link_libraries(gost_engine gost_core ${OPENSSL_CRYPTO_LIBRARY})
 
 set(GOST_SUM_SOURCE_FILES
         gostsum.c
         )
 
 add_executable(gostsum ${GOST_SUM_SOURCE_FILES})
+target_link_libraries(gostsum gost_core)
 
-target_link_libraries(gostsum gost)
-
-set(GOST_SUM_12_SOURCE_FILES
-        gostsum12.c
+set(GOST_12_SUM_SOURCE_FILES
+        gost12sum.c
         )
 
-#add_executable(gostsum12 ${GOST_SUM_12_SOURCE_FILES})
-#
-#target_link_libraries(gostsum12 gost)
+add_executable(gost12sum ${GOST_12_SUM_SOURCE_FILES})
+target_link_libraries(gost12sum gost_core)
+
+# install
+set(OPENSSL_ENGINES_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/engines-${OPENSSL_VERSION_MAJOR}_${OPENSSL_VERSION_MINOR})
+set(OPENSSL_MAN_INSTALL_DIR ${CMAKE_INSTALL_MANDIR}/man1)
+
+install(TARGETS gost_engine gostsum gost12sum EXPORT GostEngineConfig
+        LIBRARY  DESTINATION ${OPENSSL_ENGINES_INSTALL_DIR}
+        RUNTIME  DESTINATION ${CMAKE_INSTALL_BINDIR})
+install(FILES gostsum.1 gost12sum.1 DESTINATION ${OPENSSL_MAN_INSTALL_DIR})
+if (MSVC)
+ install(FILES $<TARGET_PDB_FILE:gost_engine> DESTINATION ${OPENSSL_ENGINES_INSTALL_DIR} OPTIONAL)
+ install(FILES $<TARGET_PDB_FILE:gostsum> $<TARGET_PDB_FILE:gost12sum> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
+endif()
\ No newline at end of file
index 85b4c3000c420de0e5943c136a6b4bbd98005469..e0e89468dcb5e3412f8071f4c7385939820afcf1 100644 (file)
@@ -8,54 +8,58 @@ To build and install OpenSSL GOST Engine, you will need
 
 * OpenSSL 1.1.*
 * an ANSI C compiler
-* CMake (2.8 or newer)
+* CMake (3.0 or newer)
 
 Here is a quick build guide:
 
     $ mkdir build
     $ cd build
-    $ cmake ..
-    $ make
+    $ cmake -DCMAKE_BUILD_TYPE=Release ..
+    $ cmake --build . --config Release
 
+Instead of `Release` you can use `Debug`, `RelWithDebInfo` or `MinSizeRel` configuration.
+See [cmake docs](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html) for details.
 You will find built binaries in `../bin` directory.
 
 If you want to build against a specific OpenSSL instance (you will need it
 if you have more than one OpenSSL instance for example), you can use
-the `cmake` variable `CMAKE_C_FLAGS` to specify path to include files and
-shared libraries of the desirable OpenSSL instance
+the `cmake` variable `OPENSSL_ROOT_DIR` to specify path of the desirable
+OpenSSL instance:
 
-    $ cmake -DCMAKE_C_FLAGS='-I/PATH/TO/OPENSSL/include -L/PATH/TO/OPENSSL/lib' ..
+    $ cmake -DOPENSSL_ROOT_DIR=/PATH/TO/OPENSSL/ ..
 
-If you use Visual Studio, see READMEWIN.txt for details.
+If you use Visual Studio, you can also set `CMAKE_INSTALL_PREFIX` variable
+to set install path, like this:
+
+    > cmake -G "Visual Studio 15 Win64" -DCMAKE_PREFIX_PATH=c:\OpenSSL\vc-win64a\ -DCMAKE_INSTALL_PREFIX=c:\OpenSSL\vc-win64a\ ..
+
+Also instead of `cmake --build` tool you can just open `gost-engine.sln`
+in Visual Studio, select configuration and call `Build Solution` manually.
+
+Instructions how to build OpenSSL 1.1.0 with Microsoft Visual Studio
+you can find [there](https://gist.github.com/terrillmoore/995421ea6171a9aa50552f6aa4be0998).
 
 How to Install
 --------------
 
-For now OpenSSL GOST Engine does not have an installation script, so you have to
-do it manually.
+To install GOST Engine you can call:
 
-Copy `gostsum` and `gost12sum` binaries to your binary directory. For example
-`/usr/local/bin`:
+    # cmake --build . --target install --config Release
 
-    # cd ../bin
-    # cp gostsum gost12sum /usr/local/bin
+or old plain and Unix only:
 
-Then, if you like to install man files properly, you can do it as follows:
-
-    # cd ..
-    # mkdir -p /usr/local/man/man1
-    # cp gost12sum.1 gostsum.1 /usr/local/man/man1
+    # make install
 
 The engine library `gost.so` should be installed into OpenSSL engine directory.
-Use the following command to get its name:
+
+To ensure that it is installed propery call:
 
     $ openssl version -e
     ENGINESDIR: "/usr/lib/i386-linux-gnu/engines-1.1"
 
-Then simply copy `gost.so` there
-
-    # cp bin/gost.so /usr/lib/i386-linux-gnu/engines-1.1
+Then check that `gost.so` there
 
+    # ls /usr/lib/i386-linux-gnu/engines-1.1
 
 Finally, to start using GOST Engine through OpenSSL, you should edit
 `openssl.cnf` configuration file as specified below.
diff --git a/READMEWIN.txt b/READMEWIN.txt
deleted file mode 100644 (file)
index c2023d7..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-It can be build via Visual Studio.
-
-1. Clone repository
-C:
-cd /projects/openssl/out32
-git clone git@github.com:gost-engine/engine.git
-
-2. Add to CMakeLists.txt references to OpenSSL
-
- include_directories("C:/projects/openssl/out32/openssl-x86-shared-release-vs2015/include")
-
-link_libraries("C:/projects/openssl/out32/openssl-x86-shared-release-vs2015/lib/libcrypto.lib", "C:/projects/openssl/out32/openssl-x86-shared-release-vs2015/lib/libssl.lib")
-
-3. At CMakeLists.txt replace rows
-
-add_library(gost STATIC ${GOST_LIB_SOURCE_FILES})
-set_target_properties(gost PROPERTIES POSITION_INDEPENDENT_CODE ON)
-target_link_libraries(gost_engine gost)
-target_link_libraries(gost12sum gost)
-target_link_libraries(gostsum gost)
-
-with
-
-add_library(libgost STATIC ${GOST_LIB_SOURCE_FILES})
-set_target_properties(libgost PROPERTIES POSITION_INDEPENDENT_CODE ON)
-target_link_libraries(gost_engine libgost)
-target_link_libraries(gost12sum libgost)
-target_link_libraries(gostsum libgost)
-
-4. Generate project for Visual Studio 14 (2015)
-
-cd /projects/openssl/tmp32
-mkdir engine
-cd engine
-cmake -G "Visual Studio 14" --build /projects/openssl/out32/engine
-In gost_engine.vcxproj replace
-;,.lib; to ;
-
-5. Open solution ccgost.sln into Visual Studio, select configuration Release and build solution.
-
-6. Use C:\projects\openssl\out32\engine\bin\Release\gost.dll
-
-