cmake: refactor FindSSP.cmake
Use a function to not pollute variable scope. Use modern style. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
parent
5a77d8f4ba
commit
12fa61af82
|
@ -6,91 +6,71 @@
|
||||||
#
|
#
|
||||||
# To use:
|
# To use:
|
||||||
#
|
#
|
||||||
# put a copy into your <project_root>/CMakeScripts/
|
# put a copy into your <project_root>/cmake/
|
||||||
#
|
#
|
||||||
# In your main CMakeLists.txt do something like this:
|
# In your main CMakeLists.txt do something like this:
|
||||||
#
|
#
|
||||||
# IF(WIN32)
|
# if(WIN32)
|
||||||
# SET(SSP_STATIC ON)
|
# set(SSP_STATIC ON)
|
||||||
# ENDIF(WIN32)
|
# endif()
|
||||||
#
|
#
|
||||||
# FIND_PACKAGE(SSP)
|
# find_package(SSP)
|
||||||
#
|
#
|
||||||
# IF(SSP_LIBRARY)
|
# if(SSP_LIBRARY)
|
||||||
# SET(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${SSP_LIBRARY}")
|
# set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} ${SSP_LIBRARY}")
|
||||||
# SET(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${SSP_LIBRARY}")
|
# set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${SSP_LIBRARY}")
|
||||||
# ENDIF(SSP_LIBRARY)
|
# endif()
|
||||||
#
|
|
||||||
# BSD 2-Clause License
|
|
||||||
#
|
|
||||||
# Copyright (c) 2016, Rafael Kitover
|
|
||||||
# All rights reserved.
|
|
||||||
#
|
|
||||||
# Redistribution and use in source and binary forms, with or without
|
|
||||||
# modification, are permitted provided that the following conditions are met:
|
|
||||||
#
|
|
||||||
# * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
# list of conditions and the following disclaimer.
|
|
||||||
#
|
|
||||||
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
# this list of conditions and the following disclaimer in the documentation
|
|
||||||
# and/or other materials provided with the distribution.
|
|
||||||
#
|
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
|
|
||||||
# only do this when compiling with gcc/g++
|
# only do this when compiling with gcc/g++
|
||||||
IF(NOT (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_GNUC))
|
if(NOT CMAKE_COMPILER_IS_GNUCXX)
|
||||||
RETURN()
|
return()
|
||||||
ENDIF()
|
endif()
|
||||||
|
|
||||||
foreach(arg ${CMAKE_C_COMPILER_ARG1} ${CMAKE_C_COMPILER_ARG2} ${CMAKE_C_COMPILER_ARG3} ${CMAKE_C_COMPILER_ARG4} ${CMAKE_C_COMPILER_ARG5} ${CMAKE_C_COMPILER_ARG6} ${CMAKE_C_COMPILER_ARG7} ${CMAKE_C_COMPILER_ARG8} ${CMAKE_C_COMPILER_ARG9})
|
function(FindSSP)
|
||||||
string(STRIP ${arg} arg)
|
if(NOT CMAKE_CXX_COMPILER AND CMAKE_C_COMPILER)
|
||||||
set(gcc_args "${gcc_args};${arg}")
|
set(CMAKE_CXX_COMPILER ${CMAKE_C_COMPILER})
|
||||||
endforeach()
|
endif()
|
||||||
|
|
||||||
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} ${gcc_args} --print-prog-name=gcc OUTPUT_VARIABLE GCC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
foreach(arg ${CMAKE_CXX_COMPILER_ARG1} ${CMAKE_CXX_COMPILER_ARG2} ${CMAKE_CXX_COMPILER_ARG3} ${CMAKE_CXX_COMPILER_ARG4} ${CMAKE_CXX_COMPILER_ARG5} ${CMAKE_CXX_COMPILER_ARG6} ${CMAKE_CXX_COMPILER_ARG7} ${CMAKE_CXX_COMPILER_ARG8} ${CMAKE_CXX_COMPILER_ARG9})
|
||||||
|
string(STRIP ${arg} arg)
|
||||||
|
set(gcc_args "${gcc_args};${arg}")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
execute_process(COMMAND sh -c "command -v ${GCC_EXECUTABLE}" OUTPUT_VARIABLE GCC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${gcc_args} --print-prog-name=gcc OUTPUT_VARIABLE GCC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
GET_FILENAME_COMPONENT(GCC_DIRNAME ${GCC_EXECUTABLE} DIRECTORY)
|
if(WIN32 AND NOT MSYS)
|
||||||
|
execute_process(COMMAND where.exe ${GCC_EXECUTABLE} OUTPUT_VARIABLE GCC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
else()
|
||||||
|
execute_process(COMMAND sh -c "command -v ${GCC_EXECUTABLE}" OUTPUT_VARIABLE GCC_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
endif()
|
||||||
|
|
||||||
EXECUTE_PROCESS(COMMAND ${CMAKE_C_COMPILER} ${gcc_args} --print-libgcc-file-name OUTPUT_VARIABLE LIBGCC_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
get_filename_component(GCC_DIRNAME "${GCC_EXECUTABLE}" DIRECTORY)
|
||||||
|
|
||||||
GET_FILENAME_COMPONENT(LIBGCC_DIRNAME ${LIBGCC_FILE} DIRECTORY)
|
execute_process(COMMAND ${CMAKE_CXX_COMPILER} ${gcc_args} --print-libgcc-file-name OUTPUT_VARIABLE LIBGCC_FILE OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||||
|
|
||||||
SET(SSP_SEARCH_PATHS ${GCC_DIRNAME} ${LIBGCC_DIRNAME})
|
get_filename_component(LIBGCC_DIRNAME "${LIBGCC_FILE}" DIRECTORY)
|
||||||
|
|
||||||
SET(CURRENT_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
set(SSP_SEARCH_PATHS ${GCC_DIRNAME} ${LIBGCC_DIRNAME})
|
||||||
|
|
||||||
IF(SSP_STATIC)
|
if(SSP_STATIC)
|
||||||
IF(WIN32)
|
if(WIN32)
|
||||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a)
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a)
|
||||||
ELSE(WIN32)
|
else()
|
||||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a)
|
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
|
||||||
ENDIF(WIN32)
|
endif()
|
||||||
ENDIF(SSP_STATIC)
|
endif()
|
||||||
|
|
||||||
FIND_LIBRARY(SSP_LIBRARY
|
find_library(SSP_LIBRARY
|
||||||
NAMES ssp libssp
|
NAMES ssp libssp
|
||||||
HINTS ${SSP_SEARCH_PATHS}
|
HINTS ${SSP_SEARCH_PATHS}
|
||||||
PATH_SUFFIXES lib64 lib lib/x64 lib/x86
|
PATH_SUFFIXES lib64 lib lib/x64 lib/x86
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CURRENT_FIND_LIBRARY_SUFFIXES})
|
set(SSP_LIBRARY PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
FOREACH(VAR GCC_DIRNAME LIBGCC_FILE LIBGCC_DIRNAME SSP_SEARCH_PATHS CURRENT_FIND_LIBRARY_SUFFIXES)
|
FindSSP()
|
||||||
UNSET(${VAR})
|
|
||||||
ENDFOREACH()
|
|
||||||
|
|
||||||
INCLUDE(FindPackageHandleStandardArgs)
|
include(FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SSP REQUIRED_VARS SSP_LIBRARY)
|
find_package_handle_standard_args(SSP REQUIRED_VARS SSP_LIBRARY)
|
||||||
|
|
Loading…
Reference in New Issue