Permalink
Browse files

Add cmake build infrastructure.

Not default nor even distributed in the .tar.gz, the cmake build allows for
loadable yasm plugins by building libyasm as a shared library.
Example plugins are in the plugins/ directory, and may be loaded into a
cmake-built yasm using the -N command line option (non-cmake builds will
not have this option).

Tested only on Linux so far, but should be relatively painless to port to
Windows thanks to the use of cmake rather than libtool to create shared
libraries.

The only modification to the main source tree is some conditional-compiled
additions to yasm.c.

svn path=/trunk/yasm/; revision=2098
  • Loading branch information...
1 parent 811d7ad commit b7f2fbc64fcfe8e30650a32e3354613aceaceb0c @PeterJohnson PeterJohnson committed May 22, 2008
Showing with 1,483 additions and 10 deletions.
  1. +47 −0 CMakeLists.txt
  2. +70 −0 ConfigureChecks.cmake
  3. +1 −0 cmake/CMakeLists.txt
  4. +2 −0 cmake/modules/CMakeLists.txt
  5. +4 −0 cmake/modules/DummyCFile.c
  6. +89 −0 cmake/modules/YasmMacros.cmake
  7. +51 −0 config.h.cmake
  8. +1 −0 frontends/CMakeLists.txt
  9. +26 −0 frontends/yasm/CMakeLists.txt
  10. +41 −0 frontends/yasm/genstring.py
  11. +119 −0 frontends/yasm/yasm-plugin.c
  12. +34 −0 frontends/yasm/yasm-plugin.h
  13. +43 −10 frontends/yasm/yasm.c
  14. +20 −0 libyasm-stdint.h.cmake
  15. +70 −0 libyasm/CMakeLists.txt
  16. +127 −0 libyasm/cmake-module.c
  17. +89 −0 modules/CMakeLists.txt
  18. +2 −0 modules/arch/CMakeLists.txt
  19. +11 −0 modules/arch/lc3b/CMakeLists.txt
  20. +50 −0 modules/arch/x86/CMakeLists.txt
  21. +4 −0 modules/dbgfmts/CMakeLists.txt
  22. +5 −0 modules/dbgfmts/codeview/CMakeLists.txt
  23. +6 −0 modules/dbgfmts/dwarf2/CMakeLists.txt
  24. +3 −0 modules/dbgfmts/null/CMakeLists.txt
  25. +3 −0 modules/dbgfmts/stabs/CMakeLists.txt
  26. +1 −0 modules/listfmts/CMakeLists.txt
  27. +3 −0 modules/listfmts/nasm/CMakeLists.txt
  28. +9 −0 modules/objfmts/CMakeLists.txt
  29. +3 −0 modules/objfmts/bin/CMakeLists.txt
  30. +27 −0 modules/objfmts/coff/CMakeLists.txt
  31. +3 −0 modules/objfmts/dbg/CMakeLists.txt
  32. +8 −0 modules/objfmts/elf/CMakeLists.txt
  33. +5 −0 modules/objfmts/macho/CMakeLists.txt
  34. +3 −0 modules/objfmts/rdf/CMakeLists.txt
  35. +3 −0 modules/objfmts/xdf/CMakeLists.txt
  36. +2 −0 modules/parsers/CMakeLists.txt
  37. +11 −0 modules/parsers/gas/CMakeLists.txt
  38. +21 −0 modules/parsers/nasm/CMakeLists.txt
  39. +3 −0 modules/preprocs/CMakeLists.txt
  40. +3 −0 modules/preprocs/cpp/CMakeLists.txt
  41. +25 −0 modules/preprocs/nasm/CMakeLists.txt
  42. +3 −0 modules/preprocs/raw/CMakeLists.txt
  43. +20 −0 plugins/README
  44. +45 −0 plugins/dbg/CMakeLists.txt
  45. +15 −0 plugins/dbg/README
  46. +175 −0 plugins/dbg/dbg-objfmt.c
  47. +13 −0 plugins/dbg/init_plugin.c
  48. +117 −0 plugins/x86/CMakeLists.txt
  49. +10 −0 plugins/x86/README
  50. +13 −0 plugins/x86/init_plugin.c
  51. +3 −0 tools/CMakeLists.txt
  52. +3 −0 tools/genmacro/CMakeLists.txt
  53. +7 −0 tools/genperf/CMakeLists.txt
  54. +11 −0 tools/re2c/CMakeLists.txt
