This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 2432a62ab  fix cmake code smell issues
2432a62ab is described below

commit 2432a62ab6f5a496b278e5a1cba4474410584d24
Author: xuxin19 <[email protected]>
AuthorDate: Mon Sep 4 11:04:29 2023 +0800

     fix cmake code smell issues
    
    Signed-off-by: xuxin19 <[email protected]>
---
 benchmarks/coremark/CMakeLists.txt    |  5 ++---
 canutils/lely-canopen/CMakeLists.txt  |  5 +----
 canutils/libdronecan/CMakeLists.txt   |  4 +---
 canutils/libopencyphal/CMakeLists.txt |  6 ++----
 crypto/libsodium/CMakeLists.txt       |  8 +++----
 crypto/libtomcrypt/CMakeLists.txt     | 16 ++++++--------
 crypto/mbedtls/CMakeLists.txt         | 25 +++++++++++-----------
 crypto/tinycrypt/CMakeLists.txt       | 40 ++++++++++++++++-------------------
 fsutils/inih/CMakeLists.txt           |  4 +---
 fsutils/libtinycbor/CMakeLists.txt    |  2 +-
 math/libtommath/CMakeLists.txt        |  6 ++----
 11 files changed, 49 insertions(+), 72 deletions(-)

diff --git a/benchmarks/coremark/CMakeLists.txt 
b/benchmarks/coremark/CMakeLists.txt
index eaeb577d7..c24915eaf 100644
--- a/benchmarks/coremark/CMakeLists.txt
+++ b/benchmarks/coremark/CMakeLists.txt
@@ -25,7 +25,8 @@ if(CONFIG_BENCHMARK_COREMARK)
   # 
############################################################################
 
   set(COREMARKAPP_DIR ${CMAKE_CURRENT_LIST_DIR}/coremark)
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/coremark)
+
+  if(NOT EXISTS ${COREMARKAPP_DIR})
     FetchContent_Declare(
       coremark_fetch
       URL https://github.com/eembc/coremark/archive/main.zip SOURCE_DIR
@@ -38,8 +39,6 @@ if(CONFIG_BENCHMARK_COREMARK)
     if(NOT coremark_fetch_POPULATED)
       FetchContent_Populate(coremark_fetch)
     endif()
-
-    set(COREMARKAPP_DIR ${coremark_fetch_SOURCE_DIR})
   endif()
 
   if(CONFIG_COREMARK_MULTITHREAD_OVERRIDE)
diff --git a/canutils/lely-canopen/CMakeLists.txt 
b/canutils/lely-canopen/CMakeLists.txt
index c53586410..380bd4909 100644
--- a/canutils/lely-canopen/CMakeLists.txt
+++ b/canutils/lely-canopen/CMakeLists.txt
@@ -26,7 +26,7 @@ if(CONFIG_CANUTILS_LELYCANOPEN)
 
   set(LELYCANOPEN_DIR ${CMAKE_CURRENT_LIST_DIR}/lely-canopen)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/lely-canopen)
+  if(NOT EXISTS ${LELYCANOPEN_DIR})
     FetchContent_Declare(
       lelycanopen_fetch
       URL 
${CONFIG_CANUTILS_LELYCANOPEN_URL}/lely-core-${CONFIG_CANUTILS_LELYCANOPEN_VERSION}.tar.gz
@@ -44,9 +44,6 @@ if(CONFIG_CANUTILS_LELYCANOPEN)
     if(NOT lelycanopen_fetch_POPULATED)
       FetchContent_Populate(lelycanopen_fetch)
     endif()
-
-    set(LELYCANOPEN_DIR ${lelycanopen_fetch_SOURCE_DIR})
-
   endif()
 
   nuttx_add_library(lelycanopen STATIC)
diff --git a/canutils/libdronecan/CMakeLists.txt 
b/canutils/libdronecan/CMakeLists.txt
index 5aa2afd30..feb29e354 100644
--- a/canutils/libdronecan/CMakeLists.txt
+++ b/canutils/libdronecan/CMakeLists.txt
@@ -26,7 +26,7 @@ if(CONFIG_CANUTILS_LIBDRONECAN)
 
   set(LIBDRONECAN_DIR ${CMAKE_CURRENT_LIST_DIR}/libcanard)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libcanard)
