From 50a3cd678a095c457de6f5d8de189842870d451e Mon Sep 17 00:00:00 2001 From: Hauke Heibel Date: Sun, 20 Feb 2011 11:54:07 +0100 Subject: [PATCH] Improved site and buildname generation. --- CMakeLists.txt | 39 ++----- cmake/CMakeDetermineVSServicePack.cmake | 103 +++++++++++++++++ cmake/EigenConfigureTesting.cmake | 76 ++++++++++++ cmake/EigenDetermineOSVersion.cmake | 48 ++++++++ cmake/EigenTesting.cmake | 148 +++++++++++++++++++----- 5 files changed, 353 insertions(+), 61 deletions(-) create mode 100644 cmake/CMakeDetermineVSServicePack.cmake create mode 100644 cmake/EigenConfigureTesting.cmake create mode 100644 cmake/EigenDetermineOSVersion.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 39b29e48d..b79ec4715 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,6 +101,8 @@ if(EIGEN_DEFAULT_TO_ROW_MAJOR) add_definitions("-DEIGEN_DEFAULT_TO_ROW_MAJOR") endif() +add_definitions("-DEIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS") + if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wno-long-long -ansi -Wundef -Wcast-align -Wchar-subscripts -Wall -W -Wpointer-arith -Wwrite-strings -Wformat-security -fexceptions -fno-check-new -fno-common -fstrict-aliasing") set(CMAKE_CXX_FLAGS_DEBUG "-g3") @@ -277,34 +279,7 @@ add_subdirectory(Eigen) add_subdirectory(doc EXCLUDE_FROM_ALL) -add_custom_target(buildtests) -add_custom_target(check COMMAND "ctest") -add_dependencies(check buildtests) - -# CMake/Ctest does not allow us to change the build command, -# so we have to workaround by directly editing the generated DartConfiguration.tcl file -# save CMAKE_MAKE_PROGRAM -set(CMAKE_MAKE_PROGRAM_SAVE ${CMAKE_MAKE_PROGRAM}) -# and set a fake one -set(CMAKE_MAKE_PROGRAM "@EIGEN_MAKECOMMAND_PLACEHOLDER@") - -include(CTest) -enable_testing() # must be called from the root CMakeLists, see man page -include(EigenTesting) -ei_init_testing() - -# overwrite default DartConfiguration.tcl -set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} buildtests") -configure_file(${CMAKE_BINARY_DIR}/DartConfiguration.tcl ${CMAKE_BINARY_DIR}/DartConfiguration.tcl) -# restore default CMAKE_MAKE_PROGRAM -set(CMAKE_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM_SAVE}) -# un-set temporary variables so that it is like they never existed. -# CMake 2.6.3 introduces the more logical unset() syntax for this. -set(CMAKE_MAKE_PROGRAM_SAVE) -set(EIGEN_MAKECOMMAND_PLACEHOLDER) - -configure_file(${CMAKE_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake) - +include(EigenConfigureTesting) if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) add_subdirectory(test) # can't do EXCLUDE_FROM_ALL here, breaks CTest @@ -312,10 +287,6 @@ else() add_subdirectory(test EXCLUDE_FROM_ALL) endif() -add_subdirectory(unsupported) - -add_subdirectory(demos EXCLUDE_FROM_ALL) - if(NOT MSVC) if(EIGEN_LEAVE_TEST_IN_ALL_TARGET) add_subdirectory(blas) @@ -326,6 +297,10 @@ if(NOT MSVC) endif() endif(NOT MSVC) +add_subdirectory(unsupported) + +add_subdirectory(demos EXCLUDE_FROM_ALL) + # must be after test and unsupported, for configuring buildtests.in add_subdirectory(scripts EXCLUDE_FROM_ALL) diff --git a/cmake/CMakeDetermineVSServicePack.cmake b/cmake/CMakeDetermineVSServicePack.cmake new file mode 100644 index 000000000..b89462308 --- /dev/null +++ b/cmake/CMakeDetermineVSServicePack.cmake @@ -0,0 +1,103 @@ +# - Includes a public function for assisting users in trying to determine the +# Visual Studio service pack in use. +# +# Sets the passed in variable to one of the following values or an empty +# string if unknown. +# vc80 +# vc80sp1 +# vc90 +# vc90sp1 +# +# Usage: +# =========================== +# +# if(MSVC) +# include(CMakeDetermineVSServicePack) +# DetermineVSServicePack( my_service_pack ) +# +# if( my_service_pack ) +# message(STATUS "Detected: ${my_service_pack}") +# endif() +# endif() +# +# =========================== + +#============================================================================= +# Copyright 2009-2010 Kitware, Inc. +# Copyright 2009-2010 Philip Lowman +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +# [INTERNAL] +# Please do not call this function directly +function(_DetermineVSServicePackFromCompiler _OUT_VAR _cl_version) + if (${_cl_version} VERSION_EQUAL "14.00.50727.42") + set(_version "vc80") + elseif(${_cl_version} VERSION_EQUAL "14.00.50727.762") + set(_version "vc80sp1") + elseif(${_cl_version} VERSION_EQUAL "15.00.21022.08") + set(_version "vc90") + elseif(${_cl_version} VERSION_EQUAL "15.00.30729.01") + set(_version "vc90sp1") + elseif(${_cl_version} VERSION_EQUAL "16.00.30319.01") + set(_version "vc100") + else() + set(_version "") + endif() + set(${_OUT_VAR} ${_version} PARENT_SCOPE) +endfunction() + +# +# A function to call to determine the Visual Studio service pack +# in use. See documentation above. +function(DetermineVSServicePack _pack) + if(NOT DETERMINED_VS_SERVICE_PACK OR NOT ${_pack}) + if(${CMAKE_BUILD_TOOL} STREQUAL "nmake") + EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} "/?" + ERROR_VARIABLE _output) + set(DETERMINED_VS_SERVICE_PACK ${_output}) + else() + file(WRITE "${CMAKE_BINARY_DIR}/return0.cc" + "int main() { return 0; }\n") + + try_compile(DETERMINED_VS_SERVICE_PACK + "${CMAKE_BINARY_DIR}" + "${CMAKE_BINARY_DIR}/return0.cc" + OUTPUT_VARIABLE _output + COPY_FILE "${CMAKE_BINARY_DIR}/return0.cc") + + file(REMOVE "${CMAKE_BINARY_DIR}/return0.cc") + endif() + + if(DETERMINED_VS_SERVICE_PACK AND _output) + string(REGEX MATCH "Compiler Version [0-9]+.[0-9]+.[0-9]+.[0-9]+" + _cl_version "${_output}") + if(_cl_version) + string(REGEX MATCHALL "[0-9]+" + _cl_version_list "${_cl_version}") + list(GET _cl_version_list 0 _major) + list(GET _cl_version_list 1 _minor) + list(GET _cl_version_list 2 _patch) + list(GET _cl_version_list 3 _tweak) + + set(_cl_version_string ${_major}.${_minor}.${_patch}.${_tweak}) + + # Call helper function to determine VS version + _DetermineVSServicePackFromCompiler(_sp "${_cl_version_string}") + if(_sp) + #set(${_pack} "${_sp}(${_cl_version_string})" CACHE INTERNAL + set(${_pack} "${_sp}" CACHE INTERNAL + "The Visual Studio Release with Service Pack") + endif() + endif() + endif() + endif() +endfunction() diff --git a/cmake/EigenConfigureTesting.cmake b/cmake/EigenConfigureTesting.cmake new file mode 100644 index 000000000..f54349d11 --- /dev/null +++ b/cmake/EigenConfigureTesting.cmake @@ -0,0 +1,76 @@ +include(EigenTesting) +include(CheckCXXSourceCompiles) + +# configure the "site" and "buildname" +ei_set_sitename() + +# retrieve and store the build string +ei_set_build_string() + +add_custom_target(buildtests) +add_custom_target(check COMMAND "ctest") +add_dependencies(check buildtests) + +# CMake/Ctest does not allow us to change the build command, +# so we have to workaround by directly editing the generated DartConfiguration.tcl file +# save CMAKE_MAKE_PROGRAM +set(CMAKE_MAKE_PROGRAM_SAVE ${CMAKE_MAKE_PROGRAM}) +# and set a fake one +set(CMAKE_MAKE_PROGRAM "@EIGEN_MAKECOMMAND_PLACEHOLDER@") + +# This call activates testing and generates the DartConfiguration.tcl +include(CTest) + +# overwrite default DartConfiguration.tcl +# The worarounds are different for each version of the MSVC IDE +if(MSVC_IDE) + if(MSVC_VERSION EQUAL 1600) # MSVC 2010 + set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} buildtests.vcxproj /p:Configuration=\${CTEST_CONFIGURATION_TYPE} \n# ") + else() # MSVC 2008 (TODO check MSVC 2005) + set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} /project buildtests") + endif() +else() + # for make and nmake + set(EIGEN_MAKECOMMAND_PLACEHOLDER "${CMAKE_MAKE_PROGRAM_SAVE} buildtests") +endif() + +# copy ctest properties, which currently +# o raise the warning levels +configure_file(${CMAKE_BINARY_DIR}/DartConfiguration.tcl ${CMAKE_BINARY_DIR}/DartConfiguration.tcl) + +# restore default CMAKE_MAKE_PROGRAM +set(CMAKE_MAKE_PROGRAM ${CMAKE_MAKE_PROGRAM_SAVE}) +# un-set temporary variables so that it is like they never existed. +# CMake 2.6.3 introduces the more logical unset() syntax for this. +set(CMAKE_MAKE_PROGRAM_SAVE) +set(EIGEN_MAKECOMMAND_PLACEHOLDER) + +configure_file(${CMAKE_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_BINARY_DIR}/CTestCustom.cmake) + +# some documentation of this function would be nice +ei_init_testing() + +# configure Eigen related testing options +option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF) +option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF) + +if(CMAKE_COMPILER_IS_GNUCXX) + option(EIGEN_COVERAGE_TESTING "Enable/disable gcov" OFF) + if(EIGEN_COVERAGE_TESTING) + set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage") + set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/test/") + else(EIGEN_COVERAGE_TESTING) + set(COVERAGE_FLAGS "") + endif(EIGEN_COVERAGE_TESTING) + if(EIGEN_TEST_C++0x) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") + endif(EIGEN_TEST_C++0x) + if(CMAKE_SYSTEM_NAME MATCHES Linux) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3") + endif(CMAKE_SYSTEM_NAME MATCHES Linux) +elseif(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS") +endif(CMAKE_COMPILER_IS_GNUCXX) diff --git a/cmake/EigenDetermineOSVersion.cmake b/cmake/EigenDetermineOSVersion.cmake new file mode 100644 index 000000000..8d2251ec5 --- /dev/null +++ b/cmake/EigenDetermineOSVersion.cmake @@ -0,0 +1,48 @@ +# The utility function DetermineOSVersion aims at providing an +# improved version of the CMake variable ${CMAKE_SYSTEM} on Windows +# machines. +# +# Usage: +# include(EigenDetermineOSVersion) +# DetermineOSVersion(OS_VERSION) +# message("OS: ${OS_VERSION}") + +# - A little helper variable which should not be directly called +function(DetermineShortWindowsName WIN_VERSION win_num_version) + if (${win_num_version} VERSION_EQUAL "6.1.7600") + set(_version "win7") + elseif(${win_num_version} VERSION_EQUAL "6.0.6000") + set(_version "winVista") + elseif(${win_num_version} VERSION_EQUAL "5.2.3790") + set(_version "winXpProf") + elseif(${win_num_version} VERSION_EQUAL "5.1.2600") + set(_version "winXp") + elseif(${win_num_version} VERSION_EQUAL "5.0.2195") + set(_version "win2000Prof") + else() + set(_version "") + endif() + set(${WIN_VERSION} ${_version} PARENT_SCOPE) +endfunction() + +function(DetermineOSVersion OS_VERSION) + if (WIN32) + file (TO_NATIVE_PATH "$ENV{COMSPEC}" SHELL) + exec_program( ${SHELL} ARGS "/c" "ver" + OUTPUT_VARIABLE ver_output) + + string(REGEX MATCHALL "[0-9]+" + ver_list "${ver_output}") + list(GET ver_list 0 _major) + list(GET ver_list 1 _minor) + list(GET ver_list 2 _patch) + + set(win_num_version ${_major}.${_minor}.${_patch}) + DetermineShortWindowsName(win_version "${win_num_version}") + if(win_version) + set(${OS_VERSION} ${win_version} PARENT_SCOPE) + endif() + else() + set(${OS_VERSION} ${CMAKE_SYSTEM} PARENT_SCOPE) + endif() +endfunction() diff --git a/cmake/EigenTesting.cmake b/cmake/EigenTesting.cmake index 4c8039315..e8838750a 100644 --- a/cmake/EigenTesting.cmake +++ b/cmake/EigenTesting.cmake @@ -1,11 +1,10 @@ -option(EIGEN_NO_ASSERTION_CHECKING "Disable checking of assertions using exceptions" OFF) -option(EIGEN_DEBUG_ASSERTS "Enable advanced debuging of assertions" OFF) - -include(CheckCXXSourceCompiles) - macro(ei_add_property prop value) - get_property(previous GLOBAL PROPERTY ${prop}) - set_property(GLOBAL PROPERTY ${prop} "${previous} ${value}") + get_property(previous GLOBAL PROPERTY ${prop}) + if (NOT ${previous} OR ${previous} STREQUAL "") + set_property(GLOBAL PROPERTY ${prop} "${value}") + else() + set_property(GLOBAL PROPERTY ${prop} "${previous} ${value}") + endif() endmacro(ei_add_property) #internal. See documentation of ei_add_test for details. @@ -181,12 +180,13 @@ endmacro(ei_add_failtest) # print a summary of the different options macro(ei_testing_print_summary) - message(STATUS "************************************************************") message(STATUS "*** Eigen's unit tests configuration summary ***") message(STATUS "************************************************************") message(STATUS "") message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") + message(STATUS "Build site: ${SITE}") + message(STATUS "Build string: ${BUILDNAME}") get_property(EIGEN_TESTING_SUMMARY GLOBAL PROPERTY EIGEN_TESTING_SUMMARY) get_property(EIGEN_TESTED_BACKENDS GLOBAL PROPERTY EIGEN_TESTED_BACKENDS) get_property(EIGEN_MISSING_BACKENDS GLOBAL PROPERTY EIGEN_MISSING_BACKENDS) @@ -252,7 +252,6 @@ macro(ei_testing_print_summary) message(STATUS "\n${EIGEN_TESTING_SUMMARY}") message(STATUS "************************************************************") - endmacro(ei_testing_print_summary) macro(ei_init_testing) @@ -273,23 +272,114 @@ macro(ei_init_testing) set_property(GLOBAL PROPERTY EIGEN_FAILTEST_COUNT "0") endmacro(ei_init_testing) -if(CMAKE_COMPILER_IS_GNUCXX) - option(EIGEN_COVERAGE_TESTING "Enable/disable gcov" OFF) - if(EIGEN_COVERAGE_TESTING) - set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage") - set(CTEST_CUSTOM_COVERAGE_EXCLUDE "/test/") - else(EIGEN_COVERAGE_TESTING) - set(COVERAGE_FLAGS "") - endif(EIGEN_COVERAGE_TESTING) - if(EIGEN_TEST_C++0x) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x") - endif(EIGEN_TEST_C++0x) - if(CMAKE_SYSTEM_NAME MATCHES Linux) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS} -g2") - set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${COVERAGE_FLAGS} -O2 -g2") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${COVERAGE_FLAGS} -fno-inline-functions") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS} -O0 -g3") - endif(CMAKE_SYSTEM_NAME MATCHES Linux) -elseif(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS") -endif(CMAKE_COMPILER_IS_GNUCXX) +macro(ei_set_sitename) + # if the sitename is not yet set, try to set it + if(NOT ${SITE} OR ${SITE} STREQUAL "") + set(eigen_computername $ENV{COMPUTERNAME}) + set(eigen_hostname $ENV{HOSTNAME}) + if(eigen_hostname) + set(SITE ${eigen_hostname}) + elseif(eigen_computername) + set(SITE ${eigen_computername}) + endif() + endif() + # in case it is already set, enforce lower case + if(SITE) + string(TOLOWER ${SITE} SITE) + endif() +endmacro(ei_set_sitename) + +macro(ei_get_compilerver VAR) + if(MSVC) + # on windows system, we use a modified CMake script + include(CMakeDetermineVSServicePack) + DetermineVSServicePack( my_service_pack ) + + if( my_service_pack ) + set(${VAR} ${my_service_pack}) + else() + set(${VAR} "na") + endif() + else() + # on all other system we rely on ${CMAKE_CXX_COMPILER} + # supporting a "--version" flag + exec_program(${CMAKE_CXX_COMPILER} + ARGS --version + OUTPUT_VARIABLE eigen_cxx_compiler_version + ) + # here I try to extract the version string + # - TODO: this can most likely be improved and fixed + string(REGEX REPLACE ".* ([0-9])\\.([0-9])\\.([0-9]).*" "\\1.\\2.\\3" + eigen_cxx_compiler_version ${eigen_cxx_compiler_version}) + # again, here is room for improvement + # what if the compiler is not "g++" !? + set(${VAR} "g++${eigen_cxx_compiler_version}") + endif() +endmacro(ei_get_compilerver) + +macro(ei_get_cxxflags VAR) + set(${VAR} "") + ei_is_64bit_env(IS_64BIT_ENV) + if(EIGEN_TEST_NEON) + set(${VAR} NEON) + elseif(EIGEN_TEST_ALTIVEC) + set(${VAR} ALVEC) + elseif(EIGEN_TEST_SSE4_2) + set(${VAR} SSE42) + elseif(EIGEN_TEST_SSE4_1) + set(${VAR} SSE41) + elseif(EIGEN_TEST_SSSE3) + set(${VAR} SSSE3) + elseif(EIGEN_TEST_SSE3) + set(${VAR} SSE3) + elseif(EIGEN_TEST_SSE2 OR IS_64BIT_ENV) + set(${VAR} SSE2) + endif() + + if(EIGEN_TEST_OPENMP) + if (${VAR} STREQUAL "") + set(${VAR} OMP) + else() + set(${VAR} ${${VAR}}-OMP) + endif() + endif() + + if(EIGEN_DEFAULT_TO_ROW_MAJOR) + if (${VAR} STREQUAL "") + set(${VAR} ROW) + else() + set(${VAR} ${${VAR}}-ROWMAJ) + endif() + endif() +endmacro(ei_get_cxxflags) + +macro(ei_set_build_string) + ei_get_compilerver(LOCAL_COMPILER_VERSION) + ei_get_cxxflags(LOCAL_COMPILER_FLAGS) + + include(EigenDetermineOSVersion) + DetermineOSVersion(OS_VERSION) + + set(TMP_BUILD_STRING ${OS_VERSION}-${LOCAL_COMPILER_VERSION}) + + if (NOT ${LOCAL_COMPILER_FLAGS} STREQUAL "") + set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-${LOCAL_COMPILER_FLAGS}) + endif() + + ei_is_64bit_env(IS_64BIT_ENV) + if(NOT IS_64BIT_ENV) + set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-32bit) + else() + set(TMP_BUILD_STRING ${TMP_BUILD_STRING}-64bit) + endif() + + string(TOLOWER ${TMP_BUILD_STRING} BUILDNAME) +endmacro(ei_set_build_string) + +macro(ei_is_64bit_env VAR) + if(CMAKE_CL_64) + set(${VAR} 1) + elseif("$ENV{Platform}" STREQUAL "X64") # nmake 64 bit + set(${VAR} 1) + endif() +endmacro(ei_is_64bit_env) \ No newline at end of file