Skip to content

Commit

Permalink
modernize cmake files in unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
alexteoh-intel committed Jun 7, 2024
1 parent c7dfd68 commit ee691ba
Show file tree
Hide file tree
Showing 17 changed files with 666 additions and 616 deletions.
42 changes: 21 additions & 21 deletions unit_test/cmockalib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
cmake_minimum_required(VERSION 3.5)

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_compile_options(${CMOCKA_FLAGS} -DHAVE_SIGNAL_H)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
add_compile_options(${CMOCKA_FLAGS} -DHAVE_VSNPRINTF -DHAVE_SNPRINTF)
if((TOOLCHAIN STREQUAL "VS2015") OR (TOOLCHAIN STREQUAL "VS2019") OR (TOOLCHAIN STREQUAL "VS2022"))
add_compile_options(/wd4819)
endif()
endif()
add_library(cmockalib STATIC "")

include_directories(${LIBSPDM_DIR}/unit_test/cmockalib
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/unit_test/cmockalib/cmocka/include
${LIBSPDM_DIR}/unit_test/cmockalib/cmocka/include/cmockery
target_include_directories(cmockalib
PRIVATE
${LIBSPDM_DIR}/unit_test/cmockalib
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/unit_test/cmockalib/cmocka/include
${LIBSPDM_DIR}/unit_test/cmockalib/cmocka/include/cmockery
)

target_sources(cmockalib
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/cmocka/src/cmocka.c
)

if(TOOLCHAIN STREQUAL "ARM_DS2022")
set(src_CmockaLib
cmocka/src/cmocka.c
strdup.c
)
else()
set(src_CmockaLib
cmocka/src/cmocka.c
)
target_sources(cmockalib PRIVATE ${CMAKE_CURRENT_LIST_DIR}/strdup.c)
endif()

add_library(cmockalib STATIC ${src_CmockaLib})
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_compile_options(cmockalib PRIVATE ${CMOCKA_FLAGS} -DHAVE_SIGNAL_H)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
target_compile_options(cmockalib PRIVATE ${CMOCKA_FLAGS} -DHAVE_VSNPRINTF -DHAVE_SNPRINTF)
if((TOOLCHAIN STREQUAL "VS2015") OR (TOOLCHAIN STREQUAL "VS2019") OR (TOOLCHAIN STREQUAL "VS2022"))
target_compile_options(cmockalib PRIVATE /wd4819)
endif()
endif()
19 changes: 11 additions & 8 deletions unit_test/spdm_transport_test_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
cmake_minimum_required(VERSION 3.5)

include_directories(${LIBSPDM_DIR}/unit_test/spdm_transport_test_lib
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/unit_test/include
)
add_library(spdm_transport_test_lib STATIC "")

set(src_spdm_transport_test_lib
common.c
test.c
target_include_directories(spdm_transport_test_lib
PRIVATE
${LIBSPDM_DIR}/unit_test/spdm_transport_test_lib
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/unit_test/include
)

add_library(spdm_transport_test_lib STATIC ${src_spdm_transport_test_lib})
target_sources(spdm_transport_test_lib
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/common.c
${CMAKE_CURRENT_LIST_DIR}/test.c
)
98 changes: 54 additions & 44 deletions unit_test/test_crypt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,58 +1,68 @@
cmake_minimum_required(VERSION 3.5)

include_directories(${LIBSPDM_DIR}/unit_test/test_crypt
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/os_stub/include
${LIBSPDM_DIR}/os_stub
)
cmake_minimum_required(VERSION 3.5)

add_executable(test_crypt)

set(src_test_crypt
test_crypt.c
hash_verify.c
hmac_verify.c
hkdf_verify.c
aead_verify.c
rsa_verify.c
rsa_verify2.c
dh_verify.c
ec_verify.c
ec_verify2.c
ecd_verify.c
ecd_verify2.c
sm2_verify.c
sm2_verify2.c
rand_verify.c
x509_verify.c
os_support.c
target_include_directories(test_crypt
PRIVATE
${LIBSPDM_DIR}/unit_test/test_crypt
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/os_stub/include
${LIBSPDM_DIR}/os_stub
)

set(test_crypt_LIBRARY
memlib
debuglib
${CRYPTO_LIB_PATHS}
rnglib
cryptlib_${CRYPTO}
malloclib
spdm_crypt_lib
spdm_crypt_ext_lib
target_sources(test_crypt
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/test_crypt.c
${CMAKE_CURRENT_LIST_DIR}/hash_verify.c
${CMAKE_CURRENT_LIST_DIR}/hmac_verify.c
${CMAKE_CURRENT_LIST_DIR}/hkdf_verify.c
${CMAKE_CURRENT_LIST_DIR}/aead_verify.c
${CMAKE_CURRENT_LIST_DIR}/rsa_verify.c
${CMAKE_CURRENT_LIST_DIR}/rsa_verify2.c
${CMAKE_CURRENT_LIST_DIR}/dh_verify.c
${CMAKE_CURRENT_LIST_DIR}/ec_verify.c
${CMAKE_CURRENT_LIST_DIR}/ec_verify2.c
${CMAKE_CURRENT_LIST_DIR}/ecd_verify.c
${CMAKE_CURRENT_LIST_DIR}/ecd_verify2.c
${CMAKE_CURRENT_LIST_DIR}/sm2_verify.c
${CMAKE_CURRENT_LIST_DIR}/sm2_verify2.c
${CMAKE_CURRENT_LIST_DIR}/rand_verify.c
${CMAKE_CURRENT_LIST_DIR}/x509_verify.c
${CMAKE_CURRENT_LIST_DIR}/os_support.c
)

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
if((TOOLCHAIN STREQUAL "VS2015") OR (TOOLCHAIN STREQUAL "VS2019") OR (TOOLCHAIN STREQUAL "VS2022"))
target_compile_options(test_crypt PRIVATE /wd4819)
endif()
endif()

if(TOOLCHAIN STREQUAL "ARM_DS2022")
set(test_crypt_LIBRARY ${test_crypt_LIBRARY} armbuild_lib)
target_link_libraries(test_crypt PRIVATE armbuild_lib)
endif()

if((TOOLCHAIN STREQUAL "KLEE") OR (TOOLCHAIN STREQUAL "CBMC"))
add_executable(test_crypt
${src_test_crypt}
$<TARGET_OBJECTS:memlib>
$<TARGET_OBJECTS:debuglib>
$<TARGET_OBJECTS:${CRYPTO_LIB_PATHS}>
$<TARGET_OBJECTS:rnglib>
$<TARGET_OBJECTS:cryptlib_${CRYPTO}>
$<TARGET_OBJECTS:malloclib>
target_link_libraries(test_crypt
PRIVATE
$<TARGET_OBJECTS:memlib>
$<TARGET_OBJECTS:debuglib>
$<TARGET_OBJECTS:${CRYPTO_LIB_PATHS}>
$<TARGET_OBJECTS:rnglib>
$<TARGET_OBJECTS:cryptlib_${CRYPTO}>
$<TARGET_OBJECTS:malloclib>
)
else()
add_executable(test_crypt ${src_test_crypt})
target_link_libraries(test_crypt ${test_crypt_LIBRARY})
target_link_libraries(test_crypt
PRIVATE
memlib
debuglib
${CRYPTO_LIB_PATHS}
rnglib
cryptlib_${CRYPTO}
malloclib
spdm_crypt_lib
spdm_crypt_ext_lib
)
endif()

22 changes: 12 additions & 10 deletions unit_test/test_size/cryptstublib_dummy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
cmake_minimum_required(VERSION 3.5)

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
add_compile_options(-Wno-incompatible-pointer-types -Wno-pointer-sign)
endif()

include_directories(${LIBSPDM_DIR}/include
add_library(cryptstublib_dummy STATIC "")

${LIBSPDM_DIR}/os_stub/include
target_include_directories(cryptstublib_dummy
PRIVATE
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/os_stub/include
)

set(src_cryptstublib_dummy
rand_dummy.c
timeclock_dummy.c
target_sources(cryptstublib_dummy
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/rand_dummy.c
${CMAKE_CURRENT_LIST_DIR}/timeclock_dummy.c
)

add_library(cryptstublib_dummy STATIC ${src_cryptstublib_dummy})
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
target_compile_options(cryptstublib_dummy PRIVATE -Wno-incompatible-pointer-types -Wno-pointer-sign)
endif()
65 changes: 31 additions & 34 deletions unit_test/test_size/intrinsiclib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,45 @@ if(TOOLCHAIN MATCHES "VS")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /GL-")
endif()

if(TOOLCHAIN MATCHES "CLANG")
add_compile_options(-Wno-incompatible-library-redeclaration)
endif()
add_library(intrinsiclib STATIC "")

include_directories(${LIBSPDM_DIR}/include)
target_include_directories(intrinsiclib
PRIVATE
${LIBSPDM_DIR}/include
)

target_sources(intrinsiclib
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/compiler_stub.c
${CMAKE_CURRENT_LIST_DIR}/memory_intrinsics.c
)

if(CMAKE_SYSTEM_NAME MATCHES "Linux")
if(TOOLCHAIN STREQUAL "RISCV_XPACK")
set(src_intrinsiclib
compiler_stub.c
memory_intrinsics.c
ashldi3.c
)
else()
set(src_intrinsiclib
compiler_stub.c
memory_intrinsics.c
target_sources(intrinsiclib
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/ashldi3.c
)
endif()
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows")
if(ARCH STREQUAL "x64")
set(src_intrinsiclib
compiler_stub.c
memory_intrinsics.c
)
elseif(ARCH STREQUAL "ia32")
set(src_intrinsiclib
compiler_stub.c
memory_intrinsics.c
ia32/math_div_s64x64.c
ia32/math_div_s64x64_remainder.c
ia32/math_div_u64x64.c
ia32/math_div_u64x64_remainder.c
ia32/math_ftol.c
ia32/math_lshift_s64.c
ia32/math_mult_s64x64.c
ia32/math_remainder_s64x64.c
ia32/math_remainder_u64x64.c
ia32/math_rShift_s64.c
ia32/math_rShift_u64.c
if(ARCH STREQUAL "ia32")
target_sources(intrinsiclib
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/ia32/math_div_s64x64.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_div_s64x64_remainder.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_div_u64x64.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_div_u64x64_remainder.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_ftol.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_lshift_s64.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_mult_s64x64.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_remainder_s64x64.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_remainder_u64x64.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_rShift_s64.c
${CMAKE_CURRENT_LIST_DIR}/ia32/math_rShift_u64.c
)
endif()
endif()

add_library(intrinsiclib STATIC ${src_intrinsiclib})
if(TOOLCHAIN MATCHES "CLANG")
target_compile_options(intrinsiclib PRIVATE -Wno-incompatible-library-redeclaration)
endif()
12 changes: 8 additions & 4 deletions unit_test/test_size/malloclib_null/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
cmake_minimum_required(VERSION 3.5)

include_directories(${LIBSPDM_DIR}/include)
add_library(malloclib_null STATIC "")

set(src_malloclib_null
malloclib.c
target_include_directories(malloclib_null
PRIVATE
${LIBSPDM_DIR}/include
)

add_library(malloclib_null STATIC ${src_malloclib_null})
target_sources(malloclib_null
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/malloclib.c
)
12 changes: 8 additions & 4 deletions unit_test/test_size/malloclib_simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
cmake_minimum_required(VERSION 3.5)

include_directories(${LIBSPDM_DIR}/include)
add_library(malloclib_simple STATIC "")

set(src_malloclib_simple
malloclib.c
target_include_directories(malloclib_simple
PRIVATE
${LIBSPDM_DIR}/include
)

add_library(malloclib_simple STATIC ${src_malloclib_simple})
target_sources(malloclib_simple
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/malloclib.c
)
14 changes: 9 additions & 5 deletions unit_test/test_size/rnglib_null/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
cmake_minimum_required(VERSION 3.5)

include_directories(${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/include/hal)
add_library(rnglib_null STATIC "")

set(src_rnglib_null
rnglib.c
target_include_directories(rnglib_null
PRIVATE
${LIBSPDM_DIR}/include
${LIBSPDM_DIR}/include/hal
)

add_library(rnglib_null STATIC ${src_rnglib_null})
target_sources(rnglib_null
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/rnglib.c
)
Loading

0 comments on commit ee691ba

Please sign in to comment.