View
@@ -0,0 +1,47 @@
+PROJECT(yasm)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
+
+SET(BUILD_SHARED_LIBS ON)
+
+# Where to look first for cmake modules
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
+
+INCLUDE(YasmMacros)
+
+OPTION(ENABLE_NLS "Enable message translations" OFF)
+
+OPTION(YASM_BUILD_TESTS "Enable building of tests" ON)
+
+IF(YASM_BUILD_TESTS)
+ ENABLE_TESTING()
+ENDIF(YASM_BUILD_TESTS)
+
+# Default build type to debug if not set
+IF(NOT CMAKE_BUILD_TYPE)
+ SET(CMAKE_BUILD_TYPE Debug CACHE STRING
+ "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
+ FORCE)
+ENDIF(NOT CMAKE_BUILD_TYPE)
+
+set (YASM_VERSION_MAJOR 0)
+set (YASM_VERSION_MINOR 6)
+set (YASM_VERSION_SUBMINOR 99)
+set (PACKAGE_INTVER "${YASM_VERSION_MAJOR}.${YASM_VERSION_MINOR}.${YASM_VERSION_SUBMINOR}")
+set (PACKAGE_BUILD "HEAD")
+set (PACKAGE_VERSION ${PACKAGE_BUILD})
+set (PACKAGE_STRING "yasm ${PACKAGE_VERSION}")
+
+INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${yasm_SOURCE_DIR})
+
+INCLUDE(ConfigureChecks.cmake)
+
+ADD_SUBDIRECTORY(tools)
+ADD_SUBDIRECTORY(libyasm)
+ADD_SUBDIRECTORY(modules)
+ADD_SUBDIRECTORY(frontends)
+
+INSTALL(FILES
+ libyasm.h
+ ${CMAKE_BINARY_DIR}/libyasm-stdint.h
+ DESTINATION include
+ )
View
@@ -0,0 +1,70 @@
+INCLUDE(CheckCSourceCompiles)
+INCLUDE(CheckCCompilerFlag)
+INCLUDE(CheckFunctionExists)
+INCLUDE(CheckIncludeFile)
+INCLUDE(CheckSymbolExists)
+INCLUDE(CheckTypeSize)
+INCLUDE(CheckLibraryExists)
+
+FIND_PROGRAM(CPP_PROG NAMES cpp)
+
+# Platform-specific include files (POSIX, Win32)
+CHECK_INCLUDE_FILE(locale.h HAVE_LOCALE_H)
+CHECK_INCLUDE_FILE(libgen.h HAVE_LIBGEN_H)
+CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
+CHECK_INCLUDE_FILE(direct.h HAVE_DIRECT_H)
+CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
+
+CHECK_SYMBOL_EXISTS(abort "stdlib.h" HAVE_ABORT)
+
+CHECK_FUNCTION_EXISTS(getcwd HAVE_GETCWD)
+CHECK_FUNCTION_EXISTS(toascii HAVE_TOASCII)
+
+CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
+
+IF (HAVE_LIBDL)
+ SET(LIBDL "dl")
+ELSE (HAVE_LIBDL)
+ SET(LIBDL "")
+ENDIF (HAVE_LIBDL)
+
+CONFIGURE_FILE(libyasm-stdint.h.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/libyasm-stdint.h)
+CONFIGURE_FILE(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+ADD_DEFINITIONS(-DHAVE_CONFIG_H)
+INCLUDE(FindPythonInterp)
+
+IF (CMAKE_COMPILER_IS_GNUCXX)
+ CHECK_C_COMPILER_FLAG(-pipe C_ACCEPTS_PIPE)
+ CHECK_C_COMPILER_FLAG(-ansi C_ACCEPTS_ANSI)
+ CHECK_C_COMPILER_FLAG(-pedantic C_ACCEPTS_PEDANTIC)
+ CHECK_C_COMPILER_FLAG(-Wall C_ACCEPTS_WALL)
+ CHECK_C_COMPILER_FLAG(-Wno-unused-parameter C_ACCEPTS_WNOUNUSEDPARAM)
+
+ IF (C_ACCEPTS_PIPE)
+ ADD_DEFINITIONS(-pipe)
+ ENDIF (C_ACCEPTS_PIPE)
+
+ IF (C_ACCEPTS_ANSI)
+ ADD_DEFINITIONS(-ansi)
+ ENDIF (C_ACCEPTS_ANSI)
+
+ IF (C_ACCEPTS_PEDANTIC)
+ ADD_DEFINITIONS(-pedantic)
+ ENDIF (C_ACCEPTS_PEDANTIC)
+
+ IF (C_ACCEPTS_WALL)
+ ADD_DEFINITIONS(-Wall)
+ ENDIF (C_ACCEPTS_WALL)
+
+ IF (C_ACCEPTS_WNOUNUSEDPARAM)
+ ADD_DEFINITIONS(-Wno-unused-parameter)
+ ENDIF (C_ACCEPTS_WNOUNUSEDPARAM)
+ENDIF (CMAKE_COMPILER_IS_GNUCXX)
+
+# Disable some annoying Visual Studio warnings
+IF (MSVC)
+ ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
+ ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS)
+ENDIF (MSVC)
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(modules)
@@ -0,0 +1,2 @@
+FILE(GLOB cmakeFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.cmake")
+
@@ -0,0 +1,4 @@
+int main()
+{
+ return 0;
+}
@@ -0,0 +1,89 @@
+# Portions based on kdelibs KDE4Macros.cmake:
+#
+# Copyright (c) 2006, 2007, Alexander Neundorf, <neundorf@kde.org>
+# Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
+# Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+#
+# Changes for Yasm Copyright (c) 2007 Peter Johnson
+
+# add a unit test, which is executed when running make test
+# it will be built with RPATH pointing to the build dir
+# The targets are always created, but only built for the "all"
+# target if the option YASM_BUILD_TESTS is enabled. Otherwise the rules for
+# the target are created but not built by default. You can build them by
+# manually building the target.
+# The name of the target can be specified using TESTNAME <testname>, if it is
+# not given the macro will default to the <name>
+macro (YASM_ADD_UNIT_TEST _test_NAME)
+ set(_srcList ${ARGN})
+ set(_targetName ${_test_NAME})
+ if( ${ARGV1} STREQUAL "TESTNAME" )
+ set(_targetName ${ARGV2})
+ LIST(REMOVE_AT _srcList 0 1)
+ endif( ${ARGV1} STREQUAL "TESTNAME" )
+ yasm_add_test_executable( ${_test_NAME} ${_srcList} )
+ add_test( ${_targetName} ${EXECUTABLE_OUTPUT_PATH}/${_test_NAME} )
+endmacro (YASM_ADD_UNIT_TEST)
+
+# add an test executable
+# it will be built with RPATH pointing to the build dir
+# The targets are always created, but only built for the "all"
+# target if the option YASM_BUILD_TESTS is enabled. Otherwise the rules for
+# the target are created but not built by default. You can build them by
+# manually building the target.
+macro (YASM_ADD_TEST_EXECUTABLE _target_NAME)
+
+ set(_add_executable_param)
+
+ if (NOT YASM_BUILD_TESTS)
+ set(_add_executable_param EXCLUDE_FROM_ALL)
+ endif (NOT YASM_BUILD_TESTS)
+
+ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
+
+ set(_SRCS ${ARGN})
+ add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS})
+
+ set_target_properties(${_target_NAME} PROPERTIES
+ SKIP_BUILD_RPATH FALSE
+ BUILD_WITH_INSTALL_RPATH FALSE)
+
+endmacro (YASM_ADD_TEST_EXECUTABLE)
+
+macro (YASM_ADD_MODULE _module_NAME)
+ list(APPEND YASM_MODULES_SRC ${ARGN})
+ list(APPEND YASM_MODULES ${_module_NAME})
+endmacro (YASM_ADD_MODULE)
+
+macro (YASM_GENPERF _in_NAME _out_NAME)
+ get_target_property(_tmp_GENPERF_EXE genperf LOCATION)
+ add_custom_command(
+ OUTPUT ${_out_NAME}
+ COMMAND ${_tmp_GENPERF_EXE} ${_in_NAME} ${_out_NAME}
+ DEPENDS ${_tmp_GENPERF_EXE}
+ MAIN_DEPENDENCY ${_in_NAME}
+ )
+endmacro (YASM_GENPERF)
+
+macro (YASM_RE2C _in_NAME _out_NAME)
+ get_target_property(_tmp_RE2C_EXE re2c LOCATION)
+ add_custom_command(
+ OUTPUT ${_out_NAME}
+ COMMAND ${_tmp_RE2C_EXE} ${ARGN} -o ${_out_NAME} ${_in_NAME}
+ DEPENDS ${_tmp_RE2C_EXE}
+ MAIN_DEPENDENCY ${_in_NAME}
+ )
+endmacro (YASM_RE2C)
+
+macro (YASM_GENMACRO _in_NAME _out_NAME _var_NAME)
+ get_target_property(_tmp_GENMACRO_EXE genmacro LOCATION)
+ add_custom_command(
+ OUTPUT ${_out_NAME}
+ COMMAND ${_tmp_GENMACRO_EXE} ${_out_NAME} ${_var_NAME} ${_in_NAME}
+ DEPENDS ${_tmp_GENMACRO_EXE}
+ MAIN_DEPENDENCY ${_in_NAME}
+ )
+endmacro (YASM_GENMACRO)
+
View
@@ -0,0 +1,51 @@
+/* config.h. Generated by cmake from config.h.cmake */
+
+#define CMAKE_BUILD 1
+
+/* Define if messsage translations are enabled */
+#cmakedefine ENABLE_NLS 1
+
+/* */
+#undef HAVE_GETTEXT
+
+/* Define to 1 if you have the <libgen.h> header file. */
+#cmakedefine HAVE_LIBGEN_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#cmakedefine HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the <direct.h> header file. */
+#cmakedefine HAVE_DIRECT_H 1
+
+/* Define to 1 if you have the `getcwd' function. */
+#cmakedefine HAVE_GETCWD 1
+
+/* Define to 1 if you have the `toascii' function. */
+#cmakedefine HAVE_TOASCII 1
+
+/* Name of package */
+#define PACKAGE "yasm"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "bug-yasm@tortall.net"
+
+/* Define to internal version of this package. */
+#define PACKAGE_INTVER "@PACKAGE_INTVER@"
+
+/* Define to build version of this package. */
+#define PACKAGE_BUILD "@PACKAGE_BUILD@"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "yasm"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "@PACKAGE_STRING@"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "@PACKAGE_VERSION@"
+
+#define VERSION PACKAGE_VERSION
+
+/* Command name to run C preprocessor */
+#define CPP_PROG "@CPP_PROG@"
+
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(yasm)
@@ -0,0 +1,26 @@
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/license.c
+ COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genstring.py
+ license_msg
+ ${CMAKE_CURRENT_BINARY_DIR}/license.c
+ ${CMAKE_SOURCE_DIR}/COPYING
+ MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/COPYING
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/genstring.py
+ )
+
+SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
+
+ADD_EXECUTABLE(yasm
+ yasm.c
+ yasm-options.c
+ yasm-plugin.c
+ )
+TARGET_LINK_LIBRARIES(yasm libyasm ${LIBDL})
+
+SET_SOURCE_FILES_PROPERTIES(yasm.c PROPERTIES
+ OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/license.c
+ )
+
+INSTALL(TARGETS yasm RUNTIME DESTINATION bin)
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+# Generate array-of-const-string from text file.
+#
+# Copyright (C) 2006-2007 Peter Johnson
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+def file_to_string(fout, str_name, fin_name):
+ from os.path import basename
+ print >>fout, "/* This file auto-generated from %s by genstring.py - don't edit it */\n" % basename(fin_name)
+ print >>fout, "static const char* %s[] = {" % str_name
+ print >>fout, "\n".join(' "%s",' %
+ l.strip().replace('\\', '\\\\').replace('"', '\\"')
+ for l in open(fin_name))
+ print >>fout, "};"
+
+if __name__ == "__main__":
+ import sys
+ if len(sys.argv) != 4:
+ print >>sys.stderr, "Usage: genstring.py <string> <outfile> <file>"
+ sys.exit(2)
+ file_to_string(open(sys.argv[2], "w"), sys.argv[1], sys.argv[3])
Oops, something went wrong. Retry.

0 comments on commit b7f2fbc

Please sign in to comment.