try to cache results as much as possible
This commit is contained in:
parent
566b98e5cb
commit
b389d86391
@ -1,5 +1,5 @@
|
||||
macro (canonical_host)
|
||||
if (NOT __test_canonical_host)
|
||||
if (NOT DEFINED host_cpu)
|
||||
message (STATUS "checking the host CPU")
|
||||
|
||||
execute_process (
|
||||
@ -12,10 +12,9 @@ macro (canonical_host)
|
||||
message (FATAL_ERROR "unable to query for canonical host")
|
||||
endif (${__canonical_host_result})
|
||||
|
||||
string(REGEX MATCH "^([^-\]+)" HOST_CPU ${__canonical_host_output})
|
||||
string(REGEX MATCH "^([^-\]+)" host_cpu ${__canonical_host_output})
|
||||
set (host_cpu "${host_cpu}" CACHE INTERNAL "host cpu type")
|
||||
|
||||
message (STATUS "checking the host CPU - found '${HOST_CPU}'")
|
||||
endif (NOT __test_canonical_host)
|
||||
|
||||
set (__test_canonical_host 1 INTERNAL)
|
||||
message (STATUS "checking the host CPU - found '${host_cpu}'")
|
||||
endif ()
|
||||
endmacro (canonical_host)
|
||||
|
@ -3,11 +3,11 @@ include(CheckCXXCompilerFlag)
|
||||
macro (append_compile_flag _flag)
|
||||
string (MAKE_C_IDENTIFIER ${_flag} _name)
|
||||
|
||||
if (NOT __append_compile_flag_${_name})
|
||||
check_cxx_compiler_flag (${_flag} __append_compile_flag_${_name})
|
||||
if (__append_compile_flag_${_name})
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
|
||||
set (__append_compile_flag_${_name} 1 INTERNAL)
|
||||
endif ()
|
||||
if (NOT DEFINED compile_flag_${_name})
|
||||
check_cxx_compiler_flag (${_flag} compile_flag_${_name})
|
||||
endif ()
|
||||
|
||||
if (compile_flag_${_name})
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
|
||||
endif()
|
||||
endmacro(append_compile_flag)
|
||||
|
@ -1,25 +1,36 @@
|
||||
macro(check_link_flag variable flag)
|
||||
message (STATUS "checking linker flag ${flag}")
|
||||
macro(check_link_flag _variable _flag)
|
||||
string (MAKE_C_IDENTIFIER ${_flag} _name)
|
||||
|
||||
set (__check_linker_flag_old "${CMAKE_EXE_LINKER_FLAGS}" INTERNAL)
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}")
|
||||
if (NOT DEFINED __check_link_flag_${_name})
|
||||
message (STATUS "checking linker flag ${_flag}")
|
||||
|
||||
try_compile (test_check_linker_flag
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp"
|
||||
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test_link_flag.cpp")
|
||||
if (test_check_linker_flag)
|
||||
message (STATUS "checking linker flag ${flag} - found")
|
||||
set (${variable} 1)
|
||||
else(test_check_linker_flag)
|
||||
message (STATUS "checking linker flag ${flag} - not found")
|
||||
set (${variable} 0)
|
||||
endif(test_check_linker_flag)
|
||||
set (__check_linker_flag_old "${CMAKE_EXE_LINKER_FLAGS}" INTERNAL)
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}")
|
||||
|
||||
try_compile (
|
||||
__check_link_flag_${_name}
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp"
|
||||
SOURCES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/test_link_flag.cpp")
|
||||
|
||||
if (__check_link_flag_${_name})
|
||||
message (STATUS "checking linker flag ${_flag} - found")
|
||||
else()
|
||||
message (STATUS "checking linker flag ${_flag} - not found")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
if (__check_link_flag_${_name})
|
||||
set (${variable} 1 INTERNAL)
|
||||
else()
|
||||
set (${variable} 0 INTERNAL)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
macro(append_link_flag flag)
|
||||
check_link_flag (__test_link_flag_${flag} ${flag})
|
||||
if (__test_link_flag_${flag})
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${__append_link_flag_old}")
|
||||
if (__test_link_flag_${_flag})
|
||||
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}")
|
||||
endif()
|
||||
endmacro()
|
||||
|
30
nc_cxx.cmake
30
nc_cxx.cmake
@ -3,7 +3,7 @@ include (test_restrict)
|
||||
|
||||
|
||||
###############################################################################
|
||||
append_compile_flag (-std=c++1z)
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1z -fpermissive")
|
||||
|
||||
|
||||
###############################################################################
|
||||
@ -13,16 +13,28 @@ append_compile_flag (-std=c++1z)
|
||||
# hardcoded guess and doesn't respect _all_ the system paths; specifically
|
||||
# something like /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libstdc++.so won't get
|
||||
# discovered.
|
||||
foreach(lib "" stdc++fs)
|
||||
if (NOT __nc_cxx_stdcxxfs)
|
||||
try_compile(__nc_cxx_stdcxxfs ${CMAKE_CURRENT_BINARY_DIR}
|
||||
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/nc_cxx_stdcxxfs.cpp
|
||||
LINK_LIBRARIES ${lib})
|
||||
if (__nc_cxx_stdcxxfs)
|
||||
list (APPEND LIBS ${lib})
|
||||
if (NOT DEFINED __nc_cxx_stdcxxfs)
|
||||
foreach(lib "" stdc++fs)
|
||||
if (NOT __nc_cxx_stdcxxfs)
|
||||
try_compile(
|
||||
__nc_cxx_stdcxxfs ${CMAKE_CURRENT_BINARY_DIR}
|
||||
SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/nc_cxx_stdcxxfs.cpp
|
||||
LINK_LIBRARIES
|
||||
${lib})
|
||||
|
||||
if (__nc_cxx_stdcxxfs)
|
||||
set (__nc_cxx_stdcxxfs "${lib}" CACHE INTERNAL "library required for c++ filesystem")
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
if (NOT __nc_cxx_stdcxxfs)
|
||||
set (__nc_cxx_stdcxxfs)
|
||||
endif ()
|
||||
endforeach()
|
||||
endif ()
|
||||
|
||||
list (APPEND LIBS ${__nc_cxx_stdcxxfs})
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
@ -31,18 +31,18 @@ canonical_host()
|
||||
|
||||
|
||||
##-----------------------------------------------------------------------------
|
||||
if (${HOST_CPU} STREQUAL "x86_64")
|
||||
if (${host_cpu} STREQUAL "x86_64")
|
||||
append_compile_flag(-mtune=generic)
|
||||
append_compile_flag(-msse)
|
||||
append_compile_flag(-msse2)
|
||||
append_compile_flag(-msahf)
|
||||
elseif (${HOST_CPU} STREQUAL "i686")
|
||||
elseif (${host_cpu} STREQUAL "i686")
|
||||
append_compile_flag(-march=prescott)
|
||||
append_compile_flag(-mtune=generic)
|
||||
append_compile_flag(-mcmov)
|
||||
append_compile_flag(-mfpmath=sse)
|
||||
else ()
|
||||
message (FATAL_ERROR "unknown HOST_CPU '${HOST_CPU}'")
|
||||
message (FATAL_ERROR "unknown HOST_CPU '${host_cpu}'")
|
||||
endif ()
|
||||
|
||||
|
||||
|
@ -1,39 +1,47 @@
|
||||
# search a list of libraries for a given (C linkage) _symbol. returns the
|
||||
# required library in _variable, and defines HAVE_SYMBOL if it was found.
|
||||
macro(search_libs _variable _symbol)
|
||||
message (STATUS "searching for ${_symbol}")
|
||||
if (NOT DEFINED __search_libs_${_symbol})
|
||||
message (STATUS "searching for ${_symbol}")
|
||||
|
||||
try_compile(
|
||||
__search_libs_${_symbol}
|
||||
"${CMAKE_BINARY_DIR}/CMakeTmp"
|
||||
SOURCES "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
|
||||
COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}")
|
||||
if (NOT DEFINED __search_libs_${_symbol}_lib)
|
||||
try_compile(
|
||||
__search_libs_${_symbol}
|
||||
"${CMAKE_BINARY_DIR}/CMakeTmp"
|
||||
SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
|
||||
COMPILE_DEFINITIONS
|
||||
"-DSYMBOL=${_symbol}")
|
||||
|
||||
if (NOT __search_libs_${_symbol})
|
||||
foreach (lib ${ARGN})
|
||||
if (NOT __search_libs_${_symbol}_last)
|
||||
message (STATUS "searching for ${_symbol} in ${lib}")
|
||||
try_compile(
|
||||
__search_libs_${_symbol}
|
||||
"${CMAKE_BINARY_DIR}/CMakeTmp"
|
||||
SOURCES "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
|
||||
LINK_LIBRARIES "-l${lib}"
|
||||
COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}")
|
||||
set (__search_libs_${_symbol}_last ${lib})
|
||||
if (__search_libs_${_symbol})
|
||||
set (__search_libs_${_symbol}_lib)
|
||||
else ()
|
||||
foreach (lib ${ARGN})
|
||||
if (NOT __search_libs_${_symbol})
|
||||
message (STATUS "searching for ${_symbol} in ${lib}")
|
||||
|
||||
try_compile(
|
||||
__search_libs_${_symbol}
|
||||
"${CMAKE_BINARY_DIR}/CMakeTmp"
|
||||
SOURCES
|
||||
"${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
|
||||
LINK_LIBRARIES
|
||||
"${lib}"
|
||||
COMPILE_DEFINITIONS
|
||||
"-DSYMBOL=${_symbol}")
|
||||
|
||||
if (__search_libs_${_symbol})
|
||||
set (__search_libs_${_symbol}_lib ${lib} CACHE INTERNAL "library exposing ${_symbol}")
|
||||
endif ()
|
||||
endif ()
|
||||
endforeach()
|
||||
endif ()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
if (__search_libs_${_symbol})
|
||||
if (__search_libs_${_symbol}_last)
|
||||
message (STATUS "searching for ${_symbol} - found (in ${__search_libs_${_symbol}_last})")
|
||||
else ()
|
||||
message (STATUS "searching for ${_symbol} - found")
|
||||
endif ()
|
||||
set (${_variable} __search_libs_${_symbol}_last)
|
||||
string (TOUPPER ${_symbol} upper_symbol)
|
||||
set (HAVE_${upper_symbol} 1)
|
||||
else ()
|
||||
message (STATUS "searching for ${_symbol} - not found")
|
||||
|
||||
if (__search_libs_${_symbol})
|
||||
message (STATUS "searching for ${_symbol} - found")
|
||||
else ()
|
||||
message (STATUS "searching for ${_symbol} - not found")
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
set (${_variable} ${__search_libs_${_symbol}_lib})
|
||||
endmacro()
|
||||
|
Loading…
Reference in New Issue
Block a user