123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382 |
- # This file is included from the def.cmake CMakeLists.txt file.
- # It sets up the compiler specific flags.
- # Define the common flags and options for GCC
- option(PROFILE "Enable profiling" OFF)
- add_library(common_compiler_flags INTERFACE)
- function(set_if_empty var value)
- if(DEFINED ENV{${var}} AND NOT "$ENV{${var}}" STREQUAL "")
- set(${var}
- ${value}
- PARENT_SCOPE
- )
- set(${var} "$ENV{${var}}")
- else()
- set(${var}
- ${value}
- PARENT_SCOPE
- )
- endif()
- endfunction()
- # Define the flags for the C compiler
- if(TARGET_ARCH MATCHES "x86_64")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops -Wcast-align)
- # If GCC version is greater than 4.2, enable the following flags
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- set_if_empty(CPUTYPE "generic")
- target_compile_options(
- common_compiler_flags INTERFACE -m64 -minline-all-stringops -falign-loops -ftree-vectorize
- -fno-strict-overflow -mtune=${CPUTYPE}
- )
- target_link_options(common_compiler_flags INTERFACE -m64)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- set_if_empty(CPUTYPE "athlon64")
- target_compile_options(
- common_compiler_flags INTERFACE -m64 -minline-all-stringops -falign-loops -ftree-vectorize
- -mtune=${CPUTYPE}
- )
- target_link_options(common_compiler_flags INTERFACE -m64)
- else()
- message(
- WARNING
- "You are using an old and unsupported gcc version ${CMAKE_C_COMPILER_VERSION}, compile at your own risk!"
- )
- endif()
- elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
- set_if_empty(CPUTYPE "opteron")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -m64)
- target_link_options(common_compiler_flags INTERFACE -m64)
- elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -O3 -ipo -ipo_obj -unroll -tpp6 -xK)
- else()
- message(
- WARNING
- "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for x86_64. Try GCC, Clang, or ICC. Compile at your own risk!"
- )
- endif()
- elseif(TARGET_ARCH MATCHES "i386")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -Wall -funroll-loops -Wcast-align)
- # If GCC version is greater than 4.2.0, enable the following flags
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- set_if_empty(CPUTYPE "generic")
- target_compile_options(
- common_compiler_flags INTERFACE -m32 -minline-all-stringops -falign-loops -ftree-vectorize
- -fno-strict-overflow -mtune=${CPUTYPE}
- )
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- set_if_empty(CPUTYPE "athlon64")
- target_compile_options(
- common_compiler_flags INTERFACE -m32 -minline-all-stringops -falign-loops -ftree-vectorize
- -mtune=${CPUTYPE}
- )
- else()
- message(
- WARNING
- "You are using an old and unsupported gcc version ${CMAKE_C_COMPILER_VERSION}, compile at your own risk!"
- )
- endif()
- elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
- set_if_empty(CPUTYPE "athlon64")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -m32 -mtune=${CPUTYPE})
- target_link_options(common_compiler_flags INTERFACE -m32)
- elseif(CMAKE_C_COMPILER_ID STREQUAL "Intel")
- # ICC- Intel classic specific flags
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -O3 -ipo -ipo_obj -unroll -tpp6 -xK)
- else()
- message(
- WARNING "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for i386. Try GCC, Clang, or ICC."
- )
- endif()
- elseif(TARGET_ARCH MATCHES "aarch64")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- # target_compile_options(common INTERFACE -O0 # <$<$<BOOL:${PROFILE}>:-pg> )
- # target_compile_options( common INTERFACE -marm -march=armv5t
- # -funroll-loops -fsigned-char )
- # # If GCC version is greater than 4.2.0, enable the following flags
- # if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0) target_compile_options(
- # common INTERFACE -ftree-vectorize -fno-strict-overflow ) endif()
- endif()
- elseif(TARGET_ARCH MATCHES "ppc64$")
- # PowerPC 64-bit specific flags
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops -fsigned-char)
- # Try to get CPUTYPE from the environment, fallback to "powerpc64" if not set
- if(DEFINED ENV{CPUTYPE} AND NOT "$ENV{CPUTYPE}" STREQUAL "")
- set(CPUTYPE "$ENV{CPUTYPE}")
- else()
- set(CPUTYPE "powerpc64")
- endif()
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
- target_compile_options(
- common_compiler_flags INTERFACE -ftree-vectorize -fno-strict-overflow -mtune=${CPUTYPE}
- -maltivec
- )
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.0)
- target_compile_options(
- common_compiler_flags INTERFACE -ftree-vectorize -mtune=${CPUTYPE} -maltivec
- )
- elseif(CMAKE_C_COMPILER_VERSION VERSION_LESS 3.0)
- message(
- WARNING
- "GCC version ${CMAKE_C_COMPILER_VERSION} is too old for ppc64. Try GCC 3.0 or newer."
- )
- endif()
- # else()
- # message(FATAL_ERROR "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for ppc64. Try GCC.")
- endif()
- elseif(TARGET_ARCH STREQUAL "ppc")
- # PowerPC 32-bit specific flags
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.2)
- set_if_empty(CPUTYPE "powerpc")
- target_compile_options(
- common_compiler_flags INTERFACE -funroll-loops -fsigned-char -ftree-vectorize -maltivec
- -fno-strict-overflow -mtune=${CPUTYPE}
- )
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 4.0)
- set_if_empty(CPUTYPE "powerpc")
- target_compile_options(
- common_compiler_flags INTERFACE -funroll-loops -fsigned-char -ftree-vectorize -maltivec
- -mtune=${CPUTYPE}
- )
- else()
- message(
- WARNING "GCC version ${CMAKE_C_COMPILER_VERSION} is too old for ppc. Try GCC 4.0 or newer."
- )
- endif()
- else()
- message(
- WARNING
- "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for ${TARGET_ARCH}. Try GCC. Compile at your own risk!"
- )
- endif()
- elseif(TARGET_ARCH STREQUAL "arm7")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- # ARM specific flags
- target_compile_options(
- common_compiler_flags INTERFACE -march=armv7-a -funroll-loops -fsigned-char
- )
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize -fno-strict-overflow)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize)
- else()
- message(
- WARNING "GCC version ${CMAKE_C_COMPILER_VERSION} is too old for arm7. Try GCC 4.0 or newer."
- )
- endif()
- else()
- message(FATAL_ERROR "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for arm7. Try GCC.")
- endif()
- elseif(TARGET_ARCH STREQUAL "arm6")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(
- common_compiler_flags INTERFACE -march=armv6 -funroll-loops -fsigned-char
- )
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize -fno-strict-overflow)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize)
- else()
- message(
- WARNING "GCC version ${CMAKE_C_COMPILER_VERSION} is too old for arm6. Try GCC 4.0 or newer."
- )
- endif()
- else()
- message(WARNING "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for arm6. Try GCC.")
- endif()
- elseif(TARGET_ARCH STREQUAL "arm")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- # ARM specific flags
- target_compile_options(
- common_compiler_flags INTERFACE -marm -march=armv5t -funroll-loops -fsigned-char
- )
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize -fno-strict-overflow)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize)
- else()
- message(
- WARNING "GCC version ${CMAKE_C_COMPILER_VERSION} is too old for arm. Try GCC 4.0 or newer."
- )
- endif()
- else()
- message(FATAL_ERROR "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for arm. Try GCC.")
- endif()
- elseif(TARGET_ARCH STREQUAL "sparc64")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM SPARC64_MODE)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops)
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- set_if_empty(CPUTYPE "ultrasparc")
- target_compile_options(
- common_compiler_flags INTERFACE -m64 -mcpu=ultrasparc -mtune=${CPUTYPE}
- -fno-strict-overflow -ftree-vectorize
- )
- target_link_options(common_compiler_flags INTERFACE -m64)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- set_if_empty(CPUTYPE "ultrasparc")
- target_compile_options(
- common_compiler_flags INTERFACE -m64 -mcpu=ultrasparc -mtune=${CPUTYPE} -ftree-vectorize
- )
- endif()
- # The following CMAKE_C_COMPILER_ID is not available per cmake docs
- # TODO: Use some other variable to check like CC
- elseif(CMAKE_C_COMPILER_ID STREQUAL "Sun")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM SPARC64_MODE)
- target_compile_options(
- common_compiler_flags
- INTERFACE -m64
- -xO3
- -xtarget=native
- -xmemalign=8i
- -fma=fused
- -fns=yes
- -xc99
- )
- else()
- message(
- FATAL_ERROR "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for sparc64. Try GCC or Sun."
- )
- endif()
- elseif(TARGET_ARCH STREQUAL "sparc")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops)
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- set_if_empty(CPUTYPE "v8")
- target_compile_options(
- common_compiler_flags INTERFACE -mtune=${CPUTYPE} -fno-strict-overflow -ftree-vectorize
- )
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- set_if_empty(CPUTYPE "v8")
- target_compile_options(common_compiler_flags INTERFACE -mtune=${CPUTYPE} -ftree-vectorize)
- endif()
- # The following CMAKE_C_COMPILER_ID is not available per cmake docs
- # TODO: Use some other variable to check like CC
- elseif(CMAKE_C_COMPILER_ID STREQUAL "Sun")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(
- common_compiler_flags INTERFACE -xO3 -xtarget=native -xmemalign=4i -fma=fused -fns=yes -xc99
- )
- else()
- message(FATAL_ERROR "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for sparc. Try GCC or Sun.")
- endif()
- elseif(TARGET_ARCH STREQUAL "mips")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops)
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- target_compile_options(
- common_compiler_flags INTERFACE -mfp32 -march=r3000 -ftree-vectorize -fno-strict-overflow
- )
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- target_compile_options(common_compiler_flags INTERFACE -march=r3000 -ftree-vectorize)
- else()
- message(
- WARNING "GCC version ${CMAKE_C_COMPILER_VERSION} is too old for mips. Try GCC 4.0 or newer."
- )
- endif()
- else()
- message(WARNING "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for mips. Try GCC.")
- endif()
- elseif(TARGET_ARCH STREQUAL "mips2")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops)
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize -fno-strict-overflow)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_LESS 3.0)
- message(
- WARNING
- "You are using an old and unsupported gcc version ${CMAKE_C_COMPILER_VERSION}, compile at your own risk!"
- )
- endif()
- else()
- message(
- WARNING
- "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for ${TARGET_ARCH}. Try GCC. Compile at your own risk!"
- )
- endif()
- elseif(TARGET_ARCH STREQUAL "mips64")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops)
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize -fno-strict-overflow)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.0)
- target_compile_options(common_compiler_flags INTERFACE -ftree-vectorize)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_LESS 3.0)
- message(
- WARNING
- "You are using an old and unsupported gcc version ${CMAKE_C_COMPILER_VERSION}, compile at your own risk!"
- )
- endif()
- else()
- message(
- WARNING
- "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for ${TARGET_ARCH}. Try GCC. Compile at your own risk!"
- )
- endif()
- elseif(TARGET_ARCH STREQUAL "alpha")
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
- target_compile_definitions(common_compiler_flags INTERFACE CC_GCC_LIKE_ASM)
- target_compile_options(common_compiler_flags INTERFACE -funroll-loops)
- if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.2)
- target_compile_options(common_compiler_flags INTERFACE -fno-strict-overflow)
- elseif(CMAKE_C_COMPILER_VERSION VERSION_LESS 3.0)
- message(
- WARNING
- "You are using an old and unsupported gcc version ${CMAKE_C_COMPILER_VERSION}, compile at your own risk!"
- )
- endif()
- else()
- message(
- WARNING
- "Unsupported compiler (${CMAKE_C_COMPILER_ID}) for ${TARGET_ARCH}. Try GCC. Compile at your own risk!"
- )
- endif()
- else()
- message(
- WARNING
- "Architecture ${TARGET_ARCH} not directly supported by project. Proceeding with generic flags. \
- Define any compile options you might need with env variables like CFLAGS."
- )
- endif()
|