aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2021-03-14 14:54:09 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2021-03-14 15:57:05 +0300
commitc1611949e1a8544224582fe18955739c63028db0 (patch)
tree7a9981bef494c41fcbb9882c75615b70aee97d95
parentproject.boost.download: create missing directories (diff)
downloadcmake-common-c1611949e1a8544224582fe18955739c63028db0.tar.gz
cmake-common-c1611949e1a8544224582fe18955739c63028db0.zip
project.cmake.toolchain: allow omitting --platform
When --platform is omitted, no -m32/-m64 flags will be added.
-rw-r--r--project/cmake/toolchain.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/project/cmake/toolchain.py b/project/cmake/toolchain.py
index 32831b2..c2e54a6 100644
--- a/project/cmake/toolchain.py
+++ b/project/cmake/toolchain.py
@@ -123,6 +123,7 @@ import shutil
import project.mingw
from project.os import on_windows
+from project.platform import Platform
from project.toolchain import ToolchainType
@@ -179,6 +180,8 @@ class MSVC(Auto):
self.platform = platform
def get_cmake_args(self):
+ if self.platform is None:
+ return []
# This doesn't actually specify the generator of course, but I don't
# want to implement VS detection logic.
return ['-A', self.platform.get_cmake_arch()]
@@ -211,6 +214,17 @@ class Makefile(Toolchain):
file.write(contents)
return cls(path)
+ @staticmethod
+ def _format_platform_compiler_flags(platform):
+ if platform is None:
+ # If the platform wasn't specified, don't use the -m flag, etc.
+ return ''
+ # Otherwise, use the standard -m32/-m64 flags.
+ return f'''
+set(CMAKE_C_FLAGS -m{platform.get_address_model()})
+set(CMAKE_CXX_FLAGS -m{platform.get_address_model()})
+'''
+
def get_cmake_args(self):
return [
'-D', f'CMAKE_TOOLCHAIN_FILE={self.path}',
@@ -228,10 +242,8 @@ class GCC(Makefile):
def _format(platform):
return f'''
set(CMAKE_C_COMPILER gcc)
-set(CMAKE_C_FLAGS -m{platform.get_address_model()})
set(CMAKE_CXX_COMPILER g++)
-set(CMAKE_CXX_FLAGS -m{platform.get_address_model()})
-'''
+{Makefile._format_platform_compiler_flags(platform)}'''
@staticmethod
def setup(platform, build_dir):
@@ -241,6 +253,10 @@ set(CMAKE_CXX_FLAGS -m{platform.get_address_model()})
class MinGW(Makefile):
@staticmethod
def _format(platform):
+ if platform is None:
+ # MinGW only supports x86/x64, plus we need the platform for the
+ # compiler file name, so default to x64 unless specified.
+ platform = Platform.X64
return f'''
set(CMAKE_C_COMPILER {project.mingw.get_gcc(platform)})
set(CMAKE_CXX_COMPILER {project.mingw.get_gxx(platform)})
@@ -262,15 +278,11 @@ class Clang(Makefile):
if(CMAKE_VERSION VERSION_LESS "3.15" AND WIN32)
set(CMAKE_C_COMPILER clang-cl)
set(CMAKE_CXX_COMPILER clang-cl)
- set(CMAKE_C_FLAGS -m{platform.get_address_model()})
- set(CMAKE_CXX_FLAGS -m{platform.get_address_model()})
else()
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)
- set(CMAKE_C_FLAGS -m{platform.get_address_model()})
- set(CMAKE_CXX_FLAGS -m{platform.get_address_model()})
endif()
-'''
+{Makefile._format_platform_compiler_flags(platform)}'''
def _get_makefile_generator(self):
if on_windows():
@@ -291,10 +303,8 @@ class ClangCL(Clang):
return f'''
set(CMAKE_C_COMPILER clang-cl)
set(CMAKE_CXX_COMPILER clang-cl)
-set(CMAKE_C_FLAGS -m{platform.get_address_model()})
-set(CMAKE_CXX_FLAGS -m{platform.get_address_model()})
set(CMAKE_SYSTEM_NAME Windows)
-'''
+{Makefile._format_platform_compiler_flags(platform)}'''
@staticmethod
def setup(platform, build_dir):