Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMakeLists.txt BENCHMARK_BUILD_32_BITS fails with MSVC #447

Closed
ghost opened this issue Sep 16, 2017 · 1 comment
Closed

CMakeLists.txt BENCHMARK_BUILD_32_BITS fails with MSVC #447

ghost opened this issue Sep 16, 2017 · 1 comment

Comments

@ghost
Copy link

ghost commented Sep 16, 2017

CMakeLists.txt has an option BENCHMARK_BUILD_32_BITS. This works when gcc is used, but it fails with MSVC. In fact this option tries to add -m32 to the compiler options, and this is gcc-specific and doesn't work with MSVC.

With MSVC this option doesn't really make sense, because the CMake MSVC generator determines whether the build is 32-bit or 64-bit. An MSVC user probably doesn't want or expect that setting BENCHMARK_BUILD_32_BITS would make the build fail. Therefore, I propose that BENCHMARK_BUILD_32_BITS be ignored when using MSVC. Doing this is a trivial change to CMakeLists.txt, moving the -m32 stuff so that it is not used with MSVC.

Here's a diff:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4265a6c..74fe2ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,10 +37,6 @@ include(CheckCXXCompilerFlag)
include(AddCXXCompilerFlag)
include(CXXFeatureCheck)

-if (BENCHMARK_BUILD_32_BITS)

  • add_required_cxx_compiler_flag(-m32)
    -endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")

Turn compiler warnings up to 11

string(REGEX REPLACE "[-/]W[1-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
@@ -72,6 +68,10 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /LTCG")
endif()
else()

  • if (BENCHMARK_BUILD_32_BITS)
  • add_required_cxx_compiler_flag(-m32)
  • endif()
  • Try and enable C++11. Don't use C++14 because it doesn't work in some

    configurations.

    add_cxx_compiler_flag(-std=c++11)
@dmah42
Copy link
Member

dmah42 commented Sep 21, 2017

sgtm. PR welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant