Add CMake build rules

Submitted by whitequark on May 22, 2016, 1:54 a.m.

Details

Message ID 31f34f0fe47eef469d8db639e0075597@whitequark.org
State New
Series "Add CMake build rules"
Headers show

Commit Message

whitequark May 22, 2016, 1:54 a.m.
CMake is a popular build system for C/C++ projects. One key property
it has is that a library using CMake can be "drop in" vendored,
that is, placed in the build tree of another project using CMake
and immediately used as if it was a part of that project.

There is no intermediate configuration step or build directories,
and it is enough to set up a (perhaps cross-)toolchain once for
the toplevel project. This results in a massive usability improvement
for the case where a project links many static libraries, such as
when deploying to Windows or Android, and especially when there is
a combinatorial explosion of targets and target options, such as
on Android, where it is necessary to produce x86, ARM and MIPS builds
in order to target the majority of devices.

For this reason, many projects (including, for example, zlib and
Freetype) opt to provide CMake build rules alongside autoconf ones.

These build rules closely follow the existing autoconf-based rules,
to the degree that any change in autoconf files should trivially
translate to changes in CMakeLists.txt, reducing maintainer workload.
In particular, it uses the same code to test for target-specific
compiler features.

There is no SunOS support, because SunOS is responsible for most
corner cases in the autoconf build rules and it is unlikely that
anyone is interested in using CMake for SunOS builds.

The CMake build rules were tested on:
   * x86_64-linux-gnu;
   * arm-linux-gnueabi;
   * mips-linux-gnu;
   * powerpc-linux-gnu.
On all targets, the target features were manually verified to pass
when they ought to, and the target-specific implementations were
manually verified to be linked in.

On x86_64-linux-gnu, all tests were verified to pass.
On other targets, all tests were verified to link correctly.

[actual patch included as attachment]

Patch hide | download patch | download mbox

From e526d0d1c318407462b3da7e54d1210eed445f48 Mon Sep 17 00:00:00 2001
From: whitequark <whitequark@whitequark.org>
Date: Sun, 22 May 2016 01:38:11 +0000
Subject: [PATCH] Add CMake build rules.

CMake is a popular build system for C/C++ projects. One key property
it has is that a library using CMake can be "drop in" vendored,
that is, placed in the build tree of another project using CMake
and immediately used as if it was a part of that project.

There is no intermediate configuration step or build directories,
and it is enough to set up a (perhaps cross-)toolchain once for
the toplevel project. This results in a massive usability improvement
for the case where a project links many static libraries, such as
when deploying to Windows or Android, and especially when there is
a combinatorial explosion of targets and target options, such as
on Android, where it is necessary to produce x86, ARM and MIPS builds
in order to target the majority of devices.

For this reason, many projects (including, for example, zlib and
Freetype) opt to provide CMake build rules alongside autoconf ones.

These build rules closely follow the existing autoconf-based rules,
to the degree that any change in autoconf files should trivially
translate to changes in CMakeLists.txt, reducing maintainer workload.
In particular, it uses the same code to test for target-specific
compiler features.

There is no SunOS support, because SunOS is responsible for most
corner cases in the autoconf build rules and it is unlikely that
anyone is interested in using CMake for SunOS builds.

The CMake build rules were tested on:
  * x86_64-linux-gnu;
  * arm-linux-gnueabi;
  * mips-linux-gnu;
  * powerpc-linux-gnu.
On all targets, the target features were manually verified to pass
when they ought to, and the target-specific implementations were
manually verified to be linked in.

