forked from wolfSSL/wolfssl
Tweak CMakeLists.txt
- Add generated CMake files/directories to .gitignore. - Use lowercase for CMake commands, UPPERCASE for variables. - Favor the CMake "option" command over SET(... CACHE BOOL ...). - Use CMAKE_CURRENT_SOURCE_DIR in place of CMAKE_CURRENT_BINARY_DIR. - Use CMAKE_USE_PTHREADS_INIT instead of CMAKE_HAVE_PTHREAD_H. - Use target_include_directories on the wolfssl library target instead of include_directories.
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -352,3 +352,8 @@ IDE/XCODE/Index
|
|||||||
|
|
||||||
# Emacs
|
# Emacs
|
||||||
*~
|
*~
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
CMakeFiles/
|
||||||
|
CMakeCache.txt
|
||||||
|
cmake_install.cmake
|
||||||
|
@@ -16,14 +16,18 @@
|
|||||||
# To build with debugging use:
|
# To build with debugging use:
|
||||||
# $ cmake .. -DCMAKE_BUILD_TYPE=Debug
|
# $ cmake .. -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 2.6)
|
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
# Project
|
# Project
|
||||||
####################################################
|
####################################################
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.6)
|
||||||
project(wolfssl)
|
project(wolfssl)
|
||||||
find_package (Threads)
|
|
||||||
|
####################################################
|
||||||
|
# Dependencies
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
find_package(Threads)
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
# Compiler
|
# Compiler
|
||||||
@@ -32,10 +36,10 @@ find_package (Threads)
|
|||||||
|
|
||||||
if(APPLE)
|
if(APPLE)
|
||||||
# Silence ranlib warning "has no symbols"
|
# Silence ranlib warning "has no symbols"
|
||||||
SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
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_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_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>")
|
set(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
@@ -55,46 +59,50 @@ endif()
|
|||||||
####################################################
|
####################################################
|
||||||
# Build Options
|
# Build Options
|
||||||
####################################################
|
####################################################
|
||||||
SET(BUILD_TESTS YES CACHE BOOL "Build test applications")
|
|
||||||
|
option(BUILD_TESTS "Build test applications" YES)
|
||||||
|
|
||||||
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
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
|
${CMAKE_CURRENT_SOURCE_DIR}/user_settings.h)
|
||||||
else()
|
else()
|
||||||
# Use template
|
# Use template
|
||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h.in
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/wolfssl/options.h.in
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/user_settings.h)
|
${CMAKE_CURRENT_SOURCE_DIR}/user_settings.h)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(-DWOLFSSL_USER_SETTINGS)
|
add_definitions(-DWOLFSSL_USER_SETTINGS)
|
||||||
add_definitions(-DWOLFSSL_IGNORE_FILE_WARN)
|
add_definitions(-DWOLFSSL_IGNORE_FILE_WARN)
|
||||||
if(CMAKE_HAVE_PTHREAD_H)
|
if(CMAKE_USE_PTHREADS_INIT)
|
||||||
add_definitions(-DHAVE_PTHREAD)
|
add_definitions(-DHAVE_PTHREAD)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
# Source Files
|
# Library Target and Source Files
|
||||||
####################################################
|
####################################################
|
||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/.)
|
|
||||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/.)
|
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
file(GLOB TEST_SOURCE_FILES
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.c
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
|
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
|
|
||||||
|
|
||||||
####################################################
|
|
||||||
# Output Files
|
|
||||||
####################################################
|
|
||||||
|
|
||||||
# Build wolfssl library
|
|
||||||
add_library(wolfssl ${LIB_SOURCE_FILES})
|
add_library(wolfssl ${LIB_SOURCE_FILES})
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
# Include Directories
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
target_include_directories(wolfssl
|
||||||
|
PUBLIC
|
||||||
|
$<INSTALL_INTERFACE:wolfssl>
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/wolfssl>
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/. # Needed for user_settings.h to be visible
|
||||||
|
)
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
# Link Libraries
|
||||||
|
####################################################
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
# For Windows link ws2_32
|
# For Windows link ws2_32
|
||||||
target_link_libraries(wolfssl PUBLIC $<$<PLATFORM_ID:Windows>:ws2_32>)
|
target_link_libraries(wolfssl PUBLIC $<$<PLATFORM_ID:Windows>:ws2_32>)
|
||||||
@@ -103,6 +111,10 @@ else()
|
|||||||
target_link_libraries(wolfssl PUBLIC m)
|
target_link_libraries(wolfssl PUBLIC m)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
# Tests and Examples
|
||||||
|
####################################################
|
||||||
|
|
||||||
# Optionally build example and test applications
|
# Optionally build example and test applications
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
# Build wolfCrypt test
|
# Build wolfCrypt test
|
||||||
@@ -141,6 +153,11 @@ if(BUILD_TESTS)
|
|||||||
target_link_libraries(tls_bench wolfssl)
|
target_link_libraries(tls_bench wolfssl)
|
||||||
target_link_libraries(tls_bench Threads::Threads)
|
target_link_libraries(tls_bench Threads::Threads)
|
||||||
|
|
||||||
|
file(GLOB TEST_SOURCE_FILES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/tests/*.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/examples/server/server.c
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/examples/client/client.c)
|
||||||
|
|
||||||
# Build Unit Tests
|
# Build Unit Tests
|
||||||
add_executable(unit_test
|
add_executable(unit_test
|
||||||
${TEST_SOURCE_FILES})
|
${TEST_SOURCE_FILES})
|
||||||
|
Reference in New Issue
Block a user