[openmp][cmake][NFCI] Avoid non-eval uses of ${var} (#182267)

When using

    set(var "Example")
    if (${var})

CMake will first resolve the if-argument to

    if (Example)

And what then happens depends on the existance of a variable with the
name "Example":

1. If instead of "Example", a truth constant is used ("TRUE", "FALSE",
   "ON", "OFF", "", "-NOTFOUND" ...), it is prioritized
   (https://cmake.org/cmake/help/latest/command/if.html#constant)

2. If a variable with the name "Example" exists: Use the truthiness of
   its content
   (https://cmake.org/cmake/help/latest/command/if.html#variable)

3. Otherwise, it is false-y

That is, the the result of the conditional does not only depend on the
content of `var`, but also some other variable. This is usually
unintended and leads to problems such as addressed with #154537. The
only case where this is intended is when passing an expression to be
evaluated such as with `pythonize_bool`, `append_if` and
`libomp_append`. In all other cases, using `${var}` without quotes is a
pattern to be avoided.

Remark:
If `${var}` is not one of the values considered a [truthiness
constant](https://cmake.org/cmake/help/latest/command/if.html#constant),
the result of `if (var)` and `if ("${var}")` is different:

* `if (var)` is true-ish
  (https://cmake.org/cmake/help/latest/command/if.html#variable)

* `if ("Example")` and therefore `if ("${var}")` are false-y
  (https://cmake.org/cmake/help/latest/command/if.html#string)

In this PR I am preferring `if (var)` over `if ("${var}")` because has
less clutter, resembles Python's behaviour, and problably what most
users are expecting, even though `if (${var})` in most cases would
evaluate to false-y because a variable does not exist. This ambiguity
does not exist for STREQUAL and MATCHES.
This commit is contained in:
Michael Kruse
2026-03-02 13:21:36 +01:00
committed by GitHub
parent b39247c391
commit 87cbea6cdc
10 changed files with 81 additions and 81 deletions

View File

@@ -48,7 +48,7 @@ function(libomp_get_cxxflags cxxflags)
libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG) libomp_append(flags_local /GS LIBOMP_HAVE_GS_FLAG)
libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG) libomp_append(flags_local /EHsc LIBOMP_HAVE_EHSC_FLAG)
libomp_append(flags_local /Oy- LIBOMP_HAVE_OY__FLAG) libomp_append(flags_local /Oy- LIBOMP_HAVE_OY__FLAG)
if(${IA32} OR ${INTEL64}) if(IA32 OR INTEL64)
libomp_append(flags_local -mrtm LIBOMP_HAVE_MRTM_FLAG) libomp_append(flags_local -mrtm LIBOMP_HAVE_MRTM_FLAG)
endif() endif()
# Intel(R) C Compiler flags # Intel(R) C Compiler flags
@@ -56,18 +56,18 @@ function(libomp_get_cxxflags cxxflags)
libomp_append(flags_local -Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG) libomp_append(flags_local -Qoption,cpp,--extended_float_types LIBOMP_HAVE_EXTENDED_FLOAT_TYPES_FLAG)
libomp_append(flags_local -Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG) libomp_append(flags_local -Qlong_double LIBOMP_HAVE_LONG_DOUBLE_FLAG)
libomp_append(flags_local -Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG) libomp_append(flags_local -Qdiag-disable:177 LIBOMP_HAVE_DIAG_DISABLE_177_FLAG)
if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD}) if(RELEASE_BUILD OR RELWITHDEBINFO_BUILD)
libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG) libomp_append(flags_local -Qinline-min-size=1 LIBOMP_HAVE_INLINE_MIN_SIZE_FLAG)
endif() endif()
# Architectural C and C++ flags # Architectural C and C++ flags
if(CMAKE_SIZEOF_VOID_P EQUAL 4) if(CMAKE_SIZEOF_VOID_P EQUAL 4)
libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG) libomp_append(flags_local -m32 LIBOMP_HAVE_M32_FLAG)
endif() endif()
if(${IA32}) if(IA32)
libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG) libomp_append(flags_local /arch:SSE2 LIBOMP_HAVE_ARCH_SSE2_FLAG)
libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) libomp_append(flags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG)
libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG) libomp_append(flags_local -falign-stack=maintain-16-byte LIBOMP_HAVE_FALIGN_STACK_FLAG)
elseif(${MIC}) elseif(MIC)
libomp_append(flags_local -mmic LIBOMP_HAVE_MMIC_FLAG) libomp_append(flags_local -mmic LIBOMP_HAVE_MMIC_FLAG)
libomp_append(flags_local -ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG) libomp_append(flags_local -ftls-model=initial-exec LIBOMP_HAVE_FTLS_MODEL_FLAG)
libomp_append(flags_local "-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG) libomp_append(flags_local "-opt-streaming-stores never" LIBOMP_HAVE_OPT_STREAMING_STORES_FLAG)
@@ -84,10 +84,10 @@ function(libomp_get_asmflags asmflags)
if(CMAKE_SIZEOF_VOID_P EQUAL 4) if(CMAKE_SIZEOF_VOID_P EQUAL 4)
libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG) libomp_append(asmflags_local -m32 LIBOMP_HAVE_M32_FLAG)
endif() endif()
if(${IA32}) if(IA32)
libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG) libomp_append(asmflags_local /safeseh LIBOMP_HAVE_SAFESEH_MASM_FLAG)
libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG) libomp_append(asmflags_local /coff LIBOMP_HAVE_COFF_MASM_FLAG)
elseif(${MIC}) elseif(MIC)
libomp_append(asmflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) libomp_append(asmflags_local -mmic LIBOMP_HAVE_MMIC_FLAG)
endif() endif()
set(asmflags_local ${asmflags_local} ${LIBOMP_ASMFLAGS}) set(asmflags_local ${asmflags_local} ${LIBOMP_ASMFLAGS})
@@ -120,9 +120,9 @@ function(libomp_get_ldflags ldflags)
if(CMAKE_SIZEOF_VOID_P EQUAL 4) if(CMAKE_SIZEOF_VOID_P EQUAL 4)
libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG) libomp_append(ldflags_local -m32 LIBOMP_HAVE_M32_FLAG)
endif() endif()
if(${IA32}) if(IA32)
libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG) libomp_append(ldflags_local -msse2 LIBOMP_HAVE_MSSE2_FLAG)
elseif(${MIC}) elseif(MIC)
libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG) libomp_append(ldflags_local -mmic LIBOMP_HAVE_MMIC_FLAG)
libomp_append(ldflags_local -Wl,-x LIBOMP_HAVE_X_FLAG) libomp_append(ldflags_local -Wl,-x LIBOMP_HAVE_X_FLAG)
endif() endif()
@@ -136,7 +136,7 @@ function(libomp_get_libflags libflags)
set(libflags_local) set(libflags_local)
libomp_append(libflags_local "${CMAKE_THREAD_LIBS_INIT}") libomp_append(libflags_local "${CMAKE_THREAD_LIBS_INIT}")
libomp_append(libflags_local "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC) libomp_append(libflags_local "${LIBOMP_HWLOC_LIBRARY}" LIBOMP_USE_HWLOC)
if(${IA32}) if(IA32)
libomp_append(libflags_local -lirc_pic LIBOMP_HAVE_IRC_PIC_LIBRARY) libomp_append(libflags_local -lirc_pic LIBOMP_HAVE_IRC_PIC_LIBRARY)
endif() endif()
if(MINGW) if(MINGW)
@@ -175,10 +175,10 @@ endfunction()
# Python generate-defs.py flags (For Windows only) # Python generate-defs.py flags (For Windows only)
function(libomp_get_gdflags gdflags) function(libomp_get_gdflags gdflags)
set(gdflags_local) set(gdflags_local)
if(${IA32}) if(IA32)
set(libomp_gdflag_arch arch_32) set(libomp_gdflag_arch arch_32)
libomp_append(gdflags_local "-D IS_IA_ARCH") libomp_append(gdflags_local "-D IS_IA_ARCH")
elseif(${INTEL64}) elseif(INTEL64)
set(libomp_gdflag_arch arch_32e) set(libomp_gdflag_arch arch_32e)
libomp_append(gdflags_local "-D IS_IA_ARCH") libomp_append(gdflags_local "-D IS_IA_ARCH")
else() else()
@@ -191,7 +191,7 @@ function(libomp_get_gdflags gdflags)
libomp_append(gdflags_local "-D stub" STUBS_LIBRARY) libomp_append(gdflags_local "-D stub" STUBS_LIBRARY)
libomp_append(gdflags_local "-D HAVE_QUAD" LIBOMP_USE_QUAD_PRECISION) libomp_append(gdflags_local "-D HAVE_QUAD" LIBOMP_USE_QUAD_PRECISION)
libomp_append(gdflags_local "-D USE_DEBUGGER" LIBOMP_USE_DEBUGGER) libomp_append(gdflags_local "-D USE_DEBUGGER" LIBOMP_USE_DEBUGGER)
if(${DEBUG_BUILD} OR ${RELWITHDEBINFO_BUILD}) if(DEBUG_BUILD OR RELWITHDEBINFO_BUILD)
libomp_append(gdflags_local "-D KMP_DEBUG") libomp_append(gdflags_local "-D KMP_DEBUG")
endif() endif()
set(${gdflags} ${gdflags_local} PARENT_SCOPE) set(${gdflags} ${gdflags_local} PARENT_SCOPE)

View File

@@ -49,29 +49,29 @@ endmacro()
# appends "-D USE_FEATURE=1" if HAVE_FEATURE is true # appends "-D USE_FEATURE=1" if HAVE_FEATURE is true
# or "-D USE_FEATURE=0" if HAVE_FEATURE is false # or "-D USE_FEATURE=0" if HAVE_FEATURE is false
macro(libomp_append flags flag) macro(libomp_append flags flag)
if(NOT (${ARGC} EQUAL 2 OR ${ARGC} EQUAL 3 OR ${ARGC} EQUAL 4)) if(NOT ("${ARGC}" EQUAL 2 OR "${ARGC}" EQUAL 3 OR "${ARGC}" EQUAL 4))
libomp_error_say("libomp_append: takes 2, 3, or 4 arguments") libomp_error_say("libomp_append: takes 2, 3, or 4 arguments")
endif() endif()
if(${ARGC} EQUAL 2) if("${ARGC}" EQUAL 2)
list(APPEND ${flags} "${flag}") list(APPEND ${flags} "${flag}")
elseif(${ARGC} EQUAL 3) elseif("${ARGC}" EQUAL 3)
if(${ARGV2}) if(${ARGV2})
list(APPEND ${flags} "${flag}") list(APPEND ${flags} "${flag}")
endif() endif()
else() else()
if(${ARGV2} STREQUAL "IF_TRUE") if("${ARGV2}" STREQUAL "IF_TRUE")
if(${ARGV3}) if(${ARGV3})
list(APPEND ${flags} "${flag}") list(APPEND ${flags} "${flag}")
endif() endif()
elseif(${ARGV2} STREQUAL "IF_FALSE") elseif("${ARGV2}" STREQUAL "IF_FALSE")
if(NOT ${ARGV3}) if(NOT ${ARGV3})
list(APPEND ${flags} "${flag}") list(APPEND ${flags} "${flag}")
endif() endif()
elseif(${ARGV2} STREQUAL "IF_DEFINED") elseif("${ARGV2}" STREQUAL "IF_DEFINED")
if(DEFINED ${ARGV3}) if(DEFINED ${ARGV3})
list(APPEND ${flags} "${flag}") list(APPEND ${flags} "${flag}")
endif() endif()
elseif(${ARGV2} STREQUAL "IF_TRUE_1_0") elseif("${ARGV2}" STREQUAL "IF_TRUE_1_0")
if(${ARGV3}) if(${ARGV3})
list(APPEND ${flags} "${flag}=1") list(APPEND ${flags} "${flag}=1")
else() else()
@@ -87,39 +87,39 @@ endmacro()
# - returns (through return_arch_string) the formal architecture # - returns (through return_arch_string) the formal architecture
# string or warns user of unknown architecture # string or warns user of unknown architecture
function(libomp_get_legal_arch return_arch_string) function(libomp_get_legal_arch return_arch_string)
if(${IA32}) if(IA32)
set(${return_arch_string} "IA-32" PARENT_SCOPE) set(${return_arch_string} "IA-32" PARENT_SCOPE)
elseif(${INTEL64}) elseif(INTEL64)
set(${return_arch_string} "Intel(R) 64" PARENT_SCOPE) set(${return_arch_string} "Intel(R) 64" PARENT_SCOPE)
elseif(${MIC}) elseif(MIC)
set(${return_arch_string} "Intel(R) Many Integrated Core Architecture" PARENT_SCOPE) set(${return_arch_string} "Intel(R) Many Integrated Core Architecture" PARENT_SCOPE)
elseif(${ARM}) elseif(ARM)
set(${return_arch_string} "ARM" PARENT_SCOPE) set(${return_arch_string} "ARM" PARENT_SCOPE)
elseif(${PPC64BE}) elseif(PPC64BE)
set(${return_arch_string} "PPC64BE" PARENT_SCOPE) set(${return_arch_string} "PPC64BE" PARENT_SCOPE)
elseif(${PPC64LE}) elseif(PPC64LE)
set(${return_arch_string} "PPC64LE" PARENT_SCOPE) set(${return_arch_string} "PPC64LE" PARENT_SCOPE)
elseif(${AARCH64}) elseif(AARCH64)
set(${return_arch_string} "AARCH64" PARENT_SCOPE) set(${return_arch_string} "AARCH64" PARENT_SCOPE)
elseif(${AARCH64_32}) elseif(AARCH64_32)
set(${return_arch_string} "AARCH64_32" PARENT_SCOPE) set(${return_arch_string} "AARCH64_32" PARENT_SCOPE)
elseif(${AARCH64_A64FX}) elseif(AARCH64_A64FX)
set(${return_arch_string} "AARCH64_A64FX" PARENT_SCOPE) set(${return_arch_string} "AARCH64_A64FX" PARENT_SCOPE)
elseif(${MIPS}) elseif(MIPS)
set(${return_arch_string} "MIPS" PARENT_SCOPE) set(${return_arch_string} "MIPS" PARENT_SCOPE)
elseif(${MIPS64}) elseif(MIPS64)
set(${return_arch_string} "MIPS64" PARENT_SCOPE) set(${return_arch_string} "MIPS64" PARENT_SCOPE)
elseif(${RISCV64}) elseif(RISCV64)
set(${return_arch_string} "RISCV64" PARENT_SCOPE) set(${return_arch_string} "RISCV64" PARENT_SCOPE)
elseif(${LOONGARCH64}) elseif(LOONGARCH64)
set(${return_arch_string} "LOONGARCH64" PARENT_SCOPE) set(${return_arch_string} "LOONGARCH64" PARENT_SCOPE)
elseif(${VE}) elseif(VE)
set(${return_arch_string} "VE" PARENT_SCOPE) set(${return_arch_string} "VE" PARENT_SCOPE)
elseif(${S390X}) elseif(S390X)
set(${return_arch_string} "S390X" PARENT_SCOPE) set(${return_arch_string} "S390X" PARENT_SCOPE)
elseif(${SPARC}) elseif(SPARC)
set(${return_arch_string} "SPARC" PARENT_SCOPE) set(${return_arch_string} "SPARC" PARENT_SCOPE)
elseif(${SPARCV9}) elseif(SPARCV9)
set(${return_arch_string} "SPARCV9" PARENT_SCOPE) set(${return_arch_string} "SPARCV9" PARENT_SCOPE)
else() else()
set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE) set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE)
@@ -142,7 +142,7 @@ function(libomp_check_variable var)
set(the_value "${value}") set(the_value "${value}")
endif() endif()
endforeach() endforeach()
if(${valid_flag} EQUAL 0) if(valid_flag EQUAL 0)
libomp_error_say("libomp_check_variable(): ${var} = ${${var}} is unknown") libomp_error_say("libomp_check_variable(): ${var} = ${${var}} is unknown")
endif() endif()
endfunction() endfunction()
@@ -169,11 +169,11 @@ endfunction()
# void libomp_get_legal_type(string* return_legal_type); # void libomp_get_legal_type(string* return_legal_type);
# - set the legal type name Performance/Profiling/Stub # - set the legal type name Performance/Profiling/Stub
function(libomp_get_legal_type return_legal_type) function(libomp_get_legal_type return_legal_type)
if(${NORMAL_LIBRARY}) if(NORMAL_LIBRARY)
set(${return_legal_type} "Performance" PARENT_SCOPE) set(${return_legal_type} "Performance" PARENT_SCOPE)
elseif(${PROFILE_LIBRARY}) elseif(PROFILE_LIBRARY)
set(${return_legal_type} "Profiling" PARENT_SCOPE) set(${return_legal_type} "Profiling" PARENT_SCOPE)
elseif(${STUBS_LIBRARY}) elseif(STUBS_LIBRARY)
set(${return_legal_type} "Stub" PARENT_SCOPE) set(${return_legal_type} "Stub" PARENT_SCOPE)
endif() endif()
endfunction() endfunction()