On x86_64-linux-gnu, all tests were verified to pass.
On other targets, all tests were verified to link correctly.
---
 CMakeLists.txt                 | 355 +++++++++++++++++++++++++++++++++++++++++
 cmake/CheckCFlag.cmake         |  13 ++
 cmake/CheckInline.cmake        |  17 ++
 cmake/CheckTargetFeature.cmake |  19 +++
 cmake/config.h.in              |  63 ++++++++
 demos/CMakeLists.txt           |  42 +++++
 pixman/CMakeLists.txt          | 162 +++++++++++++++++++
 test/CMakeLists.txt            |  69 ++++++++
 8 files changed, 740 insertions(+)
 create mode 100644 CMakeLists.txt
 create mode 100644 cmake/CheckCFlag.cmake
 create mode 100644 cmake/CheckInline.cmake
 create mode 100644 cmake/CheckTargetFeature.cmake
 create mode 100644 cmake/config.h.in
 create mode 100644 demos/CMakeLists.txt
 create mode 100644 pixman/CMakeLists.txt
 create mode 100644 test/CMakeLists.txt

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..985b9de
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,355 @@ 
+project(pixman C ASM)
+cmake_minimum_required(VERSION 3.0)
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
+    "${CMAKE_SOURCE_DIR}/cmake/")
+
+include(CheckTypeSize)
+include(CheckIncludeFile)
+include(CheckFunctionExists)
+include(CheckLibraryExists)
+include(CheckSymbolExists)
+include(CheckInline)
+include(CheckCFlag)
+include(CheckTargetFeature)
+
+# Versioning
+file(READ configure.ac configure_ac)
+string(REGEX REPLACE ".*m4_define\\(\\[pixman_major\\], ([0-9]+)\\).*" "\\1"
+                     PIXMAN_VERSION_MAJOR ${configure_ac})
+string(REGEX REPLACE ".*m4_define\\(\\[pixman_minor\\], ([0-9]+)\\).*" "\\1"
+                     PIXMAN_VERSION_MINOR ${configure_ac})
+string(REGEX REPLACE ".*m4_define\\(\\[pixman_micro\\], ([0-9]+)\\).*" "\\1"
+                     PIXMAN_VERSION_MICRO ${configure_ac})
+set(PIXMAN_VERSION "${PIXMAN_VERSION_MAJOR}.${PIXMAN_VERSION_MINOR}.${PIXMAN_VERSION_MICRO}")
+message(STATUS "Building pixman version ${PIXMAN_VERSION}")
+
+# Building
+set(PIXMAN_BUILD_STATIC ON CACHE BOOL "Build a static library")
+set(PIXMAN_BUILD_SHARED ON CACHE BOOL "Build a shared library")
+set(PIXMAN_BUILD_TESTS  ON CACHE BOOL "Build and run regression tests")
+set(PIXMAN_BUILD_DEMOS  ON CACHE BOOL "Build demo code")
+
+if(PIXMAN_BUILD_TESTS)
+    enable_testing()
+endif()
+
+# Configuration
+include_directories(
+    ${CMAKE_BINARY_DIR}/pixman
+    ${CMAKE_SOURCE_DIR}/pixman
+)
+
+find_library(LIBM_LIBRARY m)
+set(CMAKE_REQUIRED_LIBRARIES ${LIBM_LIBRARY})
+
+set(WORDS_BIGENDIAN ${CMAKE_WORDS_BIGENDIAN})
+check_inline()
+
+check_function_exists(getisax HAVE_GETISAX)
+check_type_size(long SIZEOF_LONG)
+
+check_c_flag(-Wall)
+check_c_flag(-Wdeclaration-after-statement)
+check_c_flag(-Wno-unused-local-typedefs)
+check_c_flag(-fno-strict-aliasing)
+
+find_package(OpenMP)
+set(USE_OPENMP ${OPENMP_FOUND})
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
+
+set(LOONGSON_MMI_FLAGS "-march=loongson2f")
+check_target_feature(
+"#ifndef __mips_loongson_vector_rev
+#error Loongson Multimedia Instructions are only available on Loongson
+#endif
+#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 4))
+#error Need GCC >= 4.4 for Loongson MMI compilation
+#endif
+#include <pixman/loongson-mmintrin.h>
+int main () {
+    union {
+        __m64 v;
+        char c[8];
+    } a = { .c = {1, 2, 3, 4, 5, 6, 7, 8} };
+    int b = 4;
+    __m64 c = _mm_srli_pi16 (a.v, b);
+    return 0;
+}"
+    "${LOONGSON_MMI_FLAGS} -I${CMAKE_CURRENT_SOURCE_DIR}"
+    USE_LOONGSON_MMI
+    "Enable Loongson MMI fast paths")
+
+set(X86_MMX_FLAGS "-mmmx -Winline")
+check_target_feature(
+"#if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4))
+#error Need GCC >= 3.4 for MMX intrinsics
+#endif
+#include <mmintrin.h>
+#include <stdint.h>
+
+/* Check support for block expressions */
+#define _mm_shuffle_pi16(A, N)                      \\\\
+    ({                                  \\\\
+    __m64 ret;                          \\\\
+                                    \\\\
+    /* Some versions of clang will choke on K */            \\\\
+    asm (\"pshufw %2, %1, %0\\\\n\\\\t\"                    \\\\
+         : \"=y\" (ret)                       \\\\
+         : \"y\" (A), \"K\" ((const int8_t)N)               \\\\
+    );                              \\\\
+                                    \\\\
+    ret;                                \\\\
+    })
+
+int main () {
+    __m64 v = _mm_cvtsi32_si64 (1);
+    __m64 w;
+
+    w = _mm_shuffle_pi16(v, 5);
+
+    /* Some versions of clang will choke on this */
+    asm (\"pmulhuw %1, %0\\\\n\\\\t\"
+    : \"+y\" (w)
+    : \"y\" (v)
+    );
+
+    return _mm_cvtsi64_si32 (v);
+}"
+    ${X86_MMX_FLAGS}
+    USE_X86_MMX
+    "Use x86 MMX compiler intrinsics")
+
+set(SSE2_FLAGS "-msse2 -Winline")
+check_target_feature(
+"#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 2))
+#   if !defined(__amd64__) && !defined(__x86_64__)
+#      error Need GCC >= 4.2 for SSE2 intrinsics on x86
+#   endif
+#endif
+#include <mmintrin.h>
+#include <xmmintrin.h>
+#include <emmintrin.h>
+int param;
+int main () {
+    __m128i a = _mm_set1_epi32 (param), b = _mm_set1_epi32 (param + 1), c;
+    c = _mm_xor_si128 (a, b);
+    return _mm_cvtsi128_si32(c);
+}"
+    ${SSE2_FLAGS}
+    USE_SSE2
+    "Use SSE2 compiler intrinsics")
+
+set(SSSE3_FLAGS "-mssse3 -Winline")
+check_target_feature(
+"#include <mmintrin.h>
+#include <xmmintrin.h>
+#include <emmintrin.h>
+#include <tmmintrin.h>
+int param;
+int main () {
+    __m128i a = _mm_set1_epi32 (param), b = _mm_set1_epi32 (param + 1), c;
+    c = _mm_maddubs_epi16 (a, b);
+    return _mm_cvtsi128_si32(c);
+}"
+    ${SSSE3_FLAGS}
+    USE_SSSE3
+    "Use SSSE3 compiler intrinsics")
+
+if(APPLE)
+    set(VMX_FLAGS "-faltivec")
+else()
+    set(VMX_FLAGS "-maltivec -mabi=altivec")
+endif()
+check_target_feature(
+"#if defined(__GNUC__) && (__GNUC__ < 3 || (__GNUC__ == 3 && __GNUC_MINOR__ < 4))
+#error Need GCC >= 3.4 for sane altivec support
+#endif
+#include <altivec.h>
+int main () {
+    vector unsigned int v = vec_splat_u32 (1);
+    v = vec_sub (v, v);
+    return 0;
+}"
+    ${VMX_FLAGS}
+    USE_VMX
+    "Use VMX compiler intrinsics")
+
+check_target_feature(
+".text
+.arch armv6
+.object_arch armv4
+.arm
+.altmacro
+#ifndef __ARM_EABI__
+#error EABI is required (to be sure that calling conventions are compatible)
+#endif
+.globl main
+main:
+pld [r0]
+uqadd8 r0, r0, r0"
+    "-x assembler-with-cpp"
+    USE_ARM_SIMD
+    "Use ARM SIMD assembly optimizations")
+
+check_target_feature(
+".text
+.fpu neon
+.arch armv7a
+.object_arch armv4
+.eabi_attribute 10, 0
+.arm
+.altmacro
+#ifndef __ARM_EABI__
+#error EABI is required (to be sure that calling conventions are compatible)
+#endif
+.globl main
+main:
+pld [r0]
+vmovn.u16 d0, q0"
+    "-x assembler-with-cpp"
+    USE_ARM_NEON
+    "Use ARM NEON assembly optimizations")
+
+set(IWMMXT_FLAGS "-flax-vector-conversions -Winline -march=iwmmxt")
+set(PIXMAN_ENABLE_IWMMXT2 ON CACHE BOOL
+    "Build ARM IWMMXT fast paths with -march=iwmmxt2")
+if(PIXMAN_ENABLE_IWMMXT2)
+    set(IWMMXT_FLAGS "${IWMMXT_FLAGS}2")
+endif()
+check_target_feature(
+"#ifndef __arm__
+#error IWMMXT is only available on ARM
+#endif
+#ifndef __IWMMXT__
+#error IWMMXT not enabled (with -march=iwmmxt)
+#endif
+#if defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 8))
+#error Need GCC >= 4.8 for IWMMXT intrinsics
+#endif
+#include <mmintrin.h>
+int main () {
+    union {
+        __m64 v;
+        char c[8];
+    } a = { .c = {1, 2, 3, 4, 5, 6, 7, 8} };
+    int b = 4;
+    __m64 c = _mm_srli_si64 (a.v, b);
+}"
+    ${IWMMXT_FLAGS}
+    USE_ARM_IWMMXT
+    "Use ARM IWMMXT compiler intrinsics")
+
+set(MIPS_DSPR2_FLAGS "-mdspr2")
+check_target_feature(
+"#if !(defined(__mips__) &&  __mips_isa_rev >= 2)
+#error MIPS DSPr2 is currently only available on MIPS32r2 platforms.
+#endif
+int
+main ()
+{
+    int c = 0, a = 0, b = 0;
+    __asm__ __volatile__ (
+        \"precr.qb.ph %[c], %[a], %[b]          \\\\n\\\\t\"
+        : [c] \"=r\" (c)
+        : [a] \"r\" (a), [b] \"r\" (b)
+    );
+    return c;
+}"
+    ${MIPS_DSPR2_FLAGS}
+    USE_MIPS_DSPR2
+    "Enable MIPS DSPr2 fast paths")
+
+check_c_source_compiles(
+"int main () {
+    /* Most modern architectures have a NOP instruction, so this is a fairly generic test. */
+    asm volatile ( \"\\\\tnop\\\\n\" : : : \"cc\", \"memory\" );
+    return 0;
+}"
+    USE_GCC_INLINE_ASM)
+
+find_package(PkgConfig)
+if(PKGCONFIG_FOUND)
+    pkg_check_modules(GTK gtk+-2.0>=2.16)
+endif()
+
+set(PIXMAN_TIMERS OFF CACHE BOOL "Enable TIMER_BEGIN/TIMER_END macros")
+
+check_function_exists(posix_memalign      HAVE_POSIX_MEMALIGN)
+check_function_exists(sigaction           HAVE_SIGACTION)
+check_function_exists(alarm               HAVE_ALARM)
+check_include_file   (sys/mman.h          HAVE_SYS_MMAN_H)
+check_function_exists(mmap                HAVE_MMAP)
+check_function_exists(mprotect            HAVE_MPROTECT)
+check_function_exists(getpagesize         HAVE_GETPAGESIZE)
+check_include_file   (fenv.h              HAVE_FENV_H)
+check_function_exists(feenableexcept      HAVE_FEENABLEEXCEPT)
+check_symbol_exists  (FE_DIVBYZERO fenv.h HAVE_FEDIVBYZERO)
+check_function_exists(gettimeofday        HAVE_GETTIMEOFDAY)
+check_function_exists(sqrtf               HAVE_SQRTF)
+if(NOT HAVE_SQRTF)
+    set(sqrtf sqrt)
+endif()
+
+foreach(keyword "__thread" "__declspec(thread)")
+    check_c_source_compiles(
+"#if defined(__MINGW32__) && !(__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
+#error This MinGW version has broken __thread support
+#endif
+#ifdef __OpenBSD__
+#error OpenBSD has broken __thread support
+#endif
+
+int ${keyword} test;
+int main() { return 0; }"
+        HAVE_TLS_${keyword})
+    if(HAVE_TLS_${keyword})
+        set(TLS ${keyword})
+        break()
+    endif()
+endforeach()
+
+find_package(Threads)
+set(HAVE_PTHREADS ${CMAKE_USE_PTHREADS_INIT})
+link_libraries(${CMAKE_THREAD_LIBS_INIT})
+
+check_c_source_compiles(
+"#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
+/* attribute 'constructor' is supported since gcc 2.7, but some compilers
+ * may only pretend to be gcc, so let's try to actually use it
+ */
+static int x = 1;
+static void __attribute__((constructor)) constructor_function () { x = 0; }
+int main (void) { return x; }
+#else
+#error not gcc or gcc version is older than 2.7
+#endif"
+    TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR)
+
+check_c_source_compiles(
+"__float128 a = 1.0Q, b = 2.0Q; int main (void) { return a + b; }"
+    HAVE_FLOAT128)
+
+check_c_source_compiles(
+"unsigned int x = 11; int main (void) { return __builtin_clz(x); }"
+    HAVE_BUILTIN_CLZ)
+
+check_c_source_compiles(
+"unsigned int __attribute__ ((vector_size(16))) e, a, b;
+int main (void) { e = a - ((b << 27) + (b >> (32 - 27))) + 1; return e[0]; }"
+    HAVE_GCC_VECTOR_EXTENSIONS)
+
+set(HAVE_LIBPNG ${PNG_FOUND})
+
+add_definitions(-DHAVE_CONFIG_H)
+configure_file(
+    cmake/config.h.in
+    ${CMAKE_BINARY_DIR}/pixman/config.h)
+
+# Components
+add_subdirectory(pixman)
+if(PIXMAN_BUILD_TESTS)
+    add_subdirectory(test)
+endif()
+if(PIXMAN_BUILD_DEMOS AND GTK_FOUND)
+    add_subdirectory(demos)
+endif()
diff --git a/cmake/CheckCFlag.cmake b/cmake/CheckCFlag.cmake
new file mode 100644
index 0000000..3fa48e9
--- /dev/null
+++ b/cmake/CheckCFlag.cmake
@@ -0,0 +1,13 @@ 
+include(CheckCSourceCompiles)
+
+function(check_c_flag FLAG)
+    string(REPLACE "-" "_" ESCAPED_FLAG ${FLAG})
+
+    set(CMAKE_REQUIRED_FLAGS ${FLAG})
+    check_c_source_compiles(
+"int main(int argc, char **argv) { (void)argc; (void)argv; return 0; }"
+        HAS${ESCAPED_FLAG})
+    if(${HAS${ESCAPED_FLAG}})
+        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${FLAG}" PARENT_SCOPE)
+    endif()
+endfunction()
diff --git a/cmake/CheckInline.cmake b/cmake/CheckInline.cmake
new file mode 100644
index 0000000..1faa4a5
--- /dev/null
+++ b/cmake/CheckInline.cmake
@@ -0,0 +1,17 @@ 
+include(CheckCSourceCompiles)
+
+function(check_inline)
+    foreach(keyword inline __inline__ __inline)
+        set(CMAKE_REQUIRED_DEFINITIONS "-Dinline=${keyword}")
+        check_c_source_compiles(
+"static inline void x(){}
+int main(int argc, char **argv) { (void)argc; (void)argv; return 0; }"
+            USE_INLINE_${keyword})
+        if(USE_INLINE_${keyword})
+            if(NOT keyword STREQUAL "inline")
+                set(USE_INLINE ${keyword} PARENT_SCOPE)
+            endif()
+            break()
+        endif()
+    endforeach()
+endfunction()
diff --git a/cmake/CheckTargetFeature.cmake b/cmake/CheckTargetFeature.cmake
new file mode 100644
index 0000000..093c203
--- /dev/null
+++ b/cmake/CheckTargetFeature.cmake
@@ -0,0 +1,19 @@ 
+include(CheckCSourceCompiles)
+
+function(check_target_feature SOURCE FLAGS RESULT_VAR DESCRIPTION)
+    if(DEFINED ${RESULT_VAR})
+        # We got a -D${RESULT_VAR}=... on command line; still need
+        # to put it into the cache.
+        set(RESULT ${${RESULT_VAR}})
+    else()
+        # Autodetect the feature (and then put it into cache).
+        if(FLAGS MATCHES -x)
+            # Only pass -x to compiler, not linker.
+            set(CMAKE_REQUIRED_DEFINITIONS "${FLAGS}")
+        else()
+            set(CMAKE_REQUIRED_FLAGS "${FLAGS}")
+        endif()
+        check_c_source_compiles("${SOURCE}" ${RESULT_VAR})
+    endif()
+    set(${RESULT_VAR} ${${RESULT_VAR}} CACHE BOOL ${DESCRIPTION})
+endfunction()
diff --git a/cmake/config.h.in b/cmake/config.h.in
new file mode 100644
index 0000000..c9b134e
--- /dev/null
+++ b/cmake/config.h.in
@@ -0,0 +1,63 @@ 
+#define PACKAGE "pixman"
+#define PACKAGE_BUGREPORT "pixman@lists.freedesktop.org"
+#define PACKAGE_NAME "pixman"
+#define PACKAGE_STRING "pixman @PIXMAN_VERSION@"
+#define PACKAGE_TARNAME "pixman"
+#define PACKAGE_URL ""
+#define PACKAGE_VERSION "@PIXMAN_VERSION@"
+
+#ifndef __cplusplus
+#cmakedefine inline @inline@
+#endif
+
+#if defined __BIG_ENDIAN__
+#define WORDS_BIGENDIAN 1
+#else
+#cmakedefine WORDS_BIGENDIAN @WORDS_BIGENDIAN@
+#endif
+
+#cmakedefine SIZEOF_LONG @SIZEOF_LONG@
+
+#cmakedefine USE_OPENMP
+
+#cmakedefine USE_LOONGSON_MMI
+#cmakedefine USE_X86_MMX
+#cmakedefine USE_SSE2
+#cmakedefine USE_SSSE3
+#cmakedefine USE_VMX
+#cmakedefine USE_ARM_SIMD
+#cmakedefine USE_ARM_NEON
+#cmakedefine USE_ARM_IWMMXT
+#cmakedefine USE_MIPS_DSPR2
+#cmakedefine USE_GCC_INLINE_ASM
+
+#cmakedefine PIXMAN_TIMERS
+
+#cmakedefine HAVE_POSIX_MEMALIGN
+#cmakedefine HAVE_SIGACTION
+#cmakedefine HAVE_ALARM
+#cmakedefine HAVE_SYS_MMAN_H
+#cmakedefine HAVE_MMAP
+#cmakedefine HAVE_MPROTECT
+#cmakedefine HAVE_GETPAGESIZE
+#cmakedefine HAVE_FENV_H
+#cmakedefine HAVE_FEENABLEEXCEPT
+#cmakedefine HAVE_FEDIVBYZERO
+#cmakedefine HAVE_GETTIMEOFDAY
+#cmakedefine HAVE_SQRTF
+
+#cmakedefine sqrtf @sqrtf@
+
+#cmakedefine TLS @TLS@
+
+#cmakedefine HAVE_PTHREADS
+
+#cmakedefine TOOLCHAIN_SUPPORTS_ATTRIBUTE_CONSTRUCTOR
+
+#cmakedefine HAVE_FLOAT128
+
+#cmakedefine HAVE_BUILTIN_CLZ
+
+#cmakedefine HAVE_GCC_VECTOR_EXTENSIONS
+
+#cmakedefine HAVE_LIBPNG
diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt
new file mode 100644
index 0000000..df832e7
--- /dev/null
+++ b/demos/CMakeLists.txt
@@ -0,0 +1,42 @@ 
+include_directories(
+    ${GTK_INCLUDE_DIRS})
+link_directories(
+    ${GTK_LIBRARY_DIRS})
+add_definitions(
+    ${GTK_CFLAGS_OTHER})
+
+set(DEMOS
+    clip-test
+    clip-in
+    composite-test
+    gradient-test
+    radial-test
+    linear-gradient
+    conical-test
+    alpha-test
+    screen-test
+    convolution-test
+    trap-test
+    tri-test
+    quad2quad
+    checkerboard
+    srgb-trap-test
+    srgb-test
+    scale
+)
+
+add_library(pixman_gtk_utils STATIC
+    gtk-utils.c
+    gtk-utils.h)
+target_link_libraries(pixman_gtk_utils
+    pixman_test_utils
+    ${GTK_LIBRARIES})
+
+foreach(program ${DEMOS})
+    add_executable(pixman_${program}
+        ${program}.c)
+    set_target_properties(pixman_${program} PROPERTIES
+        OUTPUT_NAME ${program})
+    target_link_libraries(pixman_${program}
+        pixman_gtk_utils)
+endforeach()
diff --git a/pixman/CMakeLists.txt b/pixman/CMakeLists.txt
new file mode 100644
index 0000000..4cc6df7
--- /dev/null
+++ b/pixman/CMakeLists.txt
@@ -0,0 +1,162 @@ 
+set(SOURCES
+    pixman.c
+    pixman-access.c
+    pixman-access-accessors.c
+    pixman-bits-image.c
+    pixman-combine32.c
+    pixman-combine-float.c
+    pixman-conical-gradient.c
+    pixman-filter.c
+    pixman-x86.c
+    pixman-mips.c
+    pixman-arm.c
+    pixman-ppc.c
+    pixman-edge.c
+    pixman-edge-accessors.c
+    pixman-fast-path.c
+    pixman-glyph.c
+    pixman-general.c
+    pixman-gradient-walker.c
+    pixman-image.c
+    pixman-implementation.c
+    pixman-linear-gradient.c
+    pixman-matrix.c
+    pixman-noop.c
+    pixman-radial-gradient.c
+    pixman-region16.c
+    pixman-region32.c
+    pixman-solid-fill.c
+    pixman-timer.c
+    pixman-trap.c
+    pixman-utils.c
+)
+
+set(HEADERS
+    pixman.h
+    pixman-accessor.h
+    pixman-combine32.h
+    pixman-compiler.h
+    pixman-edge-imp.h
+    pixman-inlines.h
+    pixman-private.h
+)
+
+if(USE_X86_MMX)
+    list(APPEND SOURCES
+        pixman-mmx.c)
+    set_source_files_properties(
+        pixman-mmx.c
+        PROPERTIES COMPILE_FLAGS ${X86_MMX_FLAGS})
+endif()
+
+if(USE_VMX)
+    list(APPEND SOURCES
+        pixman-vmx.c)
+    list(APPEND HEADERS
+        pixman-combine32.h)
+    set_source_files_properties(
+        pixman-vmx.c
+        PROPERTIES COMPILE_FLAGS ${VMX_FLAGS})
+endif()
+
+if(USE_SSE2)
+    list(APPEND SOURCES
+        pixman-sse2.c)
+    set_source_files_properties(
+        pixman-sse2.c
+        PROPERTIES COMPILE_FLAGS ${SSE2_FLAGS})
+endif()
+
+if(USE_SSSE3)
+    list(APPEND SOURCES
+        pixman-ssse3.c)
+    set_source_files_properties(
+        pixman-ssse3.c
+        PROPERTIES COMPILE_FLAGS ${SSSE3_FLAGS})
+endif()
+
+if(USE_ARM_SIMD)
+    list(APPEND SOURCES
+        pixman-arm-simd.c
+        pixman-arm-simd-asm.S
+        pixman-arm-simd-asm-scaled.S)
+    list(APPEND HEADERS
+        pixman-arm-common.h
+        pixman-arm-asm.h
+        pixman-arm-simd-asm.h)
+endif()
+
+if(USE_ARM_NEON)
+    list(APPEND SOURCES
+        pixman-arm-neon.c
+        pixman-arm-neon-asm.S
+        pixman-arm-neon-asm-bilinear.S)
+    list(APPEND HEADERS
+        pixman-arm-common.h
+        pixman-arm-asm.h
+        pixman-arm-neon-asm.h)
+endif()
+
+if(USE_ARM_IWMMXT)
+    list(APPEND SOURCES
+        pixman-mmx.c)
+    set_source_files_properties(
+        pixman-mmx.c
+        PROPERTIES COMPILE_FLAGS ${IWMMXT_FLAGS})
+endif()
+
+if(USE_MIPS_DSPR2)
+    list(APPEND SOURCES
+        pixman-mips-dspr2.c
+        pixman-mips-dspr2-asm.S
+        pixman-mips-memcpy-asm.S)
+    list(APPEND HEADERS
+        pixman-mips-dspr2.h
+        pixman-mips-dspr2-asm.h)
+endif()
+
+if(USE_LOONGSON_MMI)
+    list(APPEND SOURCES
+        pixman-mmx.c)
+    list(APPEND HEADERS
+        loongson-mmintrin.h)
+    set_source_files_properties(
+        pixman-mmx.c
+        PROPERTIES COMPILE_FLAGS ${LOONGSON_MMI_FLAGS})
+endif()
+
+if(PIXMAN_BUILD_STATIC)
+    add_library(pixman_static STATIC
+        ${SOURCES} ${HEADERS})
+    target_link_libraries(pixman_static
+        ${LIBM_LIBRARY})
+    set_target_properties(pixman_static PROPERTIES
+        OUTPUT_NAME pixman-1
+        CXX_VISIBILITY_PRESET hidden)
+    install(TARGETS pixman_static
+        RUNTIME DESTINATION bin
+        ARCHIVE DESTINATION lib
+        LIBRARY DESTINATION lib)
+endif()
+
+if(PIXMAN_BUILD_SHARED)
+    add_library(pixman_shared SHARED
+        ${SOURCES} ${HEADERS})
+    target_link_libraries(pixman_shared
+        ${LIBM_LIBRARY})
+    set_target_properties(pixman_shared PROPERTIES
+        OUTPUT_NAME pixman-1
+        CXX_VISIBILITY_PRESET hidden)
+    install(TARGETS pixman_shared
+        RUNTIME DESTINATION bin
+        ARCHIVE DESTINATION lib
+        LIBRARY DESTINATION lib)
+endif()
+
+configure_file(
+    pixman-version.h.in
+    ${CMAKE_CURRENT_BINARY_DIR}/pixman-version.h)
+install(FILES
+    pixman.h
+    ${CMAKE_CURRENT_BINARY_DIR}/pixman-version.h
+    DESTINATION include/pixman-1)
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..0f68177
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,69 @@ 
+set(TESTPROGRAMS
+    oob-test
+    infinite-loop
+    trap-crasher
+    fence-image-self-test
+    region-translate-test
+    fetch-test
+    a1-trap-test
+    prng-test
+    radial-invalid
+    pdf-op-test
+    region-test
+    combiner-test
+    scaling-crash-test
+    alpha-loop
+    scaling-helpers-test
+    thread-test
+    rotate-test
+    alphamap
+    gradient-crash-test
+    pixel-test
+    matrix-test
+    composite-traps-test
+    region-contains-test
+    glyph-test
+    solid-test
+    stress-test
+    cover-test
+    blitters-test
+    affine-test
+    scaling-test
+    composite
+    tolerance-test
+)
+
+set(OTHERPROGRAMS
+    lowlevel-blt-bench
+    radial-perf-test
+    check-formats
+    scaling-bench
+    affine-bench
+)
+
+add_library(pixman_test_utils STATIC
+    utils.c
+    utils-prng.c
+    utils.h
+    utils-prng.h)
+if(PIXMAN_BUILD_SHARED)
+    target_link_libraries(pixman_test_utils
+        pixman_shared)
+else()
+    target_link_libraries(pixman_test_utils
+        pixman_static)
+endif()
+
+foreach(program ${TESTPROGRAMS} ${OTHERPROGRAMS})
+    add_executable(pixman_${program}
+        ${program}.c)
+    set_target_properties(pixman_${program} PROPERTIES
+        OUTPUT_NAME ${program})
+    target_link_libraries(pixman_${program}
+        pixman_test_utils)
+endforeach()
+
+foreach(program ${TESTPROGRAMS})
+    add_test(NAME ${program} COMMAND pixman_${program})
+    set_tests_properties(${program} PROPERTIES SKIP_RETURN_CODE 77)
+endforeach()
-- 
2.8.1