+  if(NOT EXISTS ${LIBDRONECAN_DIR})
     FetchContent_Declare(
       libdronecan_fetch
       URL ${CONFIG_LIBDRONECAN_URL}/${CONFIG_LIBDRONECAN_VERSION}.zip 
SOURCE_DIR
@@ -40,8 +40,6 @@ if(CONFIG_CANUTILS_LIBDRONECAN)
     if(NOT libdronecan_fetch_POPULATED)
       FetchContent_Populate(libdronecan_fetch)
     endif()
-
-    set(LIBDRONECAN_DIR ${libdronecan_fetch_SOURCE_DIR})
   endif()
 
   # 
############################################################################
diff --git a/canutils/libopencyphal/CMakeLists.txt 
b/canutils/libopencyphal/CMakeLists.txt
index 41a4bdf6e..d79becba0 100644
--- a/canutils/libopencyphal/CMakeLists.txt
+++ b/canutils/libopencyphal/CMakeLists.txt
@@ -25,7 +25,7 @@ if(CONFIG_CANUTILS_LIBOPENCYPHAL)
   # 
############################################################################
 
   set(LIBOPENCYPHAL_DIR ${CMAKE_CURRENT_LIST_DIR}/libcanard)
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libcanard)
+  if(NOT EXISTS ${LIBOPENCYPHAL_DIR})
     FetchContent_Declare(
       libcanard_fetch
       URL ${CONFIG_LIBOPENCYPHAL_URL}/${CONFIG_LIBOPENCYPHAL_VERSION}.zip
@@ -37,11 +37,10 @@ if(CONFIG_CANUTILS_LIBOPENCYPHAL)
     if(NOT libcanard_fetch_POPULATED)
       FetchContent_Populate(libcanard_fetch)
     endif()
-    set(LIBOPENCYPHAL_DIR ${libcanard_fetch_SOURCE_DIR})
   endif()
 
   set(O1HEAP_DIR ${CMAKE_CURRENT_LIST_DIR}/o1heap)
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/o1heap)
+  if(NOT EXISTS ${O1HEAP_DIR})
     FetchContent_Declare(
       o1heap_fetch
       URL ${CONFIG_O1HEAP_URL}/${CONFIG_O1HEAP_VERSION}.zip SOURCE_DIR
@@ -53,7 +52,6 @@ if(CONFIG_CANUTILS_LIBOPENCYPHAL)
     if(NOT o1heap_fetch_POPULATED)
       FetchContent_Populate(o1heap_fetch)
     endif()
-    set(O1HEAP_DIR ${o1heap_fetch_SOURCE_DIR})
   endif()
 
   # 
############################################################################
diff --git a/crypto/libsodium/CMakeLists.txt b/crypto/libsodium/CMakeLists.txt
index d00c828e5..db9097811 100644
--- a/crypto/libsodium/CMakeLists.txt
+++ b/crypto/libsodium/CMakeLists.txt
@@ -23,11 +23,11 @@ if(CONFIG_LIBSODIUM)
   # 
############################################################################
   # Config and Fetch libsodium lib
   # 
############################################################################
-  set(LIBSODIUM_URL https://github.com/jedisct1/libsodium/archive)
-
   set(LIBSODIUM_DIR ${CMAKE_CURRENT_LIST_DIR}/libsodium)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libsodium)
+  if(NOT EXISTS ${LIBSODIUM_DIR})
+    set(LIBSODIUM_URL https://github.com/jedisct1/libsodium/archive)
+
     FetchContent_Declare(
       libsodium_fetch
       URL ${LIBSODIUM_URL}/${CONFIG_LIBSODIUM_VERSION}.zip SOURCE_DIR
@@ -46,8 +46,6 @@ if(CONFIG_LIBSODIUM)
     if(NOT libsodium_fetch_POPULATED)
       FetchContent_Populate(libsodium_fetch)
     endif()
-    set(LIBSODIUM_DIR ${libsodium_fetch_SOURCE_DIR})
-
   endif()
 
   # 
############################################################################
diff --git a/crypto/libtomcrypt/CMakeLists.txt 
b/crypto/libtomcrypt/CMakeLists.txt
index febb7d238..0811bf1d5 100644
--- a/crypto/libtomcrypt/CMakeLists.txt
+++ b/crypto/libtomcrypt/CMakeLists.txt
@@ -23,12 +23,11 @@ if(CONFIG_CRYPTO_LIBTOMCRYPT)
   # 
############################################################################
   # Config and Fetch libtomcrypt
   # 
############################################################################
-
-  set(CONFIG_LIBTOMCRYPT_URL https://github.com/libtom/libtomcrypt/archive)
-
   set(LIBTOMCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/libtomcrypt)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libtomcrypt)
+  if(NOT EXISTS ${LIBTOMCRYPT_DIR})
+    set(CONFIG_LIBTOMCRYPT_URL https://github.com/libtom/libtomcrypt/archive)
+
     FetchContent_Declare(
       libtomcrypt_fetch
       URL ${CONFIG_LIBTOMCRYPT_URL}/v${CONFIG_LIBTOMCRYPT_VERSION}.zip
@@ -47,9 +46,6 @@ if(CONFIG_CRYPTO_LIBTOMCRYPT)
     if(NOT libtomcrypt_fetch_POPULATED)
       FetchContent_Populate(libtomcrypt_fetch)
     endif()
-
-    set(LIBTOMCRYPT_DIR ${libtomcrypt_fetch_SOURCE_DIR})
-
   endif()
 
   nuttx_add_library(libtomcrypt STATIC)
@@ -496,7 +492,7 @@ if(CONFIG_CRYPTO_LIBTOMCRYPT)
         DEPENDS
         libtomcrypt)
 
-    endif(CONFIG_LIBTOMCRYPT_LTCRYPT)
+    endif()
 
     if(CONFIG_LIBTOMCRYPT_HASHSUM)
 
@@ -514,9 +510,9 @@ if(CONFIG_CRYPTO_LIBTOMCRYPT)
         DEPENDS
         libtomcrypt)
 
-    endif(CONFIG_LIBTOMCRYPT_HASHSUM)
+    endif()
 
-  endif(CONFIG_LIBTOMCRYPT_DEMOS)
+  endif()
 
   # 
############################################################################
   # Library Configuration
diff --git a/crypto/mbedtls/CMakeLists.txt b/crypto/mbedtls/CMakeLists.txt
index bd1c03405..b7e5ee287 100644
--- a/crypto/mbedtls/CMakeLists.txt
+++ b/crypto/mbedtls/CMakeLists.txt
@@ -23,11 +23,11 @@ if(CONFIG_CRYPTO_MBEDTLS)
   # 
############################################################################
   # Config and Fetch MbedTLS lib
   # 
############################################################################
-  set(MBEDTLS_URL https://github.com/ARMmbed/mbedtls/archive)
 
   set(MBEDTLS_DIR ${CMAKE_CURRENT_LIST_DIR}/mbedtls)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/mbedtls)
+  if(NOT EXISTS ${MBEDTLS_DIR})
+    set(MBEDTLS_URL https://github.com/ARMmbed/mbedtls/archive)
     FetchContent_Declare(
       mbedtls_fetch
       URL ${MBEDTLS_URL}/v${CONFIG_MBEDTLS_VERSION}.zip SOURCE_DIR
@@ -41,7 +41,6 @@ if(CONFIG_CRYPTO_MBEDTLS)
     if(NOT mbedtls_fetch_POPULATED)
       FetchContent_Populate(mbedtls_fetch)
     endif()
-    set(MBEDTLS_DIR ${mbedtls_fetch_SOURCE_DIR})
   endif()
 
   # 
############################################################################
@@ -51,7 +50,7 @@ if(CONFIG_CRYPTO_MBEDTLS)
   set_source_files_properties(${MBEDTLS_DIR}/library/bignum.c
                               PROPERTIES COMPILE_FLAGS -fno-lto)
 
-  if(CONFIG_FRAME_POINTER STREQUAL y)
+  if(CONFIG_FRAME_POINTER)
     if(CONFIG_DEBUG_OPTLEVEL STREQUAL -O3)
       set_source_files_properties(${MBEDTLS_DIR}/library/sha246.c
                                   PROPERTIES COMPILE_FLAGS -O2)
@@ -74,14 +73,14 @@ if(CONFIG_CRYPTO_MBEDTLS)
   # Library Configuration
   # 
############################################################################
 
-  nuttx_add_library(mbedtls_nuttx STATIC)
+  nuttx_add_library(mbedtls STATIC)
 
-  target_sources(mbedtls_nuttx PRIVATE ${CSRCS})
-  target_include_directories(mbedtls_nuttx PRIVATE ${INCDIR})
-  target_compile_definitions(mbedtls_nuttx PRIVATE __unix__)
+  target_sources(mbedtls PRIVATE ${CSRCS})
+  target_include_directories(mbedtls PRIVATE ${INCDIR})
+  target_compile_definitions(mbedtls PRIVATE __unix__)
 
-  if(CONFIG_ARCH_SIM STREQUAL y)
-    target_compile_options(mbedtls_nuttx PRIVATE -O0)
+  if(CONFIG_ARCH_SIM)
+    target_compile_options(mbedtls PRIVATE -O0)
   endif()
 
   # 
############################################################################
@@ -90,7 +89,7 @@ if(CONFIG_CRYPTO_MBEDTLS)
 
   if(CONFIG_MBEDTLS_APPS)
 
-    if(CONFIG_MBEDTLS_APP_BENCHMARK STREQUAL y)
+    if(CONFIG_MBEDTLS_APP_BENCHMARK)
       nuttx_add_application(
         MODULE
         ${CONFIG_MBEDTLS_APPS}
@@ -108,7 +107,7 @@ if(CONFIG_CRYPTO_MBEDTLS)
         mbedtls_nuttx)
     endif()
 
-    if(CONFIG_MBEDTLS_APP_SELFTEST STREQUAL y)
+    if(CONFIG_MBEDTLS_APP_SELFTEST)
       nuttx_add_application(
         MODULE
         ${CONFIG_MBEDTLS_APPS}
@@ -126,6 +125,6 @@ if(CONFIG_CRYPTO_MBEDTLS)
         mbedtls_nuttx)
     endif()
 
-  endif(CONFIG_MBEDTLS_APPS)
+  endif()
 
 endif()
diff --git a/crypto/tinycrypt/CMakeLists.txt b/crypto/tinycrypt/CMakeLists.txt
index ed90ee537..fd9781797 100644
--- a/crypto/tinycrypt/CMakeLists.txt
+++ b/crypto/tinycrypt/CMakeLists.txt
@@ -23,16 +23,14 @@ if(CONFIG_TINYCRYPT)
   # 
############################################################################
   # Config and Fetch tinycrypt
   # 
############################################################################
-
-  set(TINYCRYPT_VERSION ${CONFIG_TINYCRYPT_VERSION})
-
-  set(TINYCRYPT_URL
-      
https://github.com/intel/tinycrypt/archive/refs/tags/v${TINYCRYPT_VERSION}.zip
-  )
-
   set(TINYCRYPT_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycrypt)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/tinycrypt)
+  if(NOT EXISTS ${TINYCRYPT_DIR})
+    set(TINYCRYPT_VERSION ${CONFIG_TINYCRYPT_VERSION})
+
+    set(TINYCRYPT_URL
+        
https://github.com/intel/tinycrypt/archive/refs/tags/v${TINYCRYPT_VERSION}.zip
+    )
     FetchContent_Declare(
       tinycrypt_fetch
       URL ${TINYCRYPT_URL} SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycrypt
@@ -48,8 +46,6 @@ if(CONFIG_TINYCRYPT)
     if(NOT tinycrypt_fetch_POPULATED)
       FetchContent_Populate(tinycrypt_fetch)
     endif()
-    set(TINYCRYPT_DIR ${tinycrypt_fetch_SOURCE_DIR})
-
   endif()
 
   nuttx_add_library(tinycrypt STATIC)
@@ -68,48 +64,48 @@ if(CONFIG_TINYCRYPT)
       ${TINYCRYPT_DIR}/lib/source/utils.c ${TINYCRYPT_DIR}/lib/source/ecc.c
       ${TINYCRYPT_DIR}/lib/source/ecc_platform_specific.c)
 
-  if(CONFIG_TINYCRYPT_ECC_DH STREQUAL y)
+  if(CONFIG_TINYCRYPT_ECC_DH)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ecc_dh.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_ECC_DSA STREQUAL y)
+  if(CONFIG_TINYCRYPT_ECC_DSA)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ecc_dsa.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_AES STREQUAL y)
+  if(CONFIG_TINYCRYPT_AES)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/aes_encrypt.c
          ${TINYCRYPT_DIR}/lib/source/aes_decrypt.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_AES_CBC STREQUAL y)
+  if(CONFIG_TINYCRYPT_AES_CBC)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/cbc_mode.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_AES_CTR STREQUAL y)
+  if(CONFIG_TINYCRYPT_AES_CTR)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ctr_mode.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_AES_CCM STREQUAL y)
+  if(CONFIG_TINYCRYPT_AES_CCM)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ccm_mode.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_AES_CMAC STREQUAL y)
+  if(CONFIG_TINYCRYPT_AES_CMAC)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/cmac_mode.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_SHA256 STREQUAL y)
+  if(CONFIG_TINYCRYPT_SHA256)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/sha256.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_SHA256_HMAC STREQUAL y)
+  if(CONFIG_TINYCRYPT_SHA256_HMAC)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/hmac.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_SHA256_HMAC_PRNG STREQUAL y)
+  if(CONFIG_TINYCRYPT_SHA256_HMAC_PRNG)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/hmac_prng.c)
   endif()
 