View File

@@ -85,10 +85,10 @@ endif()
if (LLVM_ENABLE_SPHINX) if (LLVM_ENABLE_SPHINX)
include(AddSphinxTarget) include(AddSphinxTarget)
if (SPHINX_FOUND) if (SPHINX_FOUND)
if (${SPHINX_OUTPUT_HTML}) if (SPHINX_OUTPUT_HTML)
add_sphinx_target(html openmp) add_sphinx_target(html openmp)
endif() endif()
if (${SPHINX_OUTPUT_MAN}) if (SPHINX_OUTPUT_MAN)
add_sphinx_target(man openmp) add_sphinx_target(man openmp)
endif() endif()
endif() endif()

View File

@@ -21,7 +21,7 @@ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(LIBOMPD_LD_STD_FLAGS FALSE CACHE BOOL set(LIBOMPD_LD_STD_FLAGS FALSE CACHE BOOL
"Use -stdlibc++ instead of -libc++ library for C++ ") "Use -stdlibc++ instead of -libc++ library for C++ ")
if(${LIBOMPD_LD_STD_FLAGS}) if(LIBOMPD_LD_STD_FLAGS)
# Find and replace/add libstdc++ to compile flags # Find and replace/add libstdc++ to compile flags
STRING( FIND "${CMAKE_CXX_FLAGS}" "-stdlib=libc++" OUT ) STRING( FIND "${CMAKE_CXX_FLAGS}" "-stdlib=libc++" OUT )
if("${OUT}" STREQUAL "-1" ) if("${OUT}" STREQUAL "-1" )