Comments

Pekka Paalanen May 22, 2016, 9:20 a.m.
On Sun, 22 May 2016 01:54:36 +0000
whitequark <whitequark@whitequark.org> wrote:

> CMake is a popular build system for C/C++ projects. One key property
> it has is that a library using CMake can be "drop in" vendored,
> that is, placed in the build tree of another project using CMake
> and immediately used as if it was a part of that project.
> 
> There is no intermediate configuration step or build directories,
> and it is enough to set up a (perhaps cross-)toolchain once for
> the toplevel project. This results in a massive usability improvement
> for the case where a project links many static libraries, such as
> when deploying to Windows or Android, and especially when there is
> a combinatorial explosion of targets and target options, such as
> on Android, where it is necessary to produce x86, ARM and MIPS builds
> in order to target the majority of devices.
> 
> For this reason, many projects (including, for example, zlib and
> Freetype) opt to provide CMake build rules alongside autoconf ones.
> 
> These build rules closely follow the existing autoconf-based rules,
> to the degree that any change in autoconf files should trivially
> translate to changes in CMakeLists.txt, reducing maintainer workload.
> In particular, it uses the same code to test for target-specific
> compiler features.
> 
> There is no SunOS support, because SunOS is responsible for most
> corner cases in the autoconf build rules and it is unlikely that
> anyone is interested in using CMake for SunOS builds.
> 
> The CMake build rules were tested on:
>    * x86_64-linux-gnu;
>    * arm-linux-gnueabi;
>    * mips-linux-gnu;
>    * powerpc-linux-gnu.
> On all targets, the target features were manually verified to pass
> when they ought to, and the target-specific implementations were
> manually verified to be linked in.
> 
> On x86_64-linux-gnu, all tests were verified to pass.
> On other targets, all tests were verified to link correctly.
> 
> [actual patch included as attachment]

