From a6edfea76e24adc57c887b52cc116f3ae7ff669a Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Thu, 10 Mar 2022 17:05:40 -0500 Subject: [PATCH] Clean string comparaison in CMake. When we compare a CMake variable to a string, there is no need to pass it as a string (aka "${}"), we can just use it directly as a named variable. Signed-off-by: George Bosilca --- CMakeLists.txt | 6 +++--- cmake_modules/AddDocumentedFiles.cmake | 4 ++-- cmake_modules/CheckStructureFieldOffset.cmake | 8 ++++---- cmake_modules/FindCython.cmake | 2 +- cmake_modules/FindGD.cmake | 8 ++++---- cmake_modules/ParsecCompilerFlags.cmake | 19 +++++++++---------- docs/CMakeLists.txt | 8 ++++---- parsec/fortran/CMakeLists.txt | 3 +-- 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9e55c10d..b6721c647 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -732,9 +732,9 @@ SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${PARSEC_INSTALL_LIBDIR}" isSystemDir) #MESSAGE(STATUS "LINK_DIRECTORIES = ${CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES}") #MESSAGE(STATUS "INSTALL_PREFIX = ${CMAKE_INSTALL_PREFIX}/${PARSEC_INSTALL_LIBDIR}") -IF("${isSystemDir}" STREQUAL "-1") +IF(isSystemDir STREQUAL "-1") SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PARSEC_INSTALL_LIBDIR}") -ENDIF("${isSystemDir}" STREQUAL "-1") +ENDIF(isSystemDir STREQUAL "-1") # Prepare the list of include directories. From the source directory we need 2 the source # itself and then the specialized headers from parsec/include. If we compile with VPATH @@ -858,7 +858,7 @@ string(REPLACE " " ";" SHM_TEST_CMD_LIST "${CTEST_SHM_LAUNCHER}") set(CTEST_MPI_LAUNCHER "${MPIEXEC} ${MPIEXEC_PREFLAGS} ${MPIEXEC_NUMPROC_FLAG}" CACHE STRING "A command to run distributed memory testings") -if( "${CTEST_MPI_LAUNCHER}" STREQUAL "" ) +if( CTEST_MPI_LAUNCHER STREQUAL "" ) MESSAGE(WARNING "MPI tests will most likely not work: 'CTEST_MPI_LAUNCHER' is not set") endif() string(REPLACE " " ";" MPI_TEST_CMD_LIST "${CTEST_MPI_LAUNCHER}") diff --git a/cmake_modules/AddDocumentedFiles.cmake b/cmake_modules/AddDocumentedFiles.cmake index a4b4756f3..a2d2848f3 100644 --- a/cmake_modules/AddDocumentedFiles.cmake +++ b/cmake_modules/AddDocumentedFiles.cmake @@ -7,13 +7,13 @@ function(add_documented_files) set(multiValueArgs FILES) cmake_parse_arguments(PARSE_ARGV 0 "ADF" "${options}" "${oneValueArgs}" "${multiValueArgs}") - if("${ADF_DIR}" STREQUAL "") + if(ADF_DIR STREQUAL "") set(BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") else() set(BASE_DIR "${ADF_DIR}") endif() - if("${ADF_PROJECT}" STREQUAL "" OR "${ADF_FILES}" STREQUAL "") + if(ADF_PROJECT STREQUAL "" OR ADF_FILES STREQUAL "") MESSAGE(FATAL_ERROR "add_documented_files: need to specify PROJECT (current: '${ADF_PROJECT}') and FILES (current: '${ADF_FILES}')") else() get_property(is_defined GLOBAL PROPERTY ${ADF_PROJECT}_DOX_SRCS DEFINED) diff --git a/cmake_modules/CheckStructureFieldOffset.cmake b/cmake_modules/CheckStructureFieldOffset.cmake index 3ba032d82..1703171d1 100644 --- a/cmake_modules/CheckStructureFieldOffset.cmake +++ b/cmake_modules/CheckStructureFieldOffset.cmake @@ -110,12 +110,12 @@ function(__check_structure_field_offset_impl field structure var map language) set(mismatch) set(first 1) foreach(info ${strings}) - if("${info}" MATCHES "${regex_offset}") + if(info MATCHES "${regex_offset}") # Get the type size. set(offset "${CMAKE_MATCH_1}") if(first) set(${var} ${offset}) - elseif(NOT "${offset}" STREQUAL "${${var}}") + elseif(NOT offset STREQUAL "${${var}}") set(mismatch 1) endif() set(first 0) @@ -166,10 +166,10 @@ macro(CHECK_STRUCTURE_FIELD_OFFSET FIELD STRUCTURE VARIABLE) # parse arguments unset(doing) foreach(arg ${ARGN}) - if("x${arg}" STREQUAL "xLANGUAGE") # change to MATCHES for more keys + if(arg STREQUAL "LANGUAGE") # change to MATCHES for more keys set(doing "${arg}") set(_CHECK_STRUCTURE_FIELD_OFFSET_${doing} "") - elseif("x${doing}" STREQUAL "xLANGUAGE") + elseif(doing STREQUAL "LANGUAGE") set(_CHECK_STRUCTURE_FIELD_OFFSET_${doing} "${arg}") unset(doing) else() diff --git a/cmake_modules/FindCython.cmake b/cmake_modules/FindCython.cmake index c138ab3b3..4ebf6071c 100644 --- a/cmake_modules/FindCython.cmake +++ b/cmake_modules/FindCython.cmake @@ -47,7 +47,7 @@ if( CYTHON_EXECUTABLE ) OUTPUT_QUIET ERROR_STRIP_TRAILING_WHITESPACE) string(REPLACE "Cython version " "" CYTHON_VERSION "${CYTHON_OUTPUT}") - if( "${CYTHON_VERSION}" VERSION_LESS "0.19.1" ) + if( CYTHON_VERSION VERSION_LESS "0.19.1" ) MESSAGE(STATUS "Cython version ${CYTHON_VERSION} found -- too old for current code") unset(CYTHON_EXECUTABLE CACHE) else() diff --git a/cmake_modules/FindGD.cmake b/cmake_modules/FindGD.cmake index ce6c959b4..7111715fe 100644 --- a/cmake_modules/FindGD.cmake +++ b/cmake_modules/FindGD.cmake @@ -71,9 +71,9 @@ IF (GD_FOUND) FOREACH(GD_DIR ${GD_INCLUDE_DIR}) SET(GD_TMP_FOUND OFF) FOREACH(GD_TRIMMED ${GDINCTRIM}) - IF ("${GD_DIR}" STREQUAL "${GD_TRIMMED}") + IF (GD_DIR STREQUAL GD_TRIMMED) SET(GD_TMP_FOUND ON) - ENDIF ("${GD_DIR}" STREQUAL "${GD_TRIMMED}") + ENDIF (GD_DIR STREQUAL GD_TRIMMED) ENDFOREACH(GD_TRIMMED ${GDINCTRIM}) IF (NOT GD_TMP_FOUND) SET(GDINCTRIM "${GDINCTRIM}" "${GD_DIR}") @@ -88,9 +88,9 @@ IF (GD_FOUND) GET_FILENAME_COMPONENT(GD_NEXTLIBDIR ${GD_LIB} PATH) SET(GD_TMP_FOUND OFF) FOREACH(GD_LIBDIR ${GD_LIBRARY_DIR}) - IF ("${GD_NEXTLIBDIR}" STREQUAL "${GD_LIBDIR}") + IF (GD_NEXTLIBDIR STREQUAL GD_LIBDIR) SET(GD_TMP_FOUND ON) - ENDIF ("${GD_NEXTLIBDIR}" STREQUAL "${GD_LIBDIR}") + ENDIF (GD_NEXTLIBDIR STREQUAL GD_LIBDIR) ENDFOREACH(GD_LIBDIR ${GD_LIBRARIES}) IF (NOT GD_TMP_FOUND) SET(GD_LIBRARY_DIR "${GD_LIBRARY_DIR}" "${GD_NEXTLIBDIR}") diff --git a/cmake_modules/ParsecCompilerFlags.cmake b/cmake_modules/ParsecCompilerFlags.cmake index dbdac9e98..e5752d051 100644 --- a/cmake_modules/ParsecCompilerFlags.cmake +++ b/cmake_modules/ParsecCompilerFlags.cmake @@ -62,11 +62,11 @@ function(check_and_set_compiler_option) endif() endforeach() set(CMAKE_REQUIRED_QUIET ${save_CMAKE_REQUIRED_QUIET}) - if( "${_supported_languages}" STREQUAL "" ) + if( _supported_languages STREQUAL "" ) message(CHECK_FAIL "[none]") - else( "${_supported_languages}" STREQUAL "" ) + else( _supported_languages STREQUAL "" ) message(CHECK_PASS "[${_supported_languages}]") - endif( "${_supported_languages}" STREQUAL "" ) + endif( _supported_languages STREQUAL "" ) if(DEFINED parsec_cas_co_COMMENT) set(${parsec_cas_co_NAME} "${parsec_cas_co_defined_options}" CACHE STRING "${parsec_cas_co_COMMENT}") @@ -106,7 +106,7 @@ if(NOT CMAKE_SYSTEM_NAME MATCHES "Windows") if( _match_xlc) set( arch_build "-q64" ) else (_match_xlc) - if( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "sparc64fx" ) + if( CMAKE_SYSTEM_PROCESSOR STREQUAL "sparc64fx" ) set ( arch_build " " ) else() set( arch_build "-m64" ) @@ -168,8 +168,7 @@ if(_match_icc) endif(_match_icc) # remove asserts in release -add_compile_definitions( - $<$:NDEBUG>) +add_compile_definitions($<$:NDEBUG>) if(CMAKE_GENERATOR STREQUAL "Ninja") # Ninja is weird with colors. It does not present a pty to cc (hence @@ -187,9 +186,9 @@ endif() if(CMAKE_Fortran_COMPILER_WORKS) get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME) # message(STATUS "Fortran Compiler ${Fortran_COMPILER_NAME} id is ${CMAKE_Fortran_COMPILER_ID}") - if(${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU") + if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") # gfortran or g77 - if(${Fortran_COMPILER_NAME} MATCHES g77) + if(Fortran_COMPILER_NAME MATCHES g77) add_compile_options("$<$:-fno-f2c>") endif() # We append the implicit fortran link flags for the case where FC=/somepath/f90 @@ -200,11 +199,11 @@ if(CMAKE_Fortran_COMPILER_WORKS) list(APPEND EXTRA_LIBS "-L${item}") endforeach() list(APPEND EXTRA_LIBS ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES}) - elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel") + elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") # ifort add_compile_options("$<$:-f77rtl>") # This is a bug in CMake, which incorrectly adds this flag that does not exist on some ifort versions. string (REPLACE "-i_dynamic" "" CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_Fortran_FLAGS}") - endif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU") + endif (CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") endif(CMAKE_Fortran_COMPILER_WORKS) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 0bfd8df9b..d0ae45c4f 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -9,17 +9,17 @@ if (BUILD_DOCUMENTATION) find_package(Doxygen) if (DOXYGEN_FOUND) - if(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}") + if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) message(STATUS "PaRSEC is pulled as a submodule -- Not generating documentation") return() - elseif( ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR} ) + elseif(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) message(FATAL_ERROR "Because PaRSEC generates many source files at compile time, " "no documentation will be generated when building directly within " "the source directory. To generate the documentation, re-configure " "and compile from an out-of-source directory (look for " "Out-of-source build trees with CMake for documentation)") - else(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}") + else(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) get_property(SRCS GLOBAL PROPERTY PARSEC_DOX_SRCS) string (REPLACE ";" " " PARSEC_DOX_SRCS "${SRCS}") @@ -37,7 +37,7 @@ if (BUILD_DOCUMENTATION) #-- Add a custom target to run Doxygen when the project is built add_custom_target(docs-parsec DEPENDS parsec ${CMAKE_CURRENT_BINARY_DIR}/doxygen/doxygen.stamp ) message(STATUS "PaRSEC documentation can be generated with target 'docs-parsec' after the library is compiled") - endif(NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}") + endif(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) else (DOXYGEN_FOUND) message(FATAL_ERROR "Documentation generation requested but Doxygen application could not be found. Either install Doygen or disable the documentation generation (BUILD_DOCUMENTATION to OFF)") endif (DOXYGEN_FOUND) diff --git a/parsec/fortran/CMakeLists.txt b/parsec/fortran/CMakeLists.txt index 814f9e136..f6886abcd 100644 --- a/parsec/fortran/CMakeLists.txt +++ b/parsec/fortran/CMakeLists.txt @@ -1,8 +1,7 @@ include(FortranCInterface) FortranCInterface_HEADER(f2c_mangle.h MACRO_NAMESPACE "PARSEC_F2C_" - SYMBOL_NAMESPACE "parsec_f2c_" - SYMBOLS my_sub parsecf:my_sub) + SYMBOL_NAMESPACE "parsec_f2c_") set(sources parsecf.F90 parsecf.c)