Permalink
Browse files

New CMake build system

  • Loading branch information...
1 parent f548cee commit 908686ef0d223239f4817afa1669d8b019f6b432 Giacomo Spigler committed with alexp-sssup Mar 27, 2010
View
@@ -0,0 +1,86 @@
+#**************************************************************************
+# Lightspark, a free flash player implementation
+#
+# Copyright (C) 2010 Giacomo Spigler <g.spigler@sssup.it>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#**************************************************************************
+
+
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+PROJECT(LIGHTSPARK)
+
+SET(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install prefix" FORCE)
+SET(COMPILE_LIGHTSPARK TRUE CACHE BOOL "Compile Lightspark?")
+SET(COMPILE_TIGHTSPARK TRUE CACHE BOOL "Compile Tightspark?")
+SET(COMPILE_PLUGIN FALSE CACHE BOOL "Compile the Firefox Plugin?")
+
+SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/conf)
+
+INCLUDE(CMakeASM-NASMCompiler)
+
+#LIBRARIES
+INCLUDE(FindLLVM)
+INCLUDE(FindSDL)
+INCLUDE(FindCURL)
+INCLUDE(FindPkgConfig)
+
+pkg_check_modules(EXTRA_LIBS REQUIRED zlib gl libpcre libpcrecpp libavcodec libxml-2.0)
+
+INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR})
+INCLUDE_DIRECTORIES(${LLVM_INCLUDE_DIR})
+INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
+INCLUDE_DIRECTORIES(${EXTRA_LIBS_INCLUDE_DIRS})
+
+FIND_LIBRARY(lib_pthread pthread REQUIRED)
+FIND_LIBRARY(lib_glew GLEW REQUIRED)
+
+LINK_LIBRARIES(${lib_pthread} ${lib_glew} ${EXTRA_LIBS_LIBRARIES})
+LINK_LIBRARIES(${LLVM_LIBS_CORE} ${LLVM_LIBS_JIT})
+LINK_LIBRARIES(${SDL_LIBRARY})
+LINK_LIBRARIES(${CURL_LIBRARIES})
+
+ENABLE_LANGUAGE(ASM-NASM)
+
+IF(COMPILE_PLUGIN)
+ SUBDIRS(plugin-dir)
+ENDIF(COMPILE_PLUGIN)
+
+IF(COMPILE_LIGHTSPARK OR COMPILE_TIGHTSPARK)
+ SET(CMAKE_CXX_FLAGS "-Wall -g -O0 -D_GLIBCXX_NO_DEBUG -Wnon-virtual-dtor -Woverloaded-virtual -pipe")
+ SET(CMAKE_CXX_FLAGS_RELEASE "-Wall -O3 -DNDEBUG -Wnon-virtual-dtor -Woverloaded-virtual -pipe")
+
+ ADD_LIBRARY(spark STATIC fastpaths.asm swf.cpp swftypes.cpp tags.cpp geometry.cpp actions.cpp frame.cpp input.cpp streams.cpp tags_stub.cpp logger.cpp vm.cpp asobjects.cpp abc.cpp abc_codesynt.cpp abc_opcodes.cpp flashdisplay.cpp flashevents.cpp textfile.cpp thread_pool.cpp flashgeom.cpp flashnet.cpp flashsystem.cpp flashutils.cpp compat.cpp abc_interpreter.cpp flashexternal.cpp flashtext.cpp flashmedia.cpp flv.cpp netutils.cpp timer.cpp)
+ENDIF(COMPILE_LIGHTSPARK OR COMPILE_TIGHTSPARK)
+
+IF(COMPILE_LIGHTSPARK)
+ ADD_EXECUTABLE(lightspark main.cpp)
+ TARGET_LINK_LIBRARIES(lightspark spark)
+
+
+ SET(BINDIR "${CMAKE_INSTALL_PREFIX}/bin")
+ SET(DATADIR "${CMAKE_INSTALL_PREFIX}/share")
+
+ IF(UNIX)
+ INSTALL(FILES lightspark.frag lightspark.vert DESTINATION ${DATADIR}/lightspark)
+ INSTALL(FILES lightspark DESTINATION ${BINDIR})
+ ENDIF(UNIX)
+ENDIF(COMPILE_LIGHTSPARK)
+
+IF(COMPILE_TIGHTSPARK)
+ ADD_EXECUTABLE(tightspark tightspark.cpp)
+ TARGET_LINK_LIBRARIES(tightspark spark)
+ENDIF(COMPILE_TIGHTSPARK)
+
View
@@ -1,51 +0,0 @@
-# User-overridable flags:
-CXXFLAGS = -Wall -g -O0 -D_GLIBCXX_NO_DEBUG -Wnon-virtual-dtor -Woverloaded-virtual
-CXXFLAGS_RELEASE = -Wall -O3 -DNDEBUG -Wnon-virtual-dtor -Woverloaded-virtual
-LLVMLIBS = `llvm-config --libfiles engine interpreter`
-EXTRAFLAGS = `pkg-config --cflags gl sdl libcurl libxml-2.0 libpcrecpp libavcodec`
-EXTRALIBS = `pkg-config --cflags --libs gl sdl libcurl libxml-2.0 libpcrecpp libavcodec` -lrt
-prefix = /usr
-bindir = $(prefix)/bin
-datarootdir = $(prefix)/share
-datadir = $(datarootdir)
-#PKG_BUILD_FLAG=-DLIGHTSPARK_PKG_BUILD # Read data from /usr/share
-
-LIBOBJS = swf.o swftypes.o tags.o geometry.o actions.o frame.o input.o streams.o tags_stub.o logger.o vm.o \
- asobjects.o abc.o abc_codesynt.o abc_opcodes.o flashdisplay.o flashevents.o textfile.o thread_pool.o \
- flashgeom.o flashnet.o flashsystem.o flashutils.o compat.o abc_interpreter.o flashexternal.o \
- flashtext.o flashmedia.o flv.o netutils.o fastpaths.o timer.o
-
-# TODO: library?
-all: lightspark tightspark
-
-release: CXXFLAGS=$(CXXFLAGS_RELEASE)
-release: all
-
-lightspark: main.o $(LIBOBJS)
- $(CXX) -pthread -lz `llvm-config --ldflags` -lGLEW $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -pipe \
- -o $@ $^ $(LLVMLIBS) $(EXTRALIBS)
-
-tightspark: tightspark.o $(LIBOBJS)
- $(CXX) -pthread -lz `llvm-config --ldflags` -lGLEW $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -pipe \
- -o $@ $^ $(LLVMLIBS) $(EXTRALIBS)
-
-plugin:
- make -C plugin-dir
-
-%.o: %.cpp
- $(CXX) -pipe -pthread -I`llvm-config --includedir` $(EXTRAFLAGS) $(PKG_BUILD_FLAG) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -c -o $@ $^
-
-%.o: %.asm
- nasm -f elf64 -o $@ $^
-
-.PHONY: all clean install
-clean:
- -rm -f main.o tightspark.o $(LIBOBJS) lightspark tightspark
- make -C plugin-dir clean
-install: all
- install -d $(DESTDIR)$(bindir) $(DESTDIR)$(datadir)/lightspark
- install lightspark $(DESTDIR)$(bindir)/lightspark
- install -m644 lightspark.frag $(DESTDIR)$(datadir)/lightspark/lightspark.frag
- install -m644 lightspark.vert $(DESTDIR)$(datadir)/lightspark/lightspark.vert
- # TODO: library/plugin install
-
@@ -0,0 +1,19 @@
+# Find the nasm assembler
+
+SET(ASM_DIALECT "-NASM")
+
+SET(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT nasm)
+
+IF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
+ IF(WIN32)
+ FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER nasmw)
+ ELSE(WIN32)
+ FIND_PROGRAM(CMAKE_ASM${ASM_DIALECT}_COMPILER nasm)
+ ENDIF(WIN32)
+ENDIF(NOT CMAKE_ASM${ASM_DIALECT}_COMPILER)
+
+INCLUDE(CMakeDetermineASMCompiler)
+SET(ASM_DIALECT)
+
+
+
@@ -0,0 +1,30 @@
+# support for the nasm assembler
+
+SET(ASM_DIALECT "-NASM")
+
+SET(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS asm)
+
+if(WIN32)
+# if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
+ SET(CMAKE_ASM${ASM_DIALECT}_OBJECT_FORMAT win64)
+# else()
+# SET(CMAKE_ASM${ASM_DIALECT}_OBJECT_FORMAT win32)
+# endif()
+elseif(APPLE)
+# if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
+ SET(CMAKE_ASM${ASM_DIALECT}_OBJECT_FORMAT macho64)
+# else()
+# SET(CMAKE_ASM${ASM_DIALECT}_OBJECT_FORMAT macho)
+# endif()
+else()
+# if(CMAKE_C_SIZEOF_DATA_PTR EQUAL 8)
+ SET(CMAKE_ASM${ASM_DIALECT}_OBJECT_FORMAT elf64)
+# else()
+# SET(CMAKE_ASM${ASM_DIALECT}_OBJECT_FORMAT elf)
+# endif()
+endif()
+
+SET(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <FLAGS> -f ${CMAKE_ASM${ASM_DIALECT}_OBJECT_FORMAT} -o <OBJECT> <SOURCE>")
+
+INCLUDE(CMakeASMInformation)
+SET(ASM_DIALECT)
@@ -0,0 +1,9 @@
+# This file is used by EnableLanguage in cmGlobalGenerator to
+# determine that the selected ASM_NASM "compiler"
+# can actually "compile" and link the most basic of programs. If not, a
+# fatal error is set and cmake stops processing commands and will not generate
+# any makefiles or projects.
+
+SET(ASM_DIALECT "-NASM")
+INCLUDE(CMakeTestASMCompiler)
+SET(ASM_DIALECT)
View
@@ -0,0 +1,168 @@
+# Detect LLVM and set various variable to link against the different component of LLVM
+#
+# NOTE: This is a modified version of the module originally found in the OpenGTL project
+# at www.opengtl.org
+#
+# LLVM_BIN_DIR : directory with LLVM binaries
+# LLVM_LIB_DIR : directory with LLVM library
+# LLVM_INCLUDE_DIR : directory with LLVM include
+#
+# LLVM_COMPILE_FLAGS : compile flags needed to build a program using LLVM headers
+# LLVM_LDFLAGS : ldflags needed to link
+# LLVM_LIBS_CORE : ldflags needed to link against a LLVM core library
+# LLVM_LIBS_JIT : ldflags needed to link against a LLVM JIT
+# LLVM_LIBS_JIT_OBJECTS : objects you need to add to your source when using LLVM JIT
+
+if (MSVC)
+ set(LLVM_ROOT "C:/Program Files/LLVM")
+ if (NOT IS_DIRECTORY ${LLVM_ROOT})
+ message(FATAL_ERROR "Could NOT find LLVM")
+ endif ()
+
+ message(STATUS "Found LLVM: ${LLVM_ROOT}")
+ set(LLVM_BIN_DIR ${LLVM_ROOT}/bin)
+ set(LLVM_LIB_DIR ${LLVM_ROOT}/lib)
+ set(LLVM_INCLUDE_DIR ${LLVM_ROOT}/include)
+
+ set(LLVM_COMPILE_FLAGS "")
+ set(LLVM_LDFLAGS "")
+ set(LLVM_LIBS_CORE LLVMLinker LLVMArchive LLVMBitWriter LLVMBitReader LLVMInstrumentation LLVMScalarOpts LLVMipo LLVMTransformUtils LLVMipa LLVMAnalysis LLVMTarget LLVMMC LLVMCore LLVMSupport LLVMSystem)
+ set(LLVM_LIBS_JIT LLVMX86AsmParser LLVMX86AsmPrinter LLVMX86CodeGen LLVMSelectionDAG LLVMAsmPrinter LLVMX86Info LLVMJIT LLVMExecutionEngine LLVMCodeGen LLVMScalarOpts LLVMTransformUtils LLVMipa LLVMAnalysis LLVMTarget LLVMMC LLVMCore LLVMSupport LLVMSystem)
+ set(LLVM_LIBS_JIT_OBJECTS "")
+endif (MSVC)
+
+if (LLVM_INCLUDE_DIR)
+ set(LLVM_FOUND TRUE)
+else (LLVM_INCLUDE_DIR)
+
+ find_program(LLVM_CONFIG_EXECUTABLE
+ NAMES llvm-config
+ PATHS
+ /opt/local/bin
+ /opt/llvm/2.6/bin
+ /opt/llvm/bin
+ )
+
+ find_program(LLVM_GCC_EXECUTABLE
+ NAMES llvm-gcc llvmgcc
+ PATHS
+ /opt/local/bin
+ /opt/llvm/2.6/bin
+ /opt/llvm/bin
+ /Developer/usr/bin
+ /usr/lib/llvm/llvm/gcc-4.2/bin
+ )
+
+ find_program(LLVM_GXX_EXECUTABLE
+ NAMES llvm-g++ llvmg++
+ PATHS
+ /opt/local/bin
+ /opt/llvm/2.6/bin
+ /opt/llvm/bin
+ /Developer/usr/bin
+ /usr/lib/llvm/llvm/gcc-4.2/bin
+ )
+
+ if(LLVM_GCC_EXECUTABLE)
+ MESSAGE(STATUS "LLVM llvm-gcc found at: ${LLVM_GCC_EXECUTABLE}")
+ #CMAKE_FORCE_C_COMPILER(${LLVM_GCC_EXECUTABLE} GNU)
+ endif(LLVM_GCC_EXECUTABLE)
+
+ if(LLVM_GXX_EXECUTABLE)
+ MESSAGE(STATUS "LLVM llvm-g++ found at: ${LLVM_GXX_EXECUTABLE}")
+ #CMAKE_FORCE_CXX_COMPILER(${LLVM_GXX_EXECUTABLE} GNU)
+ endif(LLVM_GXX_EXECUTABLE)
+
+ if(LLVM_CONFIG_EXECUTABLE)
+ MESSAGE(STATUS "LLVM llvm-config found at: ${LLVM_CONFIG_EXECUTABLE}")
+ else(LLVM_CONFIG_EXECUTABLE)
+ MESSAGE(FATAL_ERROR "Could NOT find LLVM")
+ endif(LLVM_CONFIG_EXECUTABLE)
+
+ MACRO(FIND_LLVM_LIBS LLVM_CONFIG_EXECUTABLE _libname_ LIB_VAR OBJECT_VAR)
+ exec_program( ${LLVM_CONFIG_EXECUTABLE} ARGS --libs ${_libname_} OUTPUT_VARIABLE ${LIB_VAR} )
+ STRING(REGEX MATCHALL "[^ ]*[.]o[ $]" ${OBJECT_VAR} ${${LIB_VAR}})
+ SEPARATE_ARGUMENTS(${OBJECT_VAR})
+ STRING(REGEX REPLACE "[^ ]*[.]o[ $]" "" ${LIB_VAR} ${${LIB_VAR}})
+ ENDMACRO(FIND_LLVM_LIBS)
+
+
+ # this function borrowed from PlPlot, Copyright (C) 2006 Alan W. Irwin
+ function(TRANSFORM_VERSION numerical_result version)
+ # internal_version ignores everything in version after any character that
+ # is not 0-9 or ".". This should take care of the case when there is
+ # some non-numerical data in the patch version.
+ #message(STATUS "DEBUG: version = ${version}")
+ string(REGEX REPLACE "^([0-9.]+).*$" "\\1" internal_version ${version})
+
+ # internal_version is normally a period-delimited triplet string of the form
+ # "major.minor.patch", but patch and/or minor could be missing.
+ # Transform internal_version into a numerical result that can be compared.
+ string(REGEX REPLACE "^([0-9]*).+$" "\\1" major ${internal_version})
+ string(REGEX REPLACE "^[0-9]*\\.([0-9]*).*$" "\\1" minor ${internal_version})
+ #string(REGEX REPLACE "^[0-9]*\\.[0-9]*\\.([0-9]*)$" "\\1" patch ${internal_version})
+
+ #if(NOT patch MATCHES "[0-9]+")
+ # set(patch 0)
+ #endif(NOT patch MATCHES "[0-9]+")
+ set(patch 0)
+
+ if(NOT minor MATCHES "[0-9]+")
+ set(minor 0)
+ endif(NOT minor MATCHES "[0-9]+")
+
+ if(NOT major MATCHES "[0-9]+")
+ set(major 0)
+ endif(NOT major MATCHES "[0-9]+")
+ #message(STATUS "DEBUG: internal_version = ${internal_version}")
+ #message(STATUS "DEBUG: major = ${major}")
+ #message(STATUS "DEBUG: minor= ${minor}")
+ #message(STATUS "DEBUG: patch = ${patch}")
+ math(EXPR internal_numerical_result
+ #"${major}*1000000 + ${minor}*1000 + ${patch}"
+ "${major}*1000000 + ${minor}*1000"
+ )
+ #message(STATUS "DEBUG: ${numerical_result} = ${internal_numerical_result}")
+ set(${numerical_result} ${internal_numerical_result} PARENT_SCOPE)
+ endfunction(TRANSFORM_VERSION)
+
+
+ exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --version OUTPUT_VARIABLE LLVM_STRING_VERSION )
+ MESSAGE(STATUS "LLVM version: " ${LLVM_STRING_VERSION})
+ transform_version(LLVM_VERSION ${LLVM_STRING_VERSION})
+
+ exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --bindir OUTPUT_VARIABLE LLVM_BIN_DIR )
+ exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libdir OUTPUT_VARIABLE LLVM_LIB_DIR )
+ #MESSAGE(STATUS "LLVM lib dir: " ${LLVM_LIB_DIR})
+ exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIR )
+
+
+ exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --cxxflags OUTPUT_VARIABLE LLVM_COMPILE_FLAGS )
+ MESSAGE(STATUS "LLVM CXX flags: " ${LLVM_COMPILE_FLAGS})
+ exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --ldflags OUTPUT_VARIABLE LLVM_LDFLAGS )
+ MESSAGE(STATUS "LLVM LD flags: " ${LLVM_LDFLAGS})
+ exec_program(${LLVM_CONFIG_EXECUTABLE} ARGS --libs core ipa ipo instrumentation bitreader bitwriter linker OUTPUT_VARIABLE LLVM_LIBS_CORE )
+ MESSAGE(STATUS "LLVM core libs: " ${LLVM_LIBS_CORE})
+ IF(APPLE AND UNIVERSAL)
+ FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "jit native x86 PowerPC ARM" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS )
+ ELSE(APPLE AND UNIVERSAL)
+ FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "jit native" LLVM_LIBS_JIT LLVM_LIBS_JIT_OBJECTS )
+ ENDIF(APPLE AND UNIVERSAL)
+ MESSAGE(STATUS "LLVM JIT libs: " ${LLVM_LIBS_JIT})
+ MESSAGE(STATUS "LLVM JIT objs: " ${LLVM_LIBS_JIT_OBJECTS})
+
+ if(LLVM_INCLUDE_DIR)
+ set(LLVM_FOUND TRUE)
+ endif(LLVM_INCLUDE_DIR)
+
+ if(LLVM_FOUND)
+ message(STATUS "Found LLVM: ${LLVM_INCLUDE_DIR}")
+ else(LLVM_FOUND)
+ if(LLVM_FIND_REQUIRED)
+ message(FATAL_ERROR "Could NOT find LLVM")
+ endif(LLVM_FIND_REQUIRED)
+ endif(LLVM_FOUND)
+
+endif (LLVM_INCLUDE_DIR)
+
+
Oops, something went wrong.

0 comments on commit 908686e

Please sign in to comment.