[zlib] Enable ASM optimizations on i386 and amd64.
authorDavid Korth <gerbilsoft@gerbilsoft.com>
Wed, 2 Sep 2015 04:52:21 +0000 (00:52 -0400)
committerDavid Korth <gerbilsoft@gerbilsoft.com>
Wed, 2 Sep 2015 04:52:21 +0000 (00:52 -0400)
set_source_files_properties(): Set COMPILE_FLAGS to "". Leaving out the
flags parameter entirely caused a CMake error:

CMake Error at extlib/zlib/CMakeLists.txt:152 (set_source_files_properties):
  set_source_files_properties called with incorrect number of arguments.

MSVC assembler: Explicilty set the language of the asm files as ASM_MASM.
For some reason, CMake is assuming that all .asm files are ASM_NASM,
which prevented these files from being assembled correctly.

extlib/CMakeLists.txt
extlib/zlib/CMakeLists.txt

index fd03010..19eba68 100644 (file)
@@ -5,18 +5,27 @@ cmake_minimum_required(VERSION 2.6.0)
 
 # Assembly optimizations.
 # TODO: Test on all archs and fix Z_PREFIX issues.
-# FIXME: Building 32-bit on 64-bit Linux results in CMAKE_SYSTEM_PROCESSOR == x86_64.
+# TODO: Add more assembly files from contrib/ besides the
+# default ones that were listed in zlib's CMakeLists.txt.
 # TODO: If MASM, only enable on cmake-2.6.3+
-# TODO: Can't use MASM because of conflicts with NASM in cmake.
 # TODO: If nasm/yasm, only enable on cmake-2.8.4+
-# TODO: Symbol redefinitions.
-IF(0)
-IF(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.|x)86\$")
-       SET(ASM686 "ON")
-ELSEIF(CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64\$")
-       SET(AMD64 "ON")
-ENDIF()
-ENDIF()
+# cmake_minimum_required() statements have been added to zlib's
+# CMakeLists.txt to prevent errors, but ideally, we should be
+# able to simply disable asm on older versions.
+STRING(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" arch)
+IF(arch MATCHES "^(i.|x)86$|^x86_64$|^amd64$")
+       # i386/amd64. Check sizeof(void*) for the actual architecture,
+       # since building 32-bit on 64-bit isn't considered "cross-compiling",
+       # so CMAKE_SYSTEM_PROCESSOR might not be accurate.
+       # NOTE: CMake sometimes leaves this blank for MSVC builds,
+       # so check for 64-bit first so we can default to 32-bit.
+       IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
+               SET(AMD64 "ON")
+       ELSE()
+               SET(ASM686 "ON")
+       ENDIF()
+ENDIF(arch MATCHES "^(i.|x)86$|^x86_64$|^amd64$")
+UNSET(arch)
 
 # Don't install any of these libraries.
 SET(OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
index 6e23116..ceca1c6 100644 (file)
@@ -136,18 +136,20 @@ if(NOT MINGW)
 endif()
 
 if(CMAKE_COMPILER_IS_GNUCC)
-    if(ASM686)
-        set(ZLIB_ASMS contrib/asm686/match.S)
-    elseif (AMD64)
-        set(ZLIB_ASMS contrib/amd64/amd64-match.S)
-    endif ()
+       # Gens/GS II: cmake-2.8.4 is required for nasm.
+       cmake_minimum_required(VERSION 2.8.4)
+       if(ASM686)
+               set(ZLIB_ASMS contrib/asm686/match.S)
+       elseif (AMD64)
+               set(ZLIB_ASMS contrib/amd64/amd64-match.S)
+       endif ()
 
        if(ZLIB_ASMS)
                add_definitions(-DASMV)
                # gens-gs-ii: Disable underlines only if not Windows.
                # NOTE: We have to force compilation as C.
                if(WIN32)
-                       set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS)
+                       set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS "")
                else()
                        set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
                endif()
@@ -155,22 +157,25 @@ if(CMAKE_COMPILER_IS_GNUCC)
 endif()
 
 if(MSVC)
-    if(ASM686)
+       # Gens/GS II: cmake-2.6.3 is required for masm.
+       cmake_minimum_required(VERSION 2.6.3)
+       if(ASM686)
                ENABLE_LANGUAGE(ASM_MASM)
-        set(ZLIB_ASMS
+               set(ZLIB_ASMS
                        contrib/masmx86/inffas32.asm
                        contrib/masmx86/match686.asm
-               )
-    elseif (AMD64)
+                       )
+       elseif (AMD64)
                ENABLE_LANGUAGE(ASM_MASM)
-        set(ZLIB_ASMS
+               set(ZLIB_ASMS
                        contrib/masmx64/gvmat64.asm
                        contrib/masmx64/inffasx64.asm
                )
-    endif()
+       endif()
 
        if(ZLIB_ASMS)
                add_definitions(-DASMV -DASMINF)
+               set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE ASM_MASM)
        endif()
 endif()