View File

@@ -388,10 +388,10 @@ set(LIBOMP_USE_HIER_SCHED FALSE CACHE BOOL
# Setting final library name # Setting final library name
set(LIBOMP_DEFAULT_LIB_NAME libomp) set(LIBOMP_DEFAULT_LIB_NAME libomp)
if(${PROFILE_LIBRARY}) if(PROFILE_LIBRARY)
set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}prof) set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}prof)
endif() endif()
if(${STUBS_LIBRARY}) if(STUBS_LIBRARY)
set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}stubs) set(LIBOMP_DEFAULT_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME}stubs)
endif() endif()
set(LIBOMP_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME} CACHE STRING "Base OMP library name") set(LIBOMP_LIB_NAME ${LIBOMP_DEFAULT_LIB_NAME} CACHE STRING "Base OMP library name")
@@ -401,7 +401,7 @@ if (OPENMP_MSVC_NAME_SCHEME)
set(LIBOMP_LIB_NAME ${LIBOMP_LIB_NAME}${MSVC_TOOLS_VERSION}.${LIBOMP_ARCH}) set(LIBOMP_LIB_NAME ${LIBOMP_LIB_NAME}${MSVC_TOOLS_VERSION}.${LIBOMP_ARCH})
endif() endif()
if(${LIBOMP_ENABLE_SHARED}) if(LIBOMP_ENABLE_SHARED)
set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) set(LIBOMP_LIBRARY_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(LIBOMP_LIBRARY_KIND SHARED) set(LIBOMP_LIBRARY_KIND SHARED)
set(LIBOMP_INSTALL_KIND LIBRARY) set(LIBOMP_INSTALL_KIND LIBRARY)

View File

@@ -22,7 +22,7 @@ libomp_append(libomp_suffix .dia RELWITHDEBINFO_BUILD)
libomp_append(libomp_suffix .min MINSIZEREL_BUILD) libomp_append(libomp_suffix .min MINSIZEREL_BUILD)
libomp_append(libomp_suffix .s1 LIBOMP_STATS) libomp_append(libomp_suffix .s1 LIBOMP_STATS)
libomp_append(libomp_suffix .ompt LIBOMP_OMPT_SUPPORT) libomp_append(libomp_suffix .ompt LIBOMP_OMPT_SUPPORT)
if(${LIBOMP_OMPT_SUPPORT}) if(LIBOMP_OMPT_SUPPORT)
libomp_append(libomp_suffix .optional LIBOMP_OMPT_OPTIONAL) libomp_append(libomp_suffix .optional LIBOMP_OMPT_OPTIONAL)
endif() endif()
string(REPLACE ";" "" libomp_suffix "${libomp_suffix}") string(REPLACE ";" "" libomp_suffix "${libomp_suffix}")
@@ -35,12 +35,12 @@ elseif(APPLE)
else() else()
set(LIBOMP_SHORT_OS lin) set(LIBOMP_SHORT_OS lin)
endif() endif()
if(${MIC}) if(MIC)
set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_MIC_ARCH}") # e.g., lin_knf, lin_knc set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_MIC_ARCH}") # e.g., lin_knf, lin_knc
else() else()
if(${IA32}) if(IA32)
set(libomp_platform "${LIBOMP_SHORT_OS}_32") set(libomp_platform "${LIBOMP_SHORT_OS}_32")
elseif(${INTEL64}) elseif(INTEL64)
set(libomp_platform "${LIBOMP_SHORT_OS}_32e") set(libomp_platform "${LIBOMP_SHORT_OS}_32e")
else() else()
set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_ARCH}") # e.g., lin_arm, lin_ppc64 set(libomp_platform "${LIBOMP_SHORT_OS}_${LIBOMP_ARCH}") # e.g., lin_arm, lin_ppc64
@@ -59,12 +59,12 @@ add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy omp.h ${LIBOMP_EXPORTS_CMN_DIR} COMMAND ${CMAKE_COMMAND} -E copy omp.h ${LIBOMP_EXPORTS_CMN_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ompx.h ${LIBOMP_EXPORTS_CMN_DIR} COMMAND ${CMAKE_COMMAND} -E copy ompx.h ${LIBOMP_EXPORTS_CMN_DIR}
) )
if(${LIBOMP_OMPT_SUPPORT}) if(LIBOMP_OMPT_SUPPORT)
add_custom_command(TARGET omp POST_BUILD add_custom_command(TARGET omp POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy omp-tools.h ${LIBOMP_EXPORTS_CMN_DIR} COMMAND ${CMAKE_COMMAND} -E copy omp-tools.h ${LIBOMP_EXPORTS_CMN_DIR}
) )
endif() endif()
if(${LIBOMP_FORTRAN_MODULES}) if(LIBOMP_FORTRAN_MODULES)
# We cannot attach a POST_BUILD command to libomp-mod, so instead attach it # We cannot attach a POST_BUILD command to libomp-mod, so instead attach it
# to omp and ensure that libomp-mod is built before by adding a dependency # to omp and ensure that libomp-mod is built before by adding a dependency
add_custom_command(TARGET omp POST_BUILD add_custom_command(TARGET omp POST_BUILD

View File

@@ -57,7 +57,7 @@ if(WIN32)
# test-touch compilation flags # test-touch compilation flags
libomp_append(libomp_test_touch_cflags /nologo) libomp_append(libomp_test_touch_cflags /nologo)
libomp_append(libomp_test_touch_libs ${LIBOMPIMP_OUTPUT_DIRECTORY}/${LIBOMP_IMP_LIB_FILE}) libomp_append(libomp_test_touch_libs ${LIBOMPIMP_OUTPUT_DIRECTORY}/${LIBOMP_IMP_LIB_FILE})
if(${IA32}) if(IA32)
libomp_append(libomp_test_touch_ldflags /safeseh) libomp_append(libomp_test_touch_ldflags /safeseh)
endif() endif()
else() # (Unix based systems, Intel(R) MIC Architecture, and Mac) else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
@@ -65,14 +65,14 @@ else() # (Unix based systems, Intel(R) MIC Architecture, and Mac)
set(libomp_test_touch_targets test-touch-rt/.success) set(libomp_test_touch_targets test-touch-rt/.success)
endif() endif()
# pick test-touch compiler # pick test-touch compiler
if(${LIBOMP_USE_STDCPPLIB}) if(LIBOMP_USE_STDCPPLIB)
set(libomp_test_touch_compiler ${CMAKE_CXX_COMPILER}) set(libomp_test_touch_compiler ${CMAKE_CXX_COMPILER})
else() else()
set(libomp_test_touch_compiler ${CMAKE_C_COMPILER}) set(libomp_test_touch_compiler ${CMAKE_C_COMPILER})
endif() endif()
# test-touch compilation flags # test-touch compilation flags
libomp_append(libomp_test_touch_libs "${CMAKE_THREAD_LIBS_INIT}") libomp_append(libomp_test_touch_libs "${CMAKE_THREAD_LIBS_INIT}")
if(${IA32}) if(IA32)
libomp_append(libomp_test_touch_cflags -m32 LIBOMP_HAVE_M32_FLAG) libomp_append(libomp_test_touch_cflags -m32 LIBOMP_HAVE_M32_FLAG)
endif() endif()
libomp_append(libomp_test_touch_libs ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE}) libomp_append(libomp_test_touch_libs ${LIBOMP_OUTPUT_DIRECTORY}/${LIBOMP_LIB_FILE})
@@ -89,14 +89,14 @@ macro(libomp_test_touch_recipe test_touch_dir)
set(libomp_test_touch_dependencies ${LIBOMP_SRC_DIR}/test-touch.c omp) set(libomp_test_touch_dependencies ${LIBOMP_SRC_DIR}/test-touch.c omp)
set(libomp_test_touch_exe ${test_touch_dir}/test-touch${CMAKE_EXECUTABLE_SUFFIX}) set(libomp_test_touch_exe ${test_touch_dir}/test-touch${CMAKE_EXECUTABLE_SUFFIX})
if(WIN32) if(WIN32)
if(${RELEASE_BUILD} OR ${RELWITHDEBINFO_BUILD}) if(RELEASE_BUILD OR RELWITHDEBINFO_BUILD)
if(${test_touch_dir} MATCHES "test-touch-mt") if(test_touch_dir MATCHES "test-touch-mt")
libomp_append(libomp_test_touch_cflags /MT) libomp_append(libomp_test_touch_cflags /MT)
else() else()
libomp_append(libomp_test_touch_cflags /MD) libomp_append(libomp_test_touch_cflags /MD)
endif() endif()
else() else()
if(${test_touch_dir} MATCHES "test-touch-mt") if(test_touch_dir MATCHES "test-touch-mt")
libomp_append(libomp_test_touch_cflags /MTd) libomp_append(libomp_test_touch_cflags /MTd)
else() else()
libomp_append(libomp_test_touch_cflags /MDd) libomp_append(libomp_test_touch_cflags /MDd)
@@ -179,7 +179,7 @@ elseif(WIN32)
libomp_append(libomp_expected_library_deps vcruntime140.dll) libomp_append(libomp_expected_library_deps vcruntime140.dll)
libomp_append(libomp_expected_library_deps psapi.dll) libomp_append(libomp_expected_library_deps psapi.dll)
else() else()
if(${MIC}) if(MIC)
set(libomp_expected_library_deps libc.so.6 libpthread.so.0 libdl.so.2) set(libomp_expected_library_deps libc.so.6 libpthread.so.0 libdl.so.2)
if("${LIBOMP_MIC_ARCH}" STREQUAL "knf") if("${LIBOMP_MIC_ARCH}" STREQUAL "knf")
libomp_append(libomp_expected_library_deps ld-linux-l1om.so.2) libomp_append(libomp_expected_library_deps ld-linux-l1om.so.2)
@@ -189,32 +189,32 @@ else()
endif() endif()
else() else()
set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1) set(libomp_expected_library_deps libdl.so.2 libgcc_s.so.1)
if(${IA32}) if(IA32)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps ld-linux.so.2) libomp_append(libomp_expected_library_deps ld-linux.so.2)
libomp_append(libomp_expected_library_deps librt.so.1) libomp_append(libomp_expected_library_deps librt.so.1)
elseif(${INTEL64}) elseif(INTEL64)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2) libomp_append(libomp_expected_library_deps ld-linux-x86-64.so.2)
libomp_append(libomp_expected_library_deps librt.so.1) libomp_append(libomp_expected_library_deps librt.so.1)
elseif(${ARM}) elseif(ARM)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps libffi.so.6) libomp_append(libomp_expected_library_deps libffi.so.6)
libomp_append(libomp_expected_library_deps libffi.so.5) libomp_append(libomp_expected_library_deps libffi.so.5)
libomp_append(libomp_expected_library_deps ld-linux-armhf.so.3) libomp_append(libomp_expected_library_deps ld-linux-armhf.so.3)
elseif(${PPC64}) elseif(PPC64)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps ld64.so.1) libomp_append(libomp_expected_library_deps ld64.so.1)
elseif(${MIPS} OR ${MIPS64}) elseif(MIPS OR MIPS64)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps ld.so.1) libomp_append(libomp_expected_library_deps ld.so.1)
elseif(${RISCV64}) elseif(RISCV64)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps ld.so.1) libomp_append(libomp_expected_library_deps ld.so.1)
elseif(${LOONGARCH64}) elseif(LOONGARCH64)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps ld.so.1) libomp_append(libomp_expected_library_deps ld.so.1)
elseif(${S390X}) elseif(S390X)
libomp_append(libomp_expected_library_deps libc.so.6) libomp_append(libomp_expected_library_deps libc.so.6)
libomp_append(libomp_expected_library_deps ld.so.1) libomp_append(libomp_expected_library_deps ld.so.1)
endif() endif()