Hi,

please always put patches as inline.

This sounds like a very very bad idea to me, and I think the
execution is even worse.

If Mesa has tought us anything, it is that a project with multiple
build systems is much harder to maintain. Mesa struggles with it at
times, even when it has many active *paid* developers using both (I
think it is down to two now.. no, three: autotools, scons and
Android) build systems.

That said, Mesa actually tried to make that maintenance manageable,
which I do not really see from your patch.

Assuming people were happy adding a new build system, which I very
much doubt, let's look at your patch.

 8 files changed, 740 insertions(+)

No deletions.

You use regexes to fetch the version numbers from configure.ac,
right?

That seems to be the only thing you use from the current build
system. IOW, you are duplicating:
- all source file lists
- all build rules (built binaries)
- all hand-written code checking for compiler features
- config.h template

I believe that all that duplication will be a huge pain for
upstream. It is already labourious to ask people to test on various
platforms, and this will double the required effort.

Adding the CMake files to Pixman may be a one-shot effort for you,
but then the upstream maintainers and developers (who are very few
and already burdened) are stuck with it, now trying to learn
how CMake works, and spending hours verifying the build systems
are consistent (or letting CMake just rot and refuse all bug
reports from CMake-built binaries, in which case why even bother
merging in the first place).

For what benefit? So that people who set up cross-build toolchains
and projects as their job have one less component to make that
setup for?

