1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

Build: Fix bugs in the CMake files.

Seems that the phrase "add more quotes" from sh/bash scripting
applies to CMake as well. E.g. passing an unquoted list ${FOO}
to a function that expects one argument results in only the
first element of the list being passed as an argument and
the rest get ignored. Adding quotes helps ("${FOO}").

list(INSERT ...) is weird. Inserting an empty string to an empty
variable results in empty list, but inserting it to a non-empty
variable does insert an empty element to the list.

Since INSERT requires at least one element,
"${CMAKE_THREAD_LIBS_INIT}" needs to be quoted in CMakeLists.txt.
It might result in an empty element in the list. It seems to not
matter as empty elements consistently get ignored in that variable.
In fact, calling cmake_check_push_state() and cmake_check_pop_state()
will strip the empty elements from CMAKE_REQUIRED_LIBRARIES!

In addition to quoting fixes, this fixes checks for the cache
variables in tuklib_cpucores.cmake and tuklib_physmem.cmake.

Thanks to Martin Matuška for testing and reporting the problems.
These fixes aren't tested yet but hopefully they soon will be.
This commit is contained in:
Lasse Collin 2020-02-25 20:42:31 +02:00
parent 7e3493d40e
commit 474320e990
7 changed files with 85 additions and 78 deletions

View file