View File

@@ -246,14 +246,14 @@ else()
endif() endif()
# Check if adaptive locks are available # Check if adaptive locks are available
if((${IA32} OR ${INTEL64}) AND NOT MSVC) if((IA32 OR INTEL64) AND NOT MSVC)
set(LIBOMP_HAVE_ADAPTIVE_LOCKS TRUE) set(LIBOMP_HAVE_ADAPTIVE_LOCKS TRUE)
else() else()
set(LIBOMP_HAVE_ADAPTIVE_LOCKS FALSE) set(LIBOMP_HAVE_ADAPTIVE_LOCKS FALSE)
endif() endif()
# Check if stats-gathering is available # Check if stats-gathering is available
if(${LIBOMP_STATS}) if(LIBOMP_STATS)
check_c_source_compiles( check_c_source_compiles(
"__thread int x; "__thread int x;
int main(int argc, char** argv) int main(int argc, char** argv)
@@ -264,7 +264,7 @@ if(${LIBOMP_STATS})
{ unsigned long long t = __builtin_readcyclecounter(); return 0; }" { unsigned long long t = __builtin_readcyclecounter(); return 0; }"
LIBOMP_HAVE___BUILTIN_READCYCLECOUNTER) LIBOMP_HAVE___BUILTIN_READCYCLECOUNTER)
if(NOT LIBOMP_HAVE___BUILTIN_READCYCLECOUNTER) if(NOT LIBOMP_HAVE___BUILTIN_READCYCLECOUNTER)
if(${IA32} OR ${INTEL64} OR ${MIC}) if(IA32 OR INTEL64 OR MIC)
check_include_file(x86intrin.h LIBOMP_HAVE_X86INTRIN_H) check_include_file(x86intrin.h LIBOMP_HAVE_X86INTRIN_H)
libomp_append(CMAKE_REQUIRED_DEFINITIONS -DLIBOMP_HAVE_X86INTRIN_H LIBOMP_HAVE_X86INTRIN_H) libomp_append(CMAKE_REQUIRED_DEFINITIONS -DLIBOMP_HAVE_X86INTRIN_H LIBOMP_HAVE_X86INTRIN_H)
check_c_source_compiles( check_c_source_compiles(
@@ -327,7 +327,7 @@ endif()
set(LIBOMP_HAVE_OMPT_SUPPORT ${LIBOMP_HAVE_OMPT_SUPPORT} PARENT_SCOPE) set(LIBOMP_HAVE_OMPT_SUPPORT ${LIBOMP_HAVE_OMPT_SUPPORT} PARENT_SCOPE)
# Check if HWLOC support is available # Check if HWLOC support is available
if(${LIBOMP_USE_HWLOC}) if(LIBOMP_USE_HWLOC)
find_path(LIBOMP_HWLOC_INCLUDE_DIR NAMES hwloc.h HINTS ${LIBOMP_HWLOC_INSTALL_DIR} PATH_SUFFIXES include) find_path(LIBOMP_HWLOC_INCLUDE_DIR NAMES hwloc.h HINTS ${LIBOMP_HWLOC_INSTALL_DIR} PATH_SUFFIXES include)
set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INCLUDE_DIR}) set(CMAKE_REQUIRED_INCLUDES ${LIBOMP_HWLOC_INCLUDE_DIR})
check_include_file(hwloc.h LIBOMP_HAVE_HWLOC_H) check_include_file(hwloc.h LIBOMP_HAVE_HWLOC_H)
@@ -349,7 +349,7 @@ if(${LIBOMP_USE_HWLOC})
endif() endif()
# Check if ThreadSanitizer support is available # Check if ThreadSanitizer support is available
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND ${INTEL64}) if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" AND INTEL64)
set(LIBOMP_HAVE_TSAN_SUPPORT TRUE) set(LIBOMP_HAVE_TSAN_SUPPORT TRUE)
else() else()
set(LIBOMP_HAVE_TSAN_SUPPORT FALSE) set(LIBOMP_HAVE_TSAN_SUPPORT FALSE)