If you could promise, as a company, to assign a developer whose job
will be to maintain this in Pixman, then just maybe it could make
sense, but so far I think this patch would be a turn for the worse
for Pixman.

Or would you perhaps offer a CI system automatically building with
both autotools and CMake and verifying they work the same on all
the platforms where you care about CMake?

Upstream should either fully endorse CMake as a new official build
system for Pixman, in which case you would try to share as much
configuration with autotools as possible, or, just reject it.

I wonder what others think?


Thanks,
pq
whitequark May 22, 2016, 9:47 a.m.
On 2016-05-22 09:20, Pekka Paalanen wrote:
> [snip]
> 
> Assuming people were happy adding a new build system, which I very
> much doubt,

I've checked the mailing list of Cairo before starting this work.
There have been two attempts at introducing a CMake buildsystem, and
no conceptual objections were raised. While Pixman is not Cairo,
I considered that enough to give this patch a try.

> [snip]
> 
> That seems to be the only thing you use from the current build
> system. IOW, you are duplicating:
> - all source file lists
> - all build rules (built binaries)
> - all hand-written code checking for compiler features
> - config.h template

Generating CMake and autoconf build rules from a shared source would
surely result in a system that is more complex, and harder to 
understand,
than both of those alone. I do not think that such a system would be
of benefit to anyone.

