mirror of
https://github.com/mtrojnar/osslsigncode.git
synced 2025-04-04 17:00:11 -05:00
simplify cmake
This commit is contained in:
parent
a892c50147
commit
6a873c3a49
@ -12,39 +12,66 @@ set(PACKAGE_BUGREPORT "Michal.Trojnara@stunnel.org")
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
# make find modules in cmake dir available
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
|
||||
# load CMake library modules
|
||||
include(FindOpenSSL)
|
||||
include(FindCURL)
|
||||
|
||||
# load CMake project modules
|
||||
include(SetOptions)
|
||||
include(FindOpenssl)
|
||||
include(FindCurl)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
|
||||
include(FindMapping)
|
||||
|
||||
# use config.h
|
||||
target_compile_definitions(osslsigncode PRIVATE HAVE_CONFIG_H=1)
|
||||
# define the target
|
||||
add_executable(osslsigncode)
|
||||
|
||||
# create and use config.h
|
||||
configure_file(Config.h.in config.h)
|
||||
target_compile_definitions(osslsigncode PRIVATE HAVE_CONFIG_H=1)
|
||||
|
||||
# add include directories to osslsigncode
|
||||
target_include_directories(osslsigncode PUBLIC "${PROJECT_BINARY_DIR}")
|
||||
# set sources
|
||||
target_sources(osslsigncode PRIVATE osslsigncode.c msi.c)
|
||||
if(WIN32)
|
||||
target_sources(osslsigncode PRIVATE ${OPENSSL_INCLUDE_DIRS}/applink.c)
|
||||
endif(WIN32)
|
||||
|
||||
if(MSVC)
|
||||
# set include directories
|
||||
target_include_directories(osslsigncode PRIVATE "${PROJECT_BINARY_DIR}")
|
||||
|
||||
# set OpenSSL includes/libraries
|
||||
if(NOT OPENSSL_FOUND)
|
||||
message(FATAL_ERROR "OpenSSL library not found")
|
||||
endif(NOT OPENSSL_FOUND)
|
||||
target_include_directories(osslsigncode PRIVATE ${OPENSSL_INCLUDE_DIRS})
|
||||
target_link_libraries(osslsigncode PRIVATE ${OPENSSL_LIBRARIES})
|
||||
|
||||
# set cURL includes/libraries
|
||||
if(CURL_FOUND)
|
||||
target_compile_definitions(osslsigncode PRIVATE ENABLE_CURL=1)
|
||||
target_include_directories(osslsigncode PRIVATE ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(osslsigncode PRIVATE ${CURL_LIBRARIES})
|
||||
message(NOTICE "cURL support enabled")
|
||||
else(CURL_FOUND)
|
||||
message(WARNING "cURL support disabled (library not found)")
|
||||
endif(CURL_FOUND)
|
||||
|
||||
if(WIN32)
|
||||
# set output directory
|
||||
set_target_properties(osslsigncode PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}
|
||||
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
# copy necessary libraries
|
||||
file(COPY ${OPENSSL_LIBS} ${CURL_LIB} DESTINATION ${PROJECT_BINARY_DIR})
|
||||
else()
|
||||
# copy the libraries
|
||||
file(COPY ${OPENSSL_LIBRARIES} ${CURL_LIBRARIES} DESTINATION ${PROJECT_BINARY_DIR})
|
||||
else(WIN32)
|
||||
# set LD_LIBRARY_PATH
|
||||
set_target_properties(osslsigncode PROPERTIES
|
||||
INSTALL_RPATH_USE_LINK_PATH TRUE
|
||||
)
|
||||
endif()
|
||||
endif(WIN32)
|
||||
|
||||
include(CMakeTest)
|
||||
|
||||
include(CMakeInstall)
|
||||
if(NOT MSVC)
|
||||
|
||||
if(NOT WIN32)
|
||||
include(CMakeDist)
|
||||
endif()
|
||||
endif(NOT WIN32)
|
||||
|
@ -12,7 +12,7 @@
|
||||
2) Run "MSYS2 MinGW 64-bit" and build 64-bit Windows executables.
|
||||
```
|
||||
cd osslsigncode-folder
|
||||
x86_64-w64-mingw32-gcc osslsigncode.c msi.c msi.h -o osslsigncode.exe \
|
||||
x86_64-w64-mingw32-gcc osslsigncode.c msi.c -o osslsigncode.exe \
|
||||
-lcrypto -lssl -lcurl \
|
||||
-D 'PACKAGE_STRING="osslsigncode 2.4"' \
|
||||
-D 'PACKAGE_BUGREPORT="Michal.Trojnara@stunnel.org"' \
|
||||
@ -71,7 +71,7 @@
|
||||
3) Build 64-bit Windows executables.
|
||||
```
|
||||
cd osslsigncode-folder
|
||||
x86_64-w64-mingw32-gcc osslsigncode.c msi.c msi.h -o osslsigncode.exe \
|
||||
x86_64-w64-mingw32-gcc osslsigncode.c msi.c -o osslsigncode.exe \
|
||||
-L 'C:/OpenSSL/lib/' -lcrypto -lssl \
|
||||
-I 'C:/OpenSSL/include/' \
|
||||
-L 'C:/curl/lib' -lcurl \
|
||||
@ -94,28 +94,18 @@
|
||||
libcurl/7.78.0 OpenSSL/1.1.1k
|
||||
```
|
||||
|
||||
### Building OpenSSL, Curl and osslsigncode sources with Microsoft Visual Studio 64-bit:
|
||||
### Building OpenSSL, Curl and osslsigncode sources with Microsoft Visual Studio:
|
||||
|
||||
1) Download and install Strawberry Perl from https://strawberryperl.com/
|
||||
1) Install and integrate vcpkg: https://vcpkg.io/en/getting-started.html
|
||||
|
||||
2) Run "Open Visual Studio 2022 Tools Command Prompt for targeting x64"
|
||||
|
||||
3) Build and install OpenSSL.
|
||||
2) Install the prerequisites:
|
||||
```
|
||||
cd openssl-(version)
|
||||
perl Configure VC-WIN64A --prefix=C:\OpenSSL\vc-win64a --openssldir=C:\OpenSSL\SSL no-asm shared
|
||||
nmake && nmake install
|
||||
vcpkg install openssl curl
|
||||
```
|
||||
|
||||
4) Build and install curl.
|
||||
```
|
||||
cd curl-(version)\winbuild
|
||||
nmake /f Makefile.vc mode=dll WITH_PREFIX=C:\curl SSL_PATH=C:\OpenSSL\vc-win64a \
|
||||
VC=22 MACHINE=x64 DEBUG=no WITH_SSL=dll ENABLE_NGHTTP2=no ENABLE_SSPI=no \
|
||||
ENABLE_IDN=no GEN_PDB=no ENABLE_WINSSL=no USE_ZLIB=no
|
||||
```
|
||||
3) Git clone osslsigncode: https://github.com/mtrojnar/osslsigncode/
|
||||
|
||||
5) Build 64-bit Windows osslsigncode.
|
||||
4) Build osslsigncode with GUI or cmake.
|
||||
Navigate to the build directory and run CMake to configure the osslsigncode project
|
||||
and generate a native build system:
|
||||
```
|
||||
@ -125,21 +115,18 @@
|
||||
```
|
||||
-Denable-strict=ON
|
||||
-Denable-pedantic=ON
|
||||
-Dwith-curl=OFF
|
||||
-Dssl-path=C:\OpenSSL\
|
||||
-Dcurl-path=C:\curl\
|
||||
```
|
||||
Then call that build system to actually compile/link the osslsigncode project:
|
||||
```
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
6) Make tests.
|
||||
5) Make tests.
|
||||
```
|
||||
ctest -C Release
|
||||
```
|
||||
|
||||
5) Make install (with administrator privileges).
|
||||
6) Make install (with administrative privileges).
|
||||
```
|
||||
cmake --install . --prefix "C:\osslsigncode"
|
||||
```
|
||||
|
@ -54,9 +54,6 @@ You may need to use `cmake3` instead of `cmake` to complete the following steps
|
||||
```
|
||||
-Denable-strict=ON
|
||||
-Denable-pedantic=ON
|
||||
-Dssl-path=/opt/openssl-3.0.2/
|
||||
-Dcurl-path=/opt/curl-7.82/
|
||||
-Dwith-curl=OFF
|
||||
```
|
||||
* Then call that build system to actually compile/link the osslsigncode project (alias `make`):
|
||||
```
|
||||
|
@ -1,47 +0,0 @@
|
||||
# find the native CURL headers and libraries
|
||||
|
||||
if(with-curl)
|
||||
if(curl-path)
|
||||
set(CURL_SEARCH_DIR PATHS ${CURL_ROOT} NO_DEFAULT_PATH)
|
||||
find_path(CURL_INCLUDE_DIRS
|
||||
NAMES curl/curl.h
|
||||
PATHS ${CURL_SEARCH_DIR}
|
||||
PATH_SUFFIXES include
|
||||
REQUIRED
|
||||
)
|
||||
find_library(CURL_LIBRARIES
|
||||
NAMES libcurl libcurl.so
|
||||
PATHS ${CURL_SEARCH_DIR}
|
||||
PATH_SUFFIXES lib
|
||||
NO_DEFAULT_PATH
|
||||
REQUIRED
|
||||
)
|
||||
mark_as_advanced(
|
||||
CURL_INCLUDE_DIRS
|
||||
CURL_LIBRARIES
|
||||
)
|
||||
set(CURL_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
if(CURL_FOUND)
|
||||
target_link_libraries(osslsigncode PRIVATE ${CURL_LIBRARIES})
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
message(STATUS "Link CURL library: ${CURL_LIBRARIES}")
|
||||
message(STATUS "Include CURL directory: ${CURL_INCLUDE_DIRS}")
|
||||
set(ENABLE_CURL 1)
|
||||
else()
|
||||
MESSAGE(FATAL_ERROR "Could not find the CURL library and development files.")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
find_path(CURL_BIN_DIR
|
||||
NAMES curl.exe
|
||||
PATHS ${CURL_SEARCH_DIR}
|
||||
PATH_SUFFIXES bin
|
||||
REQUIRED
|
||||
)
|
||||
set(CURL_LIB "${CURL_BIN_DIR}/libcurl.dll")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Disable CURL")
|
||||
endif()
|
@ -1,71 +0,0 @@
|
||||
# find the OpenSSL encryption library
|
||||
|
||||
if(ssl-path)
|
||||
set(OPENSSL_SEARCH_DIR PATHS ${OPENSSL_ROOT} NO_DEFAULT_PATH)
|
||||
find_path(OPENSSL_INCLUDE_DIR
|
||||
NAMES openssl/opensslconf.h
|
||||
PATHS ${OPENSSL_SEARCH_DIR}
|
||||
PATH_SUFFIXES include
|
||||
REQUIRED
|
||||
)
|
||||
find_library(OPENSSL_SSL
|
||||
NAMES libssl libssl.so
|
||||
PATHS ${OPENSSL_SEARCH_DIR}
|
||||
PATH_SUFFIXES lib lib64
|
||||
NO_DEFAULT_PATH
|
||||
REQUIRED
|
||||
)
|
||||
find_library(OPENSSL_CRYPTO
|
||||
NAMES libcrypto libcrypto.so
|
||||
PATHS ${OPENSSL_SEARCH_DIR}
|
||||
PATH_SUFFIXES lib lib64
|
||||
NO_DEFAULT_PATH
|
||||
REQUIRED
|
||||
)
|
||||
|
||||
if(MSVC)
|
||||
find_file(OPENSSL_APPLINK_SOURCE
|
||||
NAMES openssl/applink.c
|
||||
PATHS ${OPENSSL_INCLUDE_DIR}
|
||||
NO_DEFAULT_PATH
|
||||
REQUIRED
|
||||
)
|
||||
else()
|
||||
set(OPENSSL_APPLINK_SOURCE)
|
||||
endif()
|
||||
|
||||
set(OPENSSL_LIBRARIES ${OPENSSL_SSL} ${OPENSSL_CRYPTO})
|
||||
mark_as_advanced(
|
||||
OPENSSL_INCLUDE_DIR
|
||||
OPENSSL_LIBRARIES
|
||||
OPENSSL_APPLINK_SOURCE
|
||||
)
|
||||
set(OPENSSL_FOUND TRUE)
|
||||
endif()
|
||||
|
||||
if(OPENSSL_FOUND)
|
||||
message(STATUS "Link OpenSSL libraries: ${OPENSSL_LIBRARIES}")
|
||||
message(STATUS "Include OpenSSL directory: ${OPENSSL_INCLUDE_DIR}")
|
||||
if(MSVC)
|
||||
message(STATUS "OpenSSL applink source: ${OPENSSL_APPLINK_SOURCE}")
|
||||
endif()
|
||||
else()
|
||||
MESSAGE(FATAL_ERROR "Could not find the OpenSSL library and development files.")
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
find_path(OPENSSL_BIN_DIR
|
||||
NAMES openssl.exe
|
||||
PATHS ${OPENSSL_SEARCH_DIR}
|
||||
PATH_SUFFIXES bin
|
||||
REQUIRED
|
||||
)
|
||||
set(OPENSSL_LIBS "${OPENSSL_BIN_DIR}/libcrypto-3-x64.dll" "${OPENSSL_BIN_DIR}/libssl-3-x64.dll")
|
||||
endif()
|
||||
|
||||
# add an executable target called "osslsigncode" to be built from the source files
|
||||
set(SOURCE_FILES osslsigncode.c msi.c ${OPENSSL_APPLINK_SOURCE})
|
||||
add_executable(osslsigncode)
|
||||
target_sources(osslsigncode PRIVATE ${SOURCE_FILES})
|
||||
target_link_libraries(osslsigncode PRIVATE ${OPENSSL_LIBRARIES})
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
@ -9,30 +9,6 @@ option(enable-strict "Enable strict compile mode" OFF)
|
||||
option(enable-pedantic "Enable pedantic compile mode" OFF)
|
||||
option(with-curl "Enable curl" ON)
|
||||
|
||||
if(MSVC)
|
||||
set(ssl-path "D:/TEMP/OpenSSL-3.0.2/vc-win64a" CACHE FILEPATH "OpenSSL library path")
|
||||
set(curl-path "D:/TEMP/curl-7.82.0" CACHE FILEPATH "cURL library path")
|
||||
else()
|
||||
option(ssl-path "OpenSSL library path" OFF)
|
||||
option(curl-path "cURL library path" OFF)
|
||||
endif()
|
||||
|
||||
if(ssl-path)
|
||||
set(OPENSSL_ROOT ${ssl-path})
|
||||
set(OPENSSL_SEARCH_DIR)
|
||||
else()
|
||||
include(FindOpenSSL)
|
||||
endif()
|
||||
|
||||
if(with-curl)
|
||||
if(curl-path)
|
||||
set(CURL_ROOT ${curl-path})
|
||||
set(CURL_BIN_DIR)
|
||||
else()
|
||||
include(FindCURL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# enable compile options
|
||||
if(enable-strict)
|
||||
message(STATUS "Enable strict compile mode")
|
||||
|
Loading…
x
Reference in New Issue
Block a user