From 68e423e996442c316fa2828a5be8c0e2ee8b1e5b Mon Sep 17 00:00:00 2001 From: Mikko Rapeli Date: Fri, 21 Dec 2012 09:44:36 +0100 Subject: [PATCH cmake] ARM compiler (RVDS) support From: Abdelrazak Younes http://public.kitware.com/Bug/file_download.php?file_id=4190&type=bug CMakeFindBinUtils.cmake part from Eric F. http://public.kitware.com/Bug/view.php?id=12614#c31625 Some cleanup by Mikko Rapeli: * removed from CMAKE_C_LINK_EXECUTABLE since linker does not understand compiler flags * allow C/CXX_FLAGS to be overridden via toolchain file * removed hardcoded ASM compiler flags * added mark_as_advanced(CMAKE_LINKER) to FindBinUtils * added CMAKE_C/CXX_CREATE_ASSEMBLY_SOURCE and CMAKE_C/CXX_CREATE_PREPROCESSED_SOURCE Tested on Windows 7 with cmake 2.8.10.1, ARM RVDS compiler 4.1 and following test project: $ cat main.c int main(void) { return 0; } $ cat CMakeLists.txt cmake_minimum_required (VERSION 2.8) project (main) add_library(main STATIC main.c) $ cat toolchain-arm.cmake SET(CMAKE_SYSTEM_NAME Generic) SET(CMAKE_SYSTEM_VERSION 1) SET(CMAKE_C_COMPILER armcc) SET(CMAKE_CXX_COMPILER armcc) SET(CMAKE_FIND_ROOT_PATH ../../ ) SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) SET(ARCH "--cpu=Cortex-A9 --fpmode=fast") SET(CMAKE_C_FLAGS_INIT "${ARCH} --pending_instantiations=0 --diag_style=gnu --diag_suppress=2523 --diag_suppress=1300 -O2 --debug --no_exceptions") SET(CMAKE_CXX_FLAGS_INIT "${CMAKE_C_FLAGS} --cpp") ADD_DEFINITIONS(-DNDEBUG) INCLUDE_DIRECTORIES(".") $ mkdir build-arm && cd build-arm $ cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=../toolchain-arm.cmake .. -- The C compiler identification is RVDS -- The CXX compiler identification is RVDS -- Check for working C compiler: armcc -- Check for working C compiler: armcc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working CXX compiler: armcc -- Check for working CXX compiler: armcc -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Configuring done -- Generating done -- Build files have been written to: C:/src/cmake/build-arm $ make Scanning dependencies of target main [100%] Building C object CMakeFiles/main.dir/main.c.obj Warning: C9931W: Your license for Compiler (feature compiler_pro) will expire in 28 days Warning: C9931W: Your license for Compiler (feature compiler_pro) will expire in 28 days Linking C static library libmain.a Creating archive 'libmain.a' [100%] Built target main Fixes bug: http://public.kitware.com/Bug/view.php?id=12614 --- Modules/CMakeASM-RVDSInformation.cmake | 10 +++++++ Modules/CMakeCCompilerId.c.in | 3 ++ Modules/CMakeCXXCompilerId.cpp.in | 3 ++ Modules/CMakeDetermineASM-RVDSCompiler.cmake | 4 +++ Modules/CMakeFindBinUtils.cmake | 7 +++++ Modules/CMakeTestASM-RVDSCompiler.cmake | 3 ++ Modules/Compiler/RVDS-C.cmake | 35 ++++++++++++++++++++++++++ Modules/Compiler/RVDS-CXX.cmake | 35 ++++++++++++++++++++++++++ 8 files changed, 100 insertions(+), 0 deletions(-) create mode 100644 Modules/CMakeASM-RVDSInformation.cmake create mode 100644 Modules/CMakeDetermineASM-RVDSCompiler.cmake create mode 100644 Modules/CMakeTestASM-RVDSCompiler.cmake create mode 100644 Modules/Compiler/RVDS-C.cmake create mode 100644 Modules/Compiler/RVDS-CXX.cmake diff --git a/Modules/CMakeASM-RVDSInformation.cmake b/Modules/CMakeASM-RVDSInformation.cmake new file mode 100644 index 0000000..4c23da5 --- /dev/null +++ b/Modules/CMakeASM-RVDSInformation.cmake @@ -0,0 +1,10 @@ + +SET(ASM_DIALECT "-RVDS") +# *.S files are supposed to be preprocessed, so they should not be passed to +# assembler but should be processed by gcc +SET(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS s;asm) + +SET(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT " -o ") + +INCLUDE(CMakeASMInformation) +SET(ASM_DIALECT) diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index 2d76c7a..0cb92dd 100644 --- a/Modules/CMakeCCompilerId.c.in +++ b/Modules/CMakeCCompilerId.c.in @@ -197,6 +197,9 @@ #elif defined(__hpux) || defined(__hpua) # define COMPILER_ID "HP" +#elif defined(__ARMCC_VERSION) +# define COMPILER_ID "RVDS" + #else /* unknown compiler */ # define COMPILER_ID "" diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in index 5e70a41..ef4f55b 100644 --- a/Modules/CMakeCXXCompilerId.cpp.in +++ b/Modules/CMakeCXXCompilerId.cpp.in @@ -184,6 +184,9 @@ #elif defined(__hpux) || defined(__hpua) # define COMPILER_ID "HP" +#elif defined(__ARMCC_VERSION) +# define COMPILER_ID "RVDS" + #else /* unknown compiler */ # define COMPILER_ID "" diff --git a/Modules/CMakeDetermineASM-RVDSCompiler.cmake b/Modules/CMakeDetermineASM-RVDSCompiler.cmake new file mode 100644 index 0000000..2c942f9 --- /dev/null +++ b/Modules/CMakeDetermineASM-RVDSCompiler.cmake @@ -0,0 +1,4 @@ +SET(ASM_DIALECT "-RVDS") +SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT armasm) +INCLUDE(CMakeDetermineASMCompiler) +SET(ASM_DIALECT) diff --git a/Modules/CMakeFindBinUtils.cmake b/Modules/CMakeFindBinUtils.cmake index e08c1c6..b97c2d5 100644 --- a/Modules/CMakeFindBinUtils.cmake +++ b/Modules/CMakeFindBinUtils.cmake @@ -38,6 +38,13 @@ if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC" mark_as_advanced(CMAKE_LINKER) +elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "RVDS" + OR "${CMAKE_C_COMPILER_ID}" MATCHES "RVDS") + + find_program(CMAKE_LINKER NAMES armar HINTS ${_CMAKE_TOOLCHAIN_LOCATION}) + + mark_as_advanced(CMAKE_LINKER) + # in all other cases search for ar, ranlib, etc. else() diff --git a/Modules/CMakeTestASM-RVDSCompiler.cmake b/Modules/CMakeTestASM-RVDSCompiler.cmake new file mode 100644 index 0000000..45bf7ca --- /dev/null +++ b/Modules/CMakeTestASM-RVDSCompiler.cmake @@ -0,0 +1,3 @@ +SET(ASM_DIALECT "-RVDS") +INCLUDE(CMakeTestASMCompiler) +SET(ASM_DIALECT) diff --git a/Modules/Compiler/RVDS-C.cmake b/Modules/Compiler/RVDS-C.cmake new file mode 100644 index 0000000..4542d6f --- /dev/null +++ b/Modules/Compiler/RVDS-C.cmake @@ -0,0 +1,35 @@ +SET(CMAKE_C_COMPILER "armcc") +SET(CMAKE_AR "armar") +SET(CMAKE_LINKER "armlink") +SET(CMAKE_C_CREATE_ASSEMBLY_SOURCE " -S -o ") +SET(CMAKE_C_CREATE_PREPROCESSED_SOURCE " -E > ") + +# Allow toolchain files to override these +if(NOT DEFINED CMAKE_C_FLAGS_INIT) + SET(CMAKE_C_FLAGS_INIT "") +endif() + +if(NOT DEFINED CMAKE_C_FLAGS_DEBUG_INIT) + SET(CMAKE_C_FLAGS_DEBUG_INIT "-g") +endif() + +if(NOT DEFINED CMAKE_C_FLAGS_MINSIZEREL_INIT) + SET(CMAKE_C_FLAGS_MINSIZEREL_INIT "-Ospace -DNDEBUG") +endif() + +if(NOT DEFINED CMAKE_C_FLAGS_RELEASE_INIT) + SET(CMAKE_C_FLAGS_RELEASE_INIT "-Otime -DNDEBUG") +endif() + +if(NOT DEFINED CMAKE_C_FLAGS_RELWITHDEBINFO_INIT) + SET(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "-O2 -g") +endif() + +if(NOT DEFINED CMAKE_C_CREATE_STATIC_LIBRARY) + SET(CMAKE_C_CREATE_STATIC_LIBRARY " -r ") +endif() + +if(NOT DEFINED CMAKE_C_LINK_EXECUTABLE) + SET(CMAKE_C_LINK_EXECUTABLE " -o ") +endif() + diff --git a/Modules/Compiler/RVDS-CXX.cmake b/Modules/Compiler/RVDS-CXX.cmake new file mode 100644 index 0000000..33a8c69 --- /dev/null +++ b/Modules/Compiler/RVDS-CXX.cmake @@ -0,0 +1,35 @@ +SET(CMAKE_CXX_COMPILER "armcc") +SET(CMAKE_AR "armar") +SET(CMAKE_LINKER "armlink") +SET(CMAKE_CXX_CREATE_ASSEMBLY_SOURCE " -S -o ") +SET(CMAKE_CXX_CREATE_PREPROCESSED_SOURCE " -E > ") + +# Allow toolchain files to override these +if(NOT DEFINED CMAKE_CXX_FLAGS_INIT) + SET(CMAKE_CXX_FLAGS_INIT "") +endif() + +if(NOT DEFINED CMAKE_CXX_FLAGS_DEBUG_INIT) + SET(CMAKE_CXX_FLAGS_DEBUG_INIT "-g") +endif() + +if(NOT DEFINED CMAKE_CXX_FLAGS_MINSIZEREL_INIT) + SET(CMAKE_CXX_FLAGS_MINSIZEREL_INIT "-Ospace -DNDEBUG") +endif() + +if(NOT DEFINED CMAKE_CXX_FLAGS_RELEASE_INIT) + SET(CMAKE_CXX_FLAGS_RELEASE_INIT "-Otime -DNDEBUG") +endif() + +if(NOT DEFINED CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT) + SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT "-O2 -g") +endif() + +if(NOT DEFINED CMAKE_CXX_CREATE_STATIC_LIBRARY) + SET(CMAKE_CXX_CREATE_STATIC_LIBRARY " -r ") +endif() + +if(NOT DEFINED CMAKE_CXX_LINK_EXECUTABLE) + SET(CMAKE_CXX_LINK_EXECUTABLE " -o ") +endif() + -- 1.7.9