> [snip]
> 
> For what benefit? So that people who set up cross-build toolchains
> and projects as their job have one less component to make that
> setup for?

So that people would avoid the setup of cross-build toolchains from
becoming their job.

In any case, the purpose of submitting this patch is less of insisting
on action from upstream and more of sharing my work. If upstream 
considers
it valuable, I am willing to spend time coordinating the integration.
If not? That's fine by me as well; I'll just keep using the fork.
Koen Kooi May 22, 2016, 4:44 p.m.
Op 22-05-16 om 11:47 schreef whitequark:
> On 2016-05-22 09:20, Pekka Paalanen wrote:
>> [snip]
>> 
>> For what benefit? So that people who set up cross-build toolchains and
>> projects as their job have one less component to make that setup for?
> 
> So that people would avoid the setup of cross-build toolchains from 
> becoming their job.

LOL, cross-building with cmake is a joke. While core-cmake cross-build
functionality is awesome (a toolchain file!), the people writing the
FindLibFoo stuff are ignorantly hardcoding /usr/lib, /usr/include and
friends. And worse, patches for that are generally land on the bottom of the
review pile.

And for the record, cross-build toolchains and buidsystems *are* my job and
I hate cmake with a passion.

Even if all of the above magically gets fixed, having more than 1
buildsystem for a project is a drain on resources and usually ends up with
"But it *does* work in my pet system, WONTFIX" type of replies to people who
run into issues.