@ -65,10 +65,10 @@ string(REGEX REPLACE
#define LZMA_VERSION_MINOR ([0-9]+)\n\ #define LZMA_VERSION_MINOR ([0-9]+)\n\
#define LZMA_VERSION_PATCH ([0-9]+)\n\ #define LZMA_VERSION_PATCH ([0-9]+)\n\
.*$" .*$"
"\\1.\\2.\\3" XZ_VERSION ${XZ_VERSION}) "\\1.\\2.\\3" XZ_VERSION "${XZ_VERSION}")
# Among other things, this gives us variables xz_VERSION and xz_VERSION_MAJOR. # Among other things, this gives us variables xz_VERSION and xz_VERSION_MAJOR.
project(xz VERSION ${XZ_VERSION} LANGUAGES C) project(xz VERSION "${XZ_VERSION}" LANGUAGES C)
# Definitions common to all targets: # Definitions common to all targets:
add_compile_definitions( add_compile_definitions(
@ -152,7 +152,7 @@ if(NOT WIN32 AND NOT DEFINED CACHE{HAVE_CLOCK_GETTIME})
# when clock_gettime is available. # when clock_gettime is available.
add_compile_definitions( add_compile_definitions(
HAVE_CLOCK_GETTIME HAVE_CLOCK_GETTIME
HAVE_DECL_CLOCK_MONOTONIC=$<BOOL:${HAVE_DECL_CLOCK_MONOTONIC}> HAVE_DECL_CLOCK_MONOTONIC=$<BOOL:"${HAVE_DECL_CLOCK_MONOTONIC}">
) )
endif() endif()
endif() endif()
@ -167,7 +167,7 @@ else()
# Check if pthread_condattr_setclock() exists to use CLOCK_MONOTONIC. # Check if pthread_condattr_setclock() exists to use CLOCK_MONOTONIC.
if(HAVE_DECL_CLOCK_MONOTONIC) if(HAVE_DECL_CLOCK_MONOTONIC)
list(INSERT CMAKE_REQUIRED_LIBRARIES 0 ${CMAKE_THREAD_LIBS_INIT}) list(INSERT CMAKE_REQUIRED_LIBRARIES 0 "${CMAKE_THREAD_LIBS_INIT}")
check_symbol_exists(pthread_condattr_setclock pthread.h check_symbol_exists(pthread_condattr_setclock pthread.h
HAVE_PTHREAD_CONDATTR_SETCLOCK) HAVE_PTHREAD_CONDATTR_SETCLOCK)
tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK) tuklib_add_definition_if(ALL HAVE_PTHREAD_CONDATTR_SETCLOCK)
@ -395,11 +395,11 @@ if(WIN32)
elseif(CMAKE_SYSTEM_NAME MATCHES "^Linux$|^FreeBSD$") elseif(CMAKE_SYSTEM_NAME MATCHES "^Linux$|^FreeBSD$")
# Symbol versioning for shared liblzma. This doesn't affect static builds. # Symbol versioning for shared liblzma. This doesn't affect static builds.
target_link_options(liblzma PRIVATE target_link_options(liblzma PRIVATE
-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma.map "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma.map"
) )
set_target_properties(liblzma PROPERTIES set_target_properties(liblzma PROPERTIES
LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma.map LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/liblzma/liblzma.map"
LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/common_w32res.rc"
) )
endif() endif()
@ -407,8 +407,8 @@ set_target_properties(liblzma PROPERTIES
# At least for now the package versioning matches the rules used for # At least for now the package versioning matches the rules used for
# shared library versioning (excluding development releases) so it is # shared library versioning (excluding development releases) so it is
# fine to use the package version here. # fine to use the package version here.
SOVERSION ${xz_VERSION_MAJOR} SOVERSION "${xz_VERSION_MAJOR}"
VERSION ${xz_VERSION} VERSION "${xz_VERSION}"
# It's liblzma.so or liblzma.dll, not libliblzma.so or lzma.dll. # It's liblzma.so or liblzma.dll, not libliblzma.so or lzma.dll.
# Avoid the name lzma.dll because it would conflict with LZMA SDK. # Avoid the name lzma.dll because it would conflict with LZMA SDK.
@ -421,12 +421,12 @@ set_target_properties(liblzma PROPERTIES
# for development releases where each release may have incompatible changes. # for development releases where each release may have incompatible changes.
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
write_basic_package_version_file( write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfigVersion.cmake "${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfigVersion.cmake"
VERSION ${liblzma_VERSION} VERSION "${liblzma_VERSION}"
COMPATIBILITY SameMajorVersion) COMPATIBILITY SameMajorVersion)
# Create liblzmaConfig.cmake. # Create liblzmaConfig.cmake.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfig.cmake file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfig.cmake"
"include(CMakeFindDependencyMacro) "include(CMakeFindDependencyMacro)
set(THREADS_PREFER_PTHREAD_FLAG TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_dependency(Threads) find_dependency(Threads)
@ -439,36 +439,36 @@ include(GNUInstallDirs)
# Install the library binary. The INCLUDES specifies the include path that # Install the library binary. The INCLUDES specifies the include path that
# is exported for other projects to use but it doesn't install any files. # is exported for other projects to use but it doesn't install any files.
install(TARGETS liblzma EXPORT liblzmaTargets install(TARGETS liblzma EXPORT liblzmaTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT liblzma_Runtime COMPONENT liblzma_Runtime
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT liblzma_Runtime COMPONENT liblzma_Runtime
NAMELINK_COMPONENT liblzma_Development NAMELINK_COMPONENT liblzma_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
COMPONENT liblzma_Development COMPONENT liblzma_Development
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install the liblzma API headers. These use a subdirectory so # Install the liblzma API headers. These use a subdirectory so
# this has to be done as a separate step. # this has to be done as a separate step.
install(DIRECTORY src/liblzma/api/ install(DIRECTORY src/liblzma/api/
COMPONENT liblzma_Development COMPONENT liblzma_Development
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.h") FILES_MATCHING PATTERN "*.h")
# Install the CMake files that other packages can use to find liblzma. # Install the CMake files that other packages can use to find liblzma.
set(liblzma_INSTALL_CMAKEDIR set(liblzma_INSTALL_CMAKEDIR
${CMAKE_INSTALL_LIBDIR}/cmake/liblzma "${CMAKE_INSTALL_LIBDIR}/cmake/liblzma"
CACHE STRING "Path to liblzma's .cmake files") CACHE STRING "Path to liblzma's .cmake files")
install(EXPORT liblzmaTargets install(EXPORT liblzmaTargets
NAMESPACE liblzma:: NAMESPACE liblzma::
FILE liblzmaTargets.cmake FILE liblzmaTargets.cmake
DESTINATION ${liblzma_INSTALL_CMAKEDIR} DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
COMPONENT liblzma_Development) COMPONENT liblzma_Development)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfig.cmake install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfig.cmake"
${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfigVersion.cmake "${CMAKE_CURRENT_BINARY_DIR}/liblzmaConfigVersion.cmake"
DESTINATION ${liblzma_INSTALL_CMAKEDIR} DESTINATION "${liblzma_INSTALL_CMAKEDIR}"
COMPONENT liblzma_Development) COMPONENT liblzma_Development)
@ -507,12 +507,12 @@ if(HAVE_GETOPT_LONG)
tuklib_progname(xzdec) tuklib_progname(xzdec)
install(TARGETS xzdec install(TARGETS xzdec
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT xzdec) COMPONENT xzdec)
if(UNIX) if(UNIX)
install(FILES src/xzdec/xzdec.1 install(FILES src/xzdec/xzdec.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
COMPONENT xzdec) COMPONENT xzdec)
endif() endif()
endif() endif()
@ -634,10 +634,10 @@ if(NOT MSVC AND HAVE_GETOPT_LONG)
endif() endif()
install(TARGETS xz install(TARGETS xz
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
COMPONENT xz) COMPONENT xz)
install(FILES src/xz/xz.1 install(FILES src/xz/xz.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
COMPONENT xz) COMPONENT xz)
endif() endif()

View file

@ -8,16 +8,18 @@
# #
function(tuklib_add_definitions TARGET_OR_ALL DEFINITIONS) function(tuklib_add_definitions TARGET_OR_ALL DEFINITIONS)
# DEFINITIONS may be an empty string/list but it's fine here. There is
# no need to quote ${DEFINITIONS} as empty arguments are fine here.
if(TARGET_OR_ALL STREQUAL "ALL") if(TARGET_OR_ALL STREQUAL "ALL")
add_compile_definitions(${DEFINITIONS}) add_compile_definitions(${DEFINITIONS})
else() else()
target_compile_definitions(${TARGET_OR_ALL} PRIVATE ${DEFINITIONS}) target_compile_definitions("${TARGET_OR_ALL}" PRIVATE ${DEFINITIONS})
endif() endif()
endfunction() endfunction()
function(tuklib_add_definition_if TARGET_OR_ALL VAR) function(tuklib_add_definition_if TARGET_OR_ALL VAR)
if(${VAR}) if(${VAR})
tuklib_add_definitions(${TARGET_OR_ALL} ${VAR}) tuklib_add_definitions("${TARGET_OR_ALL}" "${VAR}")
endif() endif()
endfunction() endfunction()
@ -28,7 +30,7 @@ macro(tuklib_use_system_extensions TARGET_OR_ALL)
# FIXME? The Solaris-specific __EXTENSIONS__ should be conditional # FIXME? The Solaris-specific __EXTENSIONS__ should be conditional
# even on Solaris. See gnulib: git log m4/extensions.m4. # even on Solaris. See gnulib: git log m4/extensions.m4.
# FIXME? gnulib and autoconf.git has lots of new stuff. # FIXME? gnulib and autoconf.git has lots of new stuff.
tuklib_add_definitions(${TARGET_OR_ALL} tuklib_add_definitions("${TARGET_OR_ALL}"
_GNU_SOURCE _GNU_SOURCE
__EXTENSIONS__ __EXTENSIONS__
_POSIX_PTHREAD_SEMANTICS _POSIX_PTHREAD_SEMANTICS

View file

@ -7,15 +7,11 @@
# You can do whatever you want with this file. # You can do whatever you want with this file.
# #
include(${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake) include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
include(CheckCSourceCompiles) include(CheckCSourceCompiles)
include(CheckIncludeFile) include(CheckIncludeFile)
function(tuklib_cpucores_internal_check) function(tuklib_cpucores_internal_check)
if(CACHE{TUKLIB_CPUCORES_DEFINITIONS})
return()
endif()
if(WIN32 OR CYGWIN) if(WIN32 OR CYGWIN)
# Nothing to do, the tuklib_cpucores.c handles it. # Nothing to do, the tuklib_cpucores.c handles it.
set(TUKLIB_CPUCORES_DEFINITIONS "" CACHE INTERNAL "") set(TUKLIB_CPUCORES_DEFINITIONS "" CACHE INTERNAL "")
@ -158,16 +154,22 @@ function(tuklib_cpucores_internal_check)
endfunction() endfunction()
function(tuklib_cpucores TARGET_OR_ALL) function(tuklib_cpucores TARGET_OR_ALL)
message(STATUS "Checking how to detect the number of available CPU cores") if(NOT DEFINED CACHE{TUKLIB_CPUCORES_FOUND})
message(STATUS
"Checking how to detect the number of available CPU cores")
tuklib_cpucores_internal_check() tuklib_cpucores_internal_check()
if(NOT DEFINED CACHE{TUKLIB_CPUCORES_DEFINITIONS}) if(DEFINED CACHE{TUKLIB_CPUCORES_DEFINITIONS})
set(TUKLIB_CPUCORES_FOUND 0 PARENT_SCOPE) set(TUKLIB_CPUCORES_FOUND 1 CACHE INTERNAL "")
else()
set(TUKLIB_CPUCORES_FOUND 0 CACHE INTERNAL "")
message(WARNING message(WARNING
"No method to detect the number of CPU cores was found") "No method to detect the number of CPU cores was found")
else() endif()
set(TUKLIB_CPUCORES_FOUND 1 PARENT_SCOPE) endif()
tuklib_add_definitions(${TARGET_OR_ALL} ${TUKLIB_CPUCORES_DEFINITIONS})
if(TUKLIB_CPUCORES_FOUND)
tuklib_add_definitions("${TARGET_OR_ALL}"
"${TUKLIB_CPUCORES_DEFINITIONS}")
endif() endif()
endfunction() endfunction()

View file

@ -7,7 +7,7 @@
# You can do whatever you want with this file. # You can do whatever you want with this file.
# #
include(${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake) include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
include(TestBigEndian) include(TestBigEndian)
include(CheckCSourceCompiles) include(CheckCSourceCompiles)
include(CheckIncludeFile) include(CheckIncludeFile)
@ -22,7 +22,7 @@ function(tuklib_integer TARGET_OR_ALL)
if(NOT DEFINED WORDS_BIGENDIAN) if(NOT DEFINED WORDS_BIGENDIAN)
message(FATAL_ERROR "Cannot determine endianness") message(FATAL_ERROR "Cannot determine endianness")
endif() endif()
tuklib_add_definition_if(${TARGET_OR_ALL} WORDS_BIGENDIAN) tuklib_add_definition_if("${TARGET_OR_ALL}" WORDS_BIGENDIAN)
# Look for a byteswapping method. # Look for a byteswapping method.
check_c_source_compiles(" check_c_source_compiles("
@ -36,24 +36,25 @@ function(tuklib_integer TARGET_OR_ALL)
" "
HAVE___BUILTIN_BSWAPXX) HAVE___BUILTIN_BSWAPXX)
if(HAVE___BUILTIN_BSWAPXX) if(HAVE___BUILTIN_BSWAPXX)
tuklib_add_definitions(${TARGET_OR_ALL} HAVE___BUILTIN_BSWAPXX) tuklib_add_definitions("${TARGET_OR_ALL}" HAVE___BUILTIN_BSWAPXX)
else() else()
check_include_file(byteswap.h HAVE_BYTESWAP_H) check_include_file(byteswap.h HAVE_BYTESWAP_H)
if(HAVE_BYTESWAP_H) if(HAVE_BYTESWAP_H)
tuklib_add_definitions(${TARGET_OR_ALL} HAVE_BYTESWAP_H) tuklib_add_definitions("${TARGET_OR_ALL}" HAVE_BYTESWAP_H)
check_symbol_exists(bswap_16 byteswap.h HAVE_BSWAP_16) check_symbol_exists(bswap_16 byteswap.h HAVE_BSWAP_16)
tuklib_add_definition_if(${TARGET_OR_ALL} HAVE_BSWAP_16) tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_BSWAP_16)
check_symbol_exists(bswap_32 byteswap.h HAVE_BSWAP_32) check_symbol_exists(bswap_32 byteswap.h HAVE_BSWAP_32)
tuklib_add_definition_if(${TARGET_OR_ALL} HAVE_BSWAP_32) tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_BSWAP_32)
check_symbol_exists(bswap_64 byteswap.h HAVE_BSWAP_64) check_symbol_exists(bswap_64 byteswap.h HAVE_BSWAP_64)
tuklib_add_definition_if(${TARGET_OR_ALL} HAVE_BSWAP_64) tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_BSWAP_64)
else() else()
check_include_file(sys/endian.h HAVE_SYS_ENDIAN_H) check_include_file(sys/endian.h HAVE_SYS_ENDIAN_H)
if(HAVE_SYS_ENDIAN_H) if(HAVE_SYS_ENDIAN_H)
tuklib_add_definitions(${TARGET_OR_ALL} HAVE_SYS_ENDIAN_H) tuklib_add_definitions("${TARGET_OR_ALL}" HAVE_SYS_ENDIAN_H)
else() else()
check_include_file(sys/byteorder.h HAVE_SYS_BYTEORDER_H) check_include_file(sys/byteorder.h HAVE_SYS_BYTEORDER_H)
tuklib_add_definition_if(${TARGET_OR_ALL} HAVE_SYS_BYTEORDER_H) tuklib_add_definition_if("${TARGET_OR_ALL}"
HAVE_SYS_BYTEORDER_H)
endif() endif()
endif() endif()
endif() endif()
@ -72,16 +73,17 @@ function(tuklib_integer TARGET_OR_ALL)
# on ARM and always assumes that unaligned is fast on ARM. # on ARM and always assumes that unaligned is fast on ARM.
set(FAST_UNALIGNED_GUESS OFF) set(FAST_UNALIGNED_GUESS OFF)
if(CMAKE_SYSTEM_PROCESSOR MATCHES if(CMAKE_SYSTEM_PROCESSOR MATCHES
[Xx3456]86|^[Xx]64|^[Aa][Mm][Dd]64|^[Aa][Rr][Mm]|^aarch|^powerpc|^ppc) "[Xx3456]86|^[Xx]64|^[Aa][Mm][Dd]64|^[Aa][Rr][Mm]|^aarch|^powerpc|^ppc")
if(NOT WORDS_BIGENDIAN OR if(NOT WORDS_BIGENDIAN OR
NOT CMAKE_SYSTEM_PROCESSOR MATCHES ^powerpc|^ppc) NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc|^ppc")
set(FAST_UNALIGNED_GUESS ON) set(FAST_UNALIGNED_GUESS ON)
endif() endif()
endif() endif()
option(TUKLIB_FAST_UNALIGNED_ACCESS option(TUKLIB_FAST_UNALIGNED_ACCESS
"Enable if the system supports *fast* unaligned memory access with 16-bit and 32-bit integers." "Enable if the system supports *fast* unaligned memory access \
${FAST_UNALIGNED_GUESS}) with 16-bit and 32-bit integers."
tuklib_add_definition_if(${TARGET_OR_ALL} TUKLIB_FAST_UNALIGNED_ACCESS) "${FAST_UNALIGNED_GUESS}")
tuklib_add_definition_if("${TARGET_OR_ALL}" TUKLIB_FAST_UNALIGNED_ACCESS)
# Unsafe type punning: # Unsafe type punning:
option(TUKLIB_USE_UNSAFE_TYPE_PUNNING option(TUKLIB_USE_UNSAFE_TYPE_PUNNING
@ -90,11 +92,11 @@ may result in broken code. However, this might improve performance \
in some cases, especially with old compilers \ in some cases, especially with old compilers \
(e.g. GCC 3 and early 4.x on x86, GCC < 6 on ARMv6 and ARMv7)." (e.g. GCC 3 and early 4.x on x86, GCC < 6 on ARMv6 and ARMv7)."
OFF) OFF)
tuklib_add_definition_if(${TARGET_OR_ALL} TUKLIB_USE_UNSAFE_TYPE_PUNNING) tuklib_add_definition_if("${TARGET_OR_ALL}" TUKLIB_USE_UNSAFE_TYPE_PUNNING)
# Check for GCC/Clang __builtin_assume_aligned(). # Check for GCC/Clang __builtin_assume_aligned().
check_c_source_compiles( check_c_source_compiles(
"int main(void) { __builtin_assume_aligned(\"\", 1); return 0; }" "int main(void) { __builtin_assume_aligned(\"\", 1); return 0; }"
HAVE___BUILTIN_ASSUME_ALIGNED) HAVE___BUILTIN_ASSUME_ALIGNED)
tuklib_add_definition_if(${TARGET_OR_ALL} HAVE___BUILTIN_ASSUME_ALIGNED) tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE___BUILTIN_ASSUME_ALIGNED)
endfunction() endfunction()

View file

@ -7,14 +7,14 @@
# You can do whatever you want with this file. # You can do whatever you want with this file.
# #
include(${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake) include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
include(CheckSymbolExists) include(CheckSymbolExists)
function(tuklib_mbstr TARGET_OR_ALL) function(tuklib_mbstr TARGET_OR_ALL)
check_symbol_exists(mbrtowc wchar.h HAVE_MBRTOWC) check_symbol_exists(mbrtowc wchar.h HAVE_MBRTOWC)
tuklib_add_definition_if(${TARGET_OR_ALL} HAVE_MBRTOWC) tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_MBRTOWC)
# NOTE: wcwidth() requires _GNU_SOURCE or _XOPEN_SOURCE on GNU/Linux. # NOTE: wcwidth() requires _GNU_SOURCE or _XOPEN_SOURCE on GNU/Linux.
check_symbol_exists(wcwidth wchar.h HAVE_WCWIDTH) check_symbol_exists(wcwidth wchar.h HAVE_WCWIDTH)
tuklib_add_definition_if(${TARGET_OR_ALL} HAVE_WCWIDTH) tuklib_add_definition_if("${TARGET_OR_ALL}" HAVE_WCWIDTH)
endfunction() endfunction()

View file

@ -10,15 +10,11 @@
# You can do whatever you want with this file. # You can do whatever you want with this file.
# #
include(${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake) include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
include(CheckCSourceCompiles) include(CheckCSourceCompiles)
include(CheckIncludeFile) include(CheckIncludeFile)
function(tuklib_physmem_internal_check) function(tuklib_physmem_internal_check)
if(CACHE{TUKLIB_PHYSMEM_DEFINITIONS})
return()
endif()
# Shortcut on Windows: # Shortcut on Windows:
if(WIN32 OR CYGWIN) if(WIN32 OR CYGWIN)
# Nothing to do, the tuklib_physmem.c handles it. # Nothing to do, the tuklib_physmem.c handles it.
@ -134,16 +130,21 @@ function(tuklib_physmem_internal_check)
endfunction() endfunction()
function(tuklib_physmem TARGET_OR_ALL) function(tuklib_physmem TARGET_OR_ALL)
if(NOT DEFINED CACHE{TUKLIB_PHYSMEM_FOUND})
message(STATUS "Checking how to detect the amount of physical memory") message(STATUS "Checking how to detect the amount of physical memory")
tuklib_physmem_internal_check() tuklib_physmem_internal_check()
if(NOT DEFINED CACHE{TUKLIB_PHYSMEM_DEFINITIONS}) if(DEFINED CACHE{TUKLIB_PHYSMEM_DEFINITIONS})
set(TUKLIB_PHYSMEM_FOUND 0 PARENT_SCOPE) set(TUKLIB_PHYSMEM_FOUND 1 CACHE INTERNAL "")
else()
set(TUKLIB_PHYSMEM_FOUND 0 CACHE INTERNAL "")
message(WARNING message(WARNING
"No method to detect the amount of physical memory was found") "No method to detect the amount of physical memory was found")
else() endif()
set(TUKLIB_PHYSMEM_FOUND 1 PARENT_SCOPE) endif()
tuklib_add_definitions(${TARGET_OR_ALL} ${TUKLIB_PHYSMEM_DEFINITIONS})
if(TUKLIB_PHYSMEM_FOUND)
tuklib_add_definitions("${TARGET_OR_ALL}"
"${TUKLIB_PHYSMEM_DEFINITIONS}")
endif() endif()
endfunction() endfunction()

View file

@ -7,13 +7,13 @@
# You can do whatever you want with this file. # You can do whatever you want with this file.
# #
include(${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake) include("${CMAKE_CURRENT_LIST_DIR}/tuklib_common.cmake")
include(CheckSymbolExists) include(CheckSymbolExists)
function(tuklib_progname TARGET_OR_ALL) function(tuklib_progname TARGET_OR_ALL)
# NOTE: This glibc extension requires _GNU_SOURCE. # NOTE: This glibc extension requires _GNU_SOURCE.
check_symbol_exists(program_invocation_name errno.h check_symbol_exists(program_invocation_name errno.h
HAVE_DECL_PROGRAM_INVOCATION_NAME) HAVE_DECL_PROGRAM_INVOCATION_NAME)
tuklib_add_definition_if(${TARGET_OR_ALL} tuklib_add_definition_if("${TARGET_OR_ALL}"
HAVE_DECL_PROGRAM_INVOCATION_NAME) HAVE_DECL_PROGRAM_INVOCATION_NAME)
endfunction() endfunction()