Implemented Compiler identification
This commit is contained in:
parent
a6183a9719
commit
635a8e8751
5 changed files with 156 additions and 30 deletions
|
@ -21,7 +21,7 @@ SET(CMAKE_D_COMPILER_ENV_VAR "DC")
|
|||
IF(CMAKE_COMPILER_IS_MINGW)
|
||||
SET(MINGW 1)
|
||||
ENDIF(CMAKE_COMPILER_IS_MINGW)
|
||||
SET(CMAKE_D_SOURCE_FILE_EXTENSIONS d)
|
||||
SET(CMAKE_D_SOURCE_FILE_EXTENSIONS d;di)
|
||||
SET(CMAKE_D_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC)
|
||||
# Prefer to use D's linker.
|
||||
# The D value 40 beats CXX value of 30 and C value of 10
|
||||
|
|
|
@ -1,36 +1,39 @@
|
|||
#if defined(__dmd__)
|
||||
# define COMPILER_ID "dmd"
|
||||
|
||||
#elif defined(__ldc__)
|
||||
# define COMPILER_ID "ldc"
|
||||
|
||||
#elif defined(__gdc__)
|
||||
# define COMPILER_ID "gdc"
|
||||
|
||||
#else /* unknown compiler */
|
||||
# define COMPILER_ID ""
|
||||
#endif
|
||||
version(DigitalMars)
|
||||
{
|
||||
const string COMPILER_ID = "DigitalMars";
|
||||
}
|
||||
else version(GNU)
|
||||
{
|
||||
const string COMPILER_ID = "GNU";
|
||||
}
|
||||
else version(LDC)
|
||||
{
|
||||
const string COMPILER_ID = "LDC";
|
||||
}
|
||||
else version(SDC)
|
||||
{
|
||||
const string COMPILER_ID = "SDC";
|
||||
}
|
||||
else
|
||||
{
|
||||
const string COMPILER_ID = "";
|
||||
}
|
||||
|
||||
/* Construct the string literal in pieces to prevent the source from
|
||||
getting matched. Store it in a pointer rather than an array
|
||||
because some compilers will just produce instructions to fill the
|
||||
array rather than assigning a pointer to a static array. */
|
||||
char* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]";
|
||||
string info_compiler = "INFO" ":" "compiler[" ~ COMPILER_ID ~ "]";
|
||||
|
||||
@CMAKE_D_COMPILER_ID_PLATFORM_CONTENT@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef ID_VOID_MAIN
|
||||
void main() {}
|
||||
#else
|
||||
int main(int argc, char* argv[])
|
||||
int main(string[] args)
|
||||
{
|
||||
int require = 0;
|
||||
require += info_compiler[argc];
|
||||
require += info_platform[argc];
|
||||
require += info_arch[argc];
|
||||
(void)argv;
|
||||
return require;
|
||||
int require = 0;
|
||||
require += info_compiler[args.length];
|
||||
require += info_platform[args.length];
|
||||
require += info_arch[args.length];
|
||||
return require;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -111,8 +111,9 @@ IF(NOT CMAKE_D_COMPILER_ID_RUN)
|
|||
|
||||
# Try to identify the compiler.
|
||||
SET(CMAKE_D_COMPILER_ID)
|
||||
FILE(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in
|
||||
CMAKE_D_COMPILER_ID_PLATFORM_CONTENT)
|
||||
FIND_FILE(CMAKE_PLATFORM_ID_CONTENT_FILE CMakePlatformId.di.in
|
||||
PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH})
|
||||
FILE(READ ${CMAKE_PLATFORM_ID_CONTENT_FILE} CMAKE_D_COMPILER_ID_PLATFORM_CONTENT)
|
||||
INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ID(D DFLAGS CMakeDCompilerId.d)
|
||||
|
||||
|
@ -136,8 +137,10 @@ IF(MSVC_D_ARCHITECTURE_ID)
|
|||
"SET(MSVC_D_ARCHITECTURE_ID ${MSVC_D_ARCHITECTURE_ID})")
|
||||
ENDIF(MSVC_D_ARCHITECTURE_ID)
|
||||
# configure variables set in this file for fast reload later on
|
||||
CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeDCompiler.cmake.in
|
||||
"${CMAKE_PLATFORM_INFO_DIR}/CMakeDCompiler.cmake"
|
||||
FIND_FILE(CMAKE_D_COMPILER_CMAKE_IN CMakeDCompiler.cmake.in
|
||||
PATHS ${CMAKE_ROOT} ${CMAKE_MODULE_PATH})
|
||||
CONFIGURE_FILE(${CMAKE_D_COMPILER_CMAKE_IN}
|
||||
${CMAKE_PLATFORM_INFO_DIR}/CMakeDCompiler.cmake
|
||||
@ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
|
||||
)
|
||||
SET(CMAKE_D_COMPILER_ENV_VAR "DC")
|
||||
|
|
118
cmaked/CMakePlatformId.di.in
Normal file
118
cmaked/CMakePlatformId.di.in
Normal file
|
@ -0,0 +1,118 @@
|
|||
/* Identify known platforms by name. */
|
||||
version(linux)
|
||||
{
|
||||
const string PLATFORM_ID = "Linux";
|
||||
}
|
||||
else version(Cygwin)
|
||||
{
|
||||
const string PLATFORM_ID = "Cygwin";
|
||||
}
|
||||
else version(MinGW)
|
||||
{
|
||||
const string PLATFORM_ID = "MinGW";
|
||||
}
|
||||
else version(OSX)
|
||||
{
|
||||
const string PLATFORM_ID = "Darwin";
|
||||
}
|
||||
else version(Windows)
|
||||
{
|
||||
const string PLATFORM_ID = "Windows";
|
||||
}
|
||||
else version(FreeBSD)
|
||||
{
|
||||
const string PLATFORM_ID = "FreeBSD";
|
||||
}
|
||||
else version(NetBSD)
|
||||
{
|
||||
const string PLATFORM_ID = "NetBSD";
|
||||
}
|
||||
else version(OpenBSD)
|
||||
{
|
||||
const string PLATFORM_ID = "OpenBSD";
|
||||
}
|
||||
else version(NetBSD)
|
||||
{
|
||||
const string PLATFORM_ID = "NetBSD";
|
||||
}
|
||||
else version(Solaris)
|
||||
{
|
||||
const string PLATFORM_ID = "SunOS";
|
||||
}
|
||||
else version(AIX)
|
||||
{
|
||||
const string PLATFORM_ID = "AIX";
|
||||
}
|
||||
else version(Haiku)
|
||||
{
|
||||
const string PLATFORM_ID = "Haiku";
|
||||
}
|
||||
else version(AIX)
|
||||
{
|
||||
const string PLATFORM_ID = "BeOS";
|
||||
}
|
||||
else version(AIX)
|
||||
{
|
||||
const string PLATFORM_ID = "QNX";
|
||||
}
|
||||
else version(AIX)
|
||||
{
|
||||
const string PLATFORM_ID = "Tru64";
|
||||
}
|
||||
else version(AIX)
|
||||
{
|
||||
const string PLATFORM_ID = "RISCos";
|
||||
}
|
||||
else
|
||||
{
|
||||
const string PLATFORM_ID = "";
|
||||
}
|
||||
|
||||
/* For windows compilers MSVC and Intel we can determine
|
||||
the architecture of the compiler being used. This is because
|
||||
the compilers do not have flags that can change the architecture,
|
||||
but rather depend on which compiler is being used
|
||||
*/
|
||||
version(IA64)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "IA64";
|
||||
}
|
||||
else version(X86_64)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "x64";
|
||||
}
|
||||
else version(X86)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "X86";
|
||||
}
|
||||
else version(ARM)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "ARM";
|
||||
}
|
||||
else version(MIPS32)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "MIPS";
|
||||
}
|
||||
else version(MIPS64)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "MIPS";
|
||||
}
|
||||
else version(SH)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "SHx";
|
||||
}
|
||||
else version(SH64)
|
||||
{
|
||||
const string ARCHITECTURE_ID = "SHx";
|
||||
}
|
||||
else
|
||||
{
|
||||
const string ARCHITECTURE_ID = "";
|
||||
}
|
||||
|
||||
/* Construct the string literal in pieces to prevent the source from
|
||||
getting matched. Store it in a pointer rather than an array
|
||||
because some compilers will just produce instructions to fill the
|
||||
array rather than assigning a pointer to a static array. */
|
||||
string info_platform = "INFO" ":" "platform[" ~ PLATFORM_ID ~ "]";
|
||||
string info_arch = "INFO" ":" "arch[" ~ ARCHITECTURE_ID ~"]";
|
|
@ -60,7 +60,9 @@ ELSE(NOT CMAKE_D_COMPILER_WORKS)
|
|||
ELSE(CMAKE_D_COMPILER_FORCED)
|
||||
# Try to identify the ABI and configure it into CMakeDCompiler.cmake
|
||||
INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
|
||||
CMAKE_DETERMINE_COMPILER_ABI(D ${CMAKE_ROOT}/Modules/CMakeDCompilerABI.d)
|
||||
FIND_FILE(CMAKE_D_COMPLER_ABI_SRC CMakeDCompilerABI.d
|
||||
PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH})
|
||||
CMAKE_DETERMINE_COMPILER_ABI(D ${CMAKE_D_COMPLER_ABI_SRC})
|
||||
CONFIGURE_FILE(
|
||||
${CMAKE_ROOT}/Modules/CMakeDCompiler.cmake.in
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeDCompiler.cmake
|
||||
|
|
Loading…
Add table
Reference in a new issue