-  if(CONFIG_TINYCRYPT_CTR_PRNG STREQUAL y)
+  if(CONFIG_TINYCRYPT_CTR_PRNG)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/lib/source/ctr_prng.c)
   endif()
 
@@ -117,7 +113,7 @@ if(CONFIG_TINYCRYPT)
   # Applications Configuration
   # 
############################################################################
 
-  if(CONFIG_TINYCRYPT_TEST STREQUAL y)
+  if(CONFIG_TINYCRYPT_TEST)
     list(APPEND CSRCS ${TINYCRYPT_DIR}/tests/test_ecc_utils.c)
     list(APPEND INCDIR ${TINYCRYPT_DIR}/tests/include)
     set(CFLAGS -Dhex2bin=ltp_hex2bin -DENABLE_TESTS)
diff --git a/fsutils/inih/CMakeLists.txt b/fsutils/inih/CMakeLists.txt
index 8f371350e..ddf779bd5 100644
--- a/fsutils/inih/CMakeLists.txt
+++ b/fsutils/inih/CMakeLists.txt
@@ -25,7 +25,7 @@ if(CONFIG_FSUTILS_INIH)
   # 
############################################################################
   set(INIH_DIR ${CMAKE_CURRENT_LIST_DIR}/inih-r42)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/inih-r42)
