try to cache results as much as possible

This commit is contained in:
Danny Robson 2017-01-18 21:43:30 +11:00
parent 566b98e5cb
commit b389d86391
6 changed files with 102 additions and 72 deletions

View File

@ -1,5 +1,5 @@
macro (canonical_host) macro (canonical_host)
if (NOT __test_canonical_host) if (NOT DEFINED host_cpu)
message (STATUS "checking the host CPU") message (STATUS "checking the host CPU")
execute_process ( execute_process (
@ -12,10 +12,9 @@ macro (canonical_host)
message (FATAL_ERROR "unable to query for canonical host") message (FATAL_ERROR "unable to query for canonical host")
endif (${__canonical_host_result}) 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}'") message (STATUS "checking the host CPU - found '${host_cpu}'")
endif (NOT __test_canonical_host) endif ()
set (__test_canonical_host 1 INTERNAL)
endmacro (canonical_host) endmacro (canonical_host)

View File

@ -3,11 +3,11 @@ include(CheckCXXCompilerFlag)
macro (append_compile_flag _flag) macro (append_compile_flag _flag)
string (MAKE_C_IDENTIFIER ${_flag} _name) string (MAKE_C_IDENTIFIER ${_flag} _name)
if (NOT __append_compile_flag_${_name}) if (NOT DEFINED compile_flag_${_name})
check_cxx_compiler_flag (${_flag} __append_compile_flag_${_name}) check_cxx_compiler_flag (${_flag} compile_flag_${_name})
if (__append_compile_flag_${_name})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
set (__append_compile_flag_${_name} 1 INTERNAL)
endif () endif ()
if (compile_flag_${_name})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}")
endif() endif()
endmacro(append_compile_flag) endmacro(append_compile_flag)

View File

