Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
badaix committed Dec 30, 2023
1 parent 6e78625 commit 6441ca0
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 176 deletions.
122 changes: 62 additions & 60 deletions cmake/CheckAtomic.cmake
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# ==============================================================================
# LLVM Release License
# ==============================================================================
# University of Illinois/NCSA
# Open Source License
# University of Illinois/NCSA Open Source License
#
# Copyright (c) 2003-2018 University of Illinois at Urbana-Champaign.
# All rights reserved.
# Copyright (c) 2003-2018 University of Illinois at Urbana-Champaign. All rights
# reserved.
#
# Developed by:
#
Expand All @@ -15,96 +14,99 @@
#
# http://llvm.org
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal with
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# with the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimers.
# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimers.
#
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimers in the
# documentation and/or other materials provided with the distribution.
# this list of conditions and the following disclaimers in the documentation
# and/or other materials provided with the distribution.
#
# * Neither the names of the LLVM Team, University of Illinois at
# Urbana-Champaign, nor the names of its contributors may be used to
# endorse or promote products derived from this Software without specific
# prior written permission.
# Urbana-Champaign, nor the names of its contributors may be used to endorse
# or promote products derived from this Software without specific prior
# written permission.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
# SOFTWARE.
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
# THE SOFTWARE.

INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckLibraryExists)

# Sometimes linking against libatomic is required for atomic ops, if
# the platform doesn't support lock-free atomics.
include(CheckCXXSourceCompiles)
include(CheckLibraryExists)

# Sometimes linking against libatomic is required for atomic ops, if the
# platform doesn't support lock-free atomics.