+  if(NOT EXISTS ${INIH_DIR})
     set(INIH_URL https://github.com/benhoyt/inih/archive/r42.tar.gz)
     FetchContent_Declare(
       inih_fetch
@@ -38,8 +38,6 @@ if(CONFIG_FSUTILS_INIH)
     if(NOT inih_fetch_POPULATED)
       FetchContent_Populate(inih_fetch)
     endif()
-
-    set(INIH_DIR ${inih_fetch_SOURCE_DIR})
   endif()
 
   # 
############################################################################
diff --git a/fsutils/libtinycbor/CMakeLists.txt 
b/fsutils/libtinycbor/CMakeLists.txt
index 38f5be0e4..e18b56577 100644
--- a/fsutils/libtinycbor/CMakeLists.txt
+++ b/fsutils/libtinycbor/CMakeLists.txt
@@ -25,7 +25,7 @@ if(CONFIG_FSUTILS_TINYCBOR_LIB)
   # 
############################################################################
   set(TINYCBOR_DIR ${CMAKE_CURRENT_LIST_DIR}/tinycbor)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/tinycbor)
+  if(NOT EXISTS ${TINYCBOR_DIR})
     set(TINYCBOR_VERSION 3cba6b11aaa0f6f674cd56ebaa573c4b65f71ee7)
     set(TINYCBOR_URL
         https://github.com/intel/tinycbor/archive/${TINYCBOR_VERSION}.zip)
diff --git a/math/libtommath/CMakeLists.txt b/math/libtommath/CMakeLists.txt
index 83a6798dc..b6c5c6f0a 100644
--- a/math/libtommath/CMakeLists.txt
+++ b/math/libtommath/CMakeLists.txt
@@ -23,11 +23,11 @@ if(CONFIG_MATH_LIBTOMMATH)
   # 
############################################################################
   # Config and Fetch Tommath lib
   # 
############################################################################
-  set(CONFIG_LIBTOMMATH_URL https://github.com/libtom/libtommath/archive)
 
   set(LIBTOMMATH_DIR ${CMAKE_CURRENT_LIST_DIR}/libtommath)
 
-  if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/libtommath)
+  if(NOT EXISTS ${LIBTOMMATH_DIR})
+    set(CONFIG_LIBTOMMATH_URL https://github.com/libtom/libtommath/archive)
     FetchContent_Declare(
       libtommath_fetch
       URL ${CONFIG_LIBTOMMATH_URL}/v${CONFIG_LIBTOMMATH_VERSION}.zip SOURCE_DIR
@@ -40,8 +40,6 @@ if(CONFIG_MATH_LIBTOMMATH)
     if(NOT libtommath_fetch_POPULATED)
       FetchContent_Populate(libtommath_fetch)
     endif()
-
-    set(LIBTOMMATH_DIR ${libtommath_fetch_SOURCE_DIR})
   endif()
 
   # 
############################################################################

Reply via email to