regards,

Koen
Emil Velikov May 22, 2016, 10:09 p.m.
On 22 May 2016 at 10:47, whitequark <whitequark@whitequark.org> wrote:
> On 2016-05-22 09:20, Pekka Paalanen wrote:
>>
>> [snip]
>>
>> Assuming people were happy adding a new build system, which I very
>> much doubt,
>
>
> I've checked the mailing list of Cairo before starting this work.
> There have been two attempts at introducing a CMake buildsystem, and
> no conceptual objections were raised. While Pixman is not Cairo,
> I considered that enough to give this patch a try.
>
>> [snip]
>>
>> That seems to be the only thing you use from the current build
>> system. IOW, you are duplicating:
>> - all source file lists
>> - all build rules (built binaries)
>> - all hand-written code checking for compiler features
>> - config.h template
>
>
> Generating CMake and autoconf build rules from a shared source would
> surely result in a system that is more complex, and harder to understand,
> than both of those alone. I do not think that such a system would be
> of benefit to anyone.
>
Err... wrong ? The following is not too complex, right ?

set(pixman_sources
     parse_list("Makefile.sources" $(libpixman_sources))
)

Obviously one needs to add the said function. Sadly the other bits in
pq's list might be rather hard to implement, depending on your cmake
skills.

>> [snip]
>>
>> For what benefit? So that people who set up cross-build toolchains
>> and projects as their job have one less component to make that
>> setup for?
>
>
> So that people would avoid the setup of cross-build toolchains from
> becoming their job.
>
Can you elaborate how cmake makes thing easier ? I think that there's
some misunderstanding here, which brings you to false assumptions.
Please list the steps you have to do for each one.


As the person trying to juggle the Mesa build systems... I would
kindly urge you against the idea. Please look if the cross-build
toolchains thing is an actual issue, before introducing and/or
maintaining another build system.

Obviously my word hear means jack, so ...

-Emil