function(check_working_cxx_atomics varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
CHECK_CXX_SOURCE_COMPILES("
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
check_cxx_source_compiles(
"
#include <atomic>
std::atomic<long long> x;
int main() {
return std::atomic_is_lock_free(&x);
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
"
${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics)


function(check_working_cxx_atomics64 varname)
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
CHECK_CXX_SOURCE_COMPILES("
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
check_cxx_source_compiles(
"
#include <atomic>
#include <cstdint>
std::atomic<uint64_t> x (0);
int main() {
uint64_t i = x.load(std::memory_order_relaxed);
return std::atomic_is_lock_free(&x);
}
" ${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
"
${varname})
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
endfunction(check_working_cxx_atomics64)


function(check_working_cxx_atomics_2args varname)
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
CHECK_CXX_SOURCE_COMPILES("
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_cxx_source_compiles(
"
int main() {
__atomic_load(nullptr, 0);
return 0;
}
" ${varname})
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
"
${varname})
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
endfunction(check_working_cxx_atomics_2args)


function(check_working_cxx_atomics64_2args varname)
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
CHECK_CXX_SOURCE_COMPILES("
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
check_cxx_source_compiles(
"
int main() {
__atomic_load_8(nullptr, 0);
return 0;
}
" ${varname})
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
"
${varname})
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
endfunction(check_working_cxx_atomics64_2args)


# First check if atomics work without the library.
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)

Expand All @@ -113,14 +115,14 @@ set(ATOMIC_LIBRARY "")
# If not, check if the library exists, and atomics work with it.
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
if( NOT HAVE_LIBATOMIC )
if(NOT HAVE_LIBATOMIC)
check_working_cxx_atomics_2args(HAVE_LIBATOMIC_2ARGS)
endif()
if( HAVE_LIBATOMIC OR HAVE_LIBATOMIC_2ARGS )
if(HAVE_LIBATOMIC OR HAVE_LIBATOMIC_2ARGS)
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
set(ATOMIC_LIBRARY "atomic")
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
if(NOT HAVE_CXX_ATOMICS_WITH_LIB)
message(FATAL_ERROR "Host compiler must support std::atomic!")
endif()
else()
Expand All @@ -132,24 +134,24 @@ if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
endif()

# If not, check if the library exists, and atomics work with it.
if( NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB )
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMICS64)
if( NOT HAVE_CXX_LIBATOMICS64 )
if(NOT HAVE_CXX_LIBATOMICS64)
check_working_cxx_atomics64_2args(HAVE_CXX_LIBATOMICS64_2ARGS)
endif()
if( HAVE_CXX_LIBATOMICS64 OR HAVE_CXX_LIBATOMICS64_2ARGS )
if(HAVE_CXX_LIBATOMICS64 OR HAVE_CXX_LIBATOMICS64_2ARGS)
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
set(ATOMIC_LIBRARY "atomic")
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
if(NOT HAVE_CXX_ATOMICS64_WITH_LIB)
message(FATAL_ERROR "Host compiler must support std::atomic!")
endif()
else()
message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
message(
FATAL_ERROR
"Host compiler appears to require libatomic, but cannot find it.")
endif()
endif()

endif()
endif()


36 changes: 18 additions & 18 deletions cmake/CheckCXX11StringSupport.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# This file is part of snapcast
# Copyright (C) 2014-2020 Johannes Pohl
# This file is part of snapcast Copyright (C) 2014-2020 Johannes Pohl

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.

#[=======================================================================[.rst:
CheckCXX11StringSupport
Expand All @@ -33,12 +32,12 @@ See also: https://stackoverflow.com/questions/17950814/how-to-use-stdstoul-and-s
failure.
#]=======================================================================]


include(CheckCXXSourceCompiles)

macro (CHECK_CXX11_STRING_SUPPORT _RESULT)
set(CMAKE_REQUIRED_DEFINITIONS -std=c++0x)
set(_CHECK_CXX11_STRING_SUPPORT_SOURCE_CODE "
macro(CHECK_CXX11_STRING_SUPPORT _RESULT)
set(CMAKE_REQUIRED_DEFINITIONS -std=c++0x)
set(_CHECK_CXX11_STRING_SUPPORT_SOURCE_CODE
"
#include <string>
int main()
{
Expand All @@ -50,5 +49,6 @@ int main()
}
")

CHECK_CXX_SOURCE_COMPILES("${_CHECK_CXX11_STRING_SUPPORT_SOURCE_CODE}" ${_RESULT})
endmacro ()
check_cxx_source_compiles("${_CHECK_CXX11_STRING_SUPPORT_SOURCE_CODE}"
${_RESULT})
endmacro()
29 changes: 15 additions & 14 deletions cmake/SystemdService.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
########
#
# Find systemd service dir

pkg_check_modules(SYSTEMD "systemd")
if (SYSTEMD_FOUND AND "${SYSTEMD_SERVICES_INSTALL_DIR}" STREQUAL "")
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE}
--variable=systemdsystemunitdir systemd
OUTPUT_VARIABLE SYSTEMD_SERVICES_INSTALL_DIR)
string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_SERVICES_INSTALL_DIR
"${SYSTEMD_SERVICES_INSTALL_DIR}")
elseif (NOT SYSTEMD_FOUND AND SYSTEMD_SERVICES_INSTALL_DIR)
message (FATAL_ERROR "Variable SYSTEMD_SERVICES_INSTALL_DIR is\
if(SYSTEMD_FOUND AND "${SYSTEMD_SERVICES_INSTALL_DIR}" STREQUAL "")
execute_process(
COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=systemdsystemunitdir systemd
OUTPUT_VARIABLE SYSTEMD_SERVICES_INSTALL_DIR)
string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_SERVICES_INSTALL_DIR
"${SYSTEMD_SERVICES_INSTALL_DIR}")
elseif(NOT SYSTEMD_FOUND AND SYSTEMD_SERVICES_INSTALL_DIR)
message(FATAL_ERROR "Variable SYSTEMD_SERVICES_INSTALL_DIR is\
defined, but we can't find systemd using pkg-config")
endif()

if (SYSTEMD_FOUND)
set(WITH_SYSTEMD "ON")
message(STATUS "systemd services install dir: ${SYSTEMD_SERVICES_INSTALL_DIR}")
if(SYSTEMD_FOUND)
set(WITH_SYSTEMD "ON")
message(
STATUS "systemd services install dir: ${SYSTEMD_SERVICES_INSTALL_DIR}")
else()
set(WITH_SYSTEMD "OFF")
endif (SYSTEMD_FOUND)
set(WITH_SYSTEMD "OFF")
endif(SYSTEMD_FOUND)
Loading

0 comments on commit 6441ca0

Please sign in to comment.