forked from wolfSSL/wolfssl
Improvements to CMake support based on feedback from users.
This commit is contained in:
@@ -4,7 +4,18 @@
|
|||||||
#
|
#
|
||||||
# This file is part of wolfSSL. (formerly known as CyaSSL)
|
# This file is part of wolfSSL. (formerly known as CyaSSL)
|
||||||
#
|
#
|
||||||
#
|
# Usage:
|
||||||
|
# $ mkdir build
|
||||||
|
# $ cd build
|
||||||
|
# $ cmake ..
|
||||||
|
# $ make
|
||||||
|
|
||||||
|
# To build library only and not build examples and test apps use:
|
||||||
|
# $ cmake .. -DBUILD_TESTS=NO
|
||||||
|
|
||||||
|
# To build with debugging use:
|
||||||
|
# $ cmake .. -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 2.6)
|
cmake_minimum_required (VERSION 2.6)
|
||||||
|
|
||||||
@@ -17,30 +28,40 @@ find_package (Threads)
|
|||||||
####################################################
|
####################################################
|
||||||
# Compiler
|
# Compiler
|
||||||
####################################################
|
####################################################
|
||||||
set(CMAKE_C_COMPILER gcc)
|
# Let CMake choose default compiler
|
||||||
set(CMAKE_CXX_COMPILER gcc)
|
|
||||||
|
# Silence ranlib warning "has no symbols"
|
||||||
|
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||||
|
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||||
|
SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||||
|
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
# Cross Compile Example
|
||||||
|
####################################################
|
||||||
|
|
||||||
# Example for cross-compile
|
|
||||||
#set(CMAKE_SYSTEM_NAME Linux)
|
#set(CMAKE_SYSTEM_NAME Linux)
|
||||||
#set(CMAKE_SYSTEM_PROCESSOR arm)
|
#set(CMAKE_SYSTEM_PROCESSOR arm)
|
||||||
#set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
|
#set(CMAKE_C_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc")
|
||||||
#set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
|
#set(CMAKE_CXX_COMPILER "/opt/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-g++")
|
||||||
#set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
|
#set(CMAKE_SYSROOT "/opt/arm-linux-musleabihf-cross/arm-linux-musleabihf/")
|
||||||
|
# Example for setting CFLAGS
|
||||||
|
#set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
|
||||||
|
# Example for map file and custom linker script
|
||||||
|
#set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
# Build Options
|
# Build Options
|
||||||
####################################################
|
####################################################
|
||||||
|
SET(BUILD_TESTS YES CACHE BOOL "Build test applications")
|
||||||
|
|
||||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h")
|
||||||
# Copy generated ./options.h
|
# Copy generated ./options.h
|
||||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h
|
||||||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
|
|
||||||
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/options.h
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
|
${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
|
||||||
else()
|
else()
|
||||||
# Use template
|
# Use template
|
||||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h.in
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h.in
|
||||||
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/)
|
|
||||||
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/options.h.in
|
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
|
${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -51,18 +72,11 @@ if(CMAKE_HAVE_PTHREAD_H)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
# Build flags
|
# Source Files
|
||||||
####################################################
|
####################################################
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.)
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/.)
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}/.)
|
||||||
|
|
||||||
# Example for map file and custom linker script
|
|
||||||
set(CMAKE_C_FLAGS "-std=gnu89 ${CMAKE_C_FLAGS}")
|
|
||||||
#set(CMAKE_EXE_LINKER_FLAGS " -Xlinker -Map=output.map -T\"${CMAKE_CURRENT_SOURCE_DIR}/linker.ld\"")
|
|
||||||
|
|
||||||
####################################################
|
|
||||||
# Source Files
|
|
||||||
####################################################
|
|
||||||
file(GLOB LIB_SOURCE_FILES
|
file(GLOB LIB_SOURCE_FILES
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c
|
${CMAKE_CURRENT_SOURCE_DIR}/src/*.c
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/src/*.c)
|
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/src/*.c)
|
||||||
@@ -75,9 +89,14 @@ file(GLOB TEST_SOURCE_FILES
|
|||||||
####################################################
|
####################################################
|
||||||
# Output Files
|
# Output Files
|
||||||
####################################################
|
####################################################
|
||||||
# Build library
|
# DH requires math (m) library
|
||||||
|
link_libraries(m)
|
||||||
|
|
||||||
|
# Build wolfssl library
|
||||||
add_library(wolfssl ${LIB_SOURCE_FILES})
|
add_library(wolfssl ${LIB_SOURCE_FILES})
|
||||||
|
|
||||||
|
# Optionally build example and test applications
|
||||||
|
if(BUILD_TESTS)
|
||||||
# Build wolfCrypt test
|
# Build wolfCrypt test
|
||||||
add_executable(wolfcrypttest
|
add_executable(wolfcrypttest
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
|
${CMAKE_CURRENT_SOURCE_DIR}/wolfcrypt/test/test.c)
|
||||||
@@ -120,3 +139,4 @@ add_executable(unit_test
|
|||||||
set_target_properties( unit_test PROPERTIES COMPILE_FLAGS "-DNO_MAIN_DRIVER" )
|
set_target_properties( unit_test PROPERTIES COMPILE_FLAGS "-DNO_MAIN_DRIVER" )
|
||||||
target_link_libraries(unit_test wolfssl)
|
target_link_libraries(unit_test wolfssl)
|
||||||
target_link_libraries(unit_test Threads::Threads)
|
target_link_libraries(unit_test Threads::Threads)
|
||||||
|
endif()
|
||||||
|
6
INSTALL
6
INSTALL
@@ -88,4 +88,10 @@
|
|||||||
$ make
|
$ make
|
||||||
$ sudo make install
|
$ sudo make install
|
||||||
|
|
||||||
|
To build library only and not build examples and test apps use:
|
||||||
|
$ cmake .. -DBUILD_TESTS=NO
|
||||||
|
|
||||||
|
To build with debugging use:
|
||||||
|
$ cmake .. -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
|
||||||
Make sure and run the built examples and test from the wolfssl-root to properly find the ./certs directory.
|
Make sure and run the built examples and test from the wolfssl-root to properly find the ./certs directory.
|
||||||
|
Reference in New Issue
Block a user