@ -1,25 +1,36 @@
macro(check_link_flag variable flag) macro(check_link_flag _variable _flag)
message (STATUS "checking linker flag ${flag}") string (MAKE_C_IDENTIFIER ${_flag} _name)
if (NOT DEFINED __check_link_flag_${_name})
message (STATUS "checking linker flag ${_flag}")
set (__check_linker_flag_old "${CMAKE_EXE_LINKER_FLAGS}" INTERNAL) set (__check_linker_flag_old "${CMAKE_EXE_LINKER_FLAGS}" INTERNAL)
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${flag}") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}")
try_compile (test_check_linker_flag try_compile (
__check_link_flag_${_name}
"${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp" "${CMAKE_CURRENT_BINARY_DIR}/CMakeTmp"
SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test_link_flag.cpp") SOURCES
if (test_check_linker_flag) "${CMAKE_CURRENT_SOURCE_DIR}/cmake/test_link_flag.cpp")
message (STATUS "checking linker flag ${flag} - found")
set (${variable} 1) if (__check_link_flag_${_name})
else(test_check_linker_flag) message (STATUS "checking linker flag ${_flag} - found")
message (STATUS "checking linker flag ${flag} - not found") else()
set (${variable} 0) message (STATUS "checking linker flag ${_flag} - not found")
endif(test_check_linker_flag) endif()
endif ()
if (__check_link_flag_${_name})
set (${variable} 1 INTERNAL)
else()
set (${variable} 0 INTERNAL)
endif()
endmacro() endmacro()
macro(append_link_flag flag) macro(append_link_flag flag)
check_link_flag (__test_link_flag_${flag} ${flag}) check_link_flag (__test_link_flag_${flag} ${flag})
if (__test_link_flag_${flag}) if (__test_link_flag_${_flag})
set (CMAKE_EXE_LINKER_FLAGS "${__append_link_flag_old}") set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${_flag}")
endif() endif()
endmacro() endmacro()

View File

@ -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,17 +13,29 @@ append_compile_flag (-std=c++1z)
# hardcoded guess and doesn't respect _all_ the system paths; specifically # 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 # something like /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libstdc++.so won't get
# discovered. # discovered.
if (NOT DEFINED __nc_cxx_stdcxxfs)
foreach(lib "" stdc++fs) foreach(lib "" stdc++fs)
if (NOT __nc_cxx_stdcxxfs) if (NOT __nc_cxx_stdcxxfs)
try_compile(__nc_cxx_stdcxxfs ${CMAKE_CURRENT_BINARY_DIR} try_compile(
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/nc_cxx_stdcxxfs.cpp __nc_cxx_stdcxxfs ${CMAKE_CURRENT_BINARY_DIR}
LINK_LIBRARIES ${lib}) SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/nc_cxx_stdcxxfs.cpp
LINK_LIBRARIES
${lib})
if (__nc_cxx_stdcxxfs) if (__nc_cxx_stdcxxfs)
list (APPEND LIBS ${lib}) set (__nc_cxx_stdcxxfs "${lib}" CACHE INTERNAL "library required for c++ filesystem")
endif () endif ()
endif () endif ()
endforeach() endforeach()
if (NOT __nc_cxx_stdcxxfs)
set (__nc_cxx_stdcxxfs)
endif ()
endif ()
list (APPEND LIBS ${__nc_cxx_stdcxxfs})
############################################################################### ###############################################################################
test_restrict(RESTRICT_KEYWORD) test_restrict(RESTRICT_KEYWORD)

View File

@ -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(-mtune=generic)
append_compile_flag(-msse) append_compile_flag(-msse)
append_compile_flag(-msse2) append_compile_flag(-msse2)
append_compile_flag(-msahf) append_compile_flag(-msahf)
elseif (${HOST_CPU} STREQUAL "i686") elseif (${host_cpu} STREQUAL "i686")
append_compile_flag(-march=prescott) append_compile_flag(-march=prescott)
append_compile_flag(-mtune=generic) append_compile_flag(-mtune=generic)
append_compile_flag(-mcmov) append_compile_flag(-mcmov)
append_compile_flag(-mfpmath=sse) append_compile_flag(-mfpmath=sse)
else () else ()
message (FATAL_ERROR "unknown HOST_CPU '${HOST_CPU}'") message (FATAL_ERROR "unknown HOST_CPU '${host_cpu}'")
endif () endif ()

View File

@ -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) macro(search_libs _variable _symbol)
if (NOT DEFINED __search_libs_${_symbol})
message (STATUS "searching for ${_symbol}") message (STATUS "searching for ${_symbol}")
if (NOT DEFINED __search_libs_${_symbol}_lib)
try_compile( try_compile(
__search_libs_${_symbol} __search_libs_${_symbol}
"${CMAKE_BINARY_DIR}/CMakeTmp" "${CMAKE_BINARY_DIR}/CMakeTmp"
SOURCES "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp" SOURCES
COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}") "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
COMPILE_DEFINITIONS
"-DSYMBOL=${_symbol}")
if (NOT __search_libs_${_symbol}) if (__search_libs_${_symbol})
set (__search_libs_${_symbol}_lib)
else ()
foreach (lib ${ARGN}) foreach (lib ${ARGN})
if (NOT __search_libs_${_symbol}_last) if (NOT __search_libs_${_symbol})
message (STATUS "searching for ${_symbol} in ${lib}") message (STATUS "searching for ${_symbol} in ${lib}")
try_compile( try_compile(
__search_libs_${_symbol} __search_libs_${_symbol}
"${CMAKE_BINARY_DIR}/CMakeTmp" "${CMAKE_BINARY_DIR}/CMakeTmp"
SOURCES "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp" SOURCES
LINK_LIBRARIES "-l${lib}" "${CMAKE_SOURCE_DIR}/cmake/search_libs.cpp"
COMPILE_DEFINITIONS "-DSYMBOL=${_symbol}") LINK_LIBRARIES
set (__search_libs_${_symbol}_last ${lib}) "${lib}"
COMPILE_DEFINITIONS
"-DSYMBOL=${_symbol}")
if (__search_libs_${_symbol})
set (__search_libs_${_symbol}_lib ${lib} CACHE INTERNAL "library exposing ${_symbol}")
endif ()
endif () endif ()
endforeach() endforeach()
endif () endif ()
endif ()
if (__search_libs_${_symbol}) 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") message (STATUS "searching for ${_symbol} - found")
endif ()
set (${_variable} __search_libs_${_symbol}_last)
string (TOUPPER ${_symbol} upper_symbol)
set (HAVE_${upper_symbol} 1)
else () else ()
message (STATUS "searching for ${_symbol} - not found") message (STATUS "searching for ${_symbol} - not found")
endif() endif()
endif ()
set (${_variable} ${__search_libs_${_symbol}_lib})
endmacro() endmacro()