View File

@@ -22,7 +22,7 @@ endif()
configure_file(${LIBOMP_INC_DIR}/omp.h.var ${LIBOMP_HEADERS_INTDIR}/omp.h @ONLY) configure_file(${LIBOMP_INC_DIR}/omp.h.var ${LIBOMP_HEADERS_INTDIR}/omp.h @ONLY)
configure_file(${LIBOMP_INC_DIR}/ompx.h.var ${LIBOMP_HEADERS_INTDIR}/ompx.h @ONLY) configure_file(${LIBOMP_INC_DIR}/ompx.h.var ${LIBOMP_HEADERS_INTDIR}/ompx.h @ONLY)
configure_file(kmp_config.h.cmake kmp_config.h @ONLY) configure_file(kmp_config.h.cmake kmp_config.h @ONLY)
if(${LIBOMP_OMPT_SUPPORT}) if(LIBOMP_OMPT_SUPPORT)
configure_file(${LIBOMP_INC_DIR}/omp-tools.h.var ${LIBOMP_HEADERS_INTDIR}/omp-tools.h @ONLY) configure_file(${LIBOMP_INC_DIR}/omp-tools.h.var ${LIBOMP_HEADERS_INTDIR}/omp-tools.h @ONLY)
endif() endif()
@@ -109,9 +109,9 @@ else()
# Windows specific files # Windows specific files
libomp_append(LIBOMP_CXXFILES z_Windows_NT_util.cpp) libomp_append(LIBOMP_CXXFILES z_Windows_NT_util.cpp)
libomp_append(LIBOMP_CXXFILES z_Windows_NT-586_util.cpp) libomp_append(LIBOMP_CXXFILES z_Windows_NT-586_util.cpp)
if(${LIBOMP_ARCH} STREQUAL "i386" OR ${LIBOMP_ARCH} STREQUAL "x86_64") if(LIBOMP_ARCH STREQUAL "i386" OR LIBOMP_ARCH STREQUAL "x86_64")
libomp_append(LIBOMP_ASMFILES z_Windows_NT-586_asm.asm) # Windows assembly file libomp_append(LIBOMP_ASMFILES z_Windows_NT-586_asm.asm) # Windows assembly file
elseif((${LIBOMP_ARCH} STREQUAL "aarch64" OR ${LIBOMP_ARCH} STREQUAL "arm") AND (NOT MSVC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")) elseif((LIBOMP_ARCH STREQUAL "aarch64" OR LIBOMP_ARCH STREQUAL "arm") AND (NOT MSVC OR CMAKE_C_COMPILER_ID STREQUAL "Clang"))
# z_Linux_asm.S works for AArch64 and ARM Windows too. # z_Linux_asm.S works for AArch64 and ARM Windows too.
libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S) libomp_append(LIBOMP_GNUASMFILES z_Linux_asm.S)
else() else()
@@ -188,7 +188,7 @@ else()
# libomp must be a C++ library such that it can link libLLVMSupport # libomp must be a C++ library such that it can link libLLVMSupport
set(LIBOMP_LINKER_LANGUAGE CXX) set(LIBOMP_LINKER_LANGUAGE CXX)
endif() endif()
if(${LIBOMP_USE_HWLOC}) if(LIBOMP_USE_HWLOC)
target_include_directories(omp target_include_directories(omp
PUBLIC PUBLIC
"$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>" "$<BUILD_INTERFACE:${LIBOMP_HWLOC_INCLUDE_DIR}>"
@@ -374,7 +374,7 @@ if(WIN32)
endif() endif()
# Move files to exports/ directory if requested # Move files to exports/ directory if requested
if(${LIBOMP_COPY_EXPORTS}) if(LIBOMP_COPY_EXPORTS)
include(LibompExports) include(LibompExports)
endif() endif()
@@ -382,7 +382,7 @@ endif()
include(LibompMicroTests) include(LibompMicroTests)
add_custom_target(libomp-micro-tests) add_custom_target(libomp-micro-tests)
set_target_properties(libomp-micro-tests PROPERTIES FOLDER "OpenMP/Tests") set_target_properties(libomp-micro-tests PROPERTIES FOLDER "OpenMP/Tests")
if(NOT ${MIC} AND NOT CMAKE_CROSSCOMPILING) if(NOT MIC AND NOT CMAKE_CROSSCOMPILING)
add_dependencies(libomp-micro-tests libomp-test-touch) add_dependencies(libomp-micro-tests libomp-test-touch)
endif() endif()
if(NOT WIN32 AND NOT APPLE) if(NOT WIN32 AND NOT APPLE)
@@ -417,7 +417,7 @@ else()
install(TARGETS omp ${export_to_llvmexports} ${LIBOMP_INSTALL_KIND} DESTINATION "${OPENMP_INSTALL_LIBDIR}") install(TARGETS omp ${export_to_llvmexports} ${LIBOMP_INSTALL_KIND} DESTINATION "${OPENMP_INSTALL_LIBDIR}")
if(${LIBOMP_INSTALL_ALIASES}) if(LIBOMP_INSTALL_ALIASES)
# Create aliases (symlinks) of the library for backwards compatibility # Create aliases (symlinks) of the library for backwards compatibility
extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}") extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
if(AIX) if(AIX)
@@ -445,7 +445,7 @@ install(
${LIBOMP_HEADERS_INTDIR}/ompx.h ${LIBOMP_HEADERS_INTDIR}/ompx.h
DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
) )
if(${LIBOMP_OMPT_SUPPORT}) if(LIBOMP_OMPT_SUPPORT)
install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}) install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH})
# install under legacy name ompt.h # install under legacy name ompt.h
install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h) install(FILES ${LIBOMP_HEADERS_INTDIR}/omp-tools.h DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH} RENAME ompt.h)

View File

@@ -15,7 +15,7 @@ option(LIBOMPTEST_INSTALL_COMPONENTS
"Install ompTest library, headers and package files." OFF) "Install ompTest library, headers and package files." OFF)
# Exit early if OMPT support or LLVM-tests were disabled by the user. # Exit early if OMPT support or LLVM-tests were disabled by the user.
if((NOT ${LIBOMP_OMPT_SUPPORT}) OR (NOT ${LLVM_INCLUDE_TESTS})) if((NOT LIBOMP_OMPT_SUPPORT) OR (NOT LLVM_INCLUDE_TESTS))
return() return()
endif() endif()