Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit b7f2fbc64fcfe8e30650a32e3354613aceaceb0c 1 parent 811d7ad
Peter Johnson authored May 22, 2008

Showing 54 changed files with 1,483 additions and 10 deletions. Show diff stats Hide diff stats

  1. 47  CMakeLists.txt
  2. 70  ConfigureChecks.cmake
  3. 1  cmake/CMakeLists.txt
  4. 2  cmake/modules/CMakeLists.txt
  5. 4  cmake/modules/DummyCFile.c
  6. 89  cmake/modules/YasmMacros.cmake
  7. 51  config.h.cmake
  8. 1  frontends/CMakeLists.txt
  9. 26  frontends/yasm/CMakeLists.txt
  10. 41  frontends/yasm/genstring.py
  11. 119  frontends/yasm/yasm-plugin.c
  12. 34  frontends/yasm/yasm-plugin.h
  13. 53  frontends/yasm/yasm.c
  14. 20  libyasm-stdint.h.cmake
  15. 70  libyasm/CMakeLists.txt
  16. 127  libyasm/cmake-module.c
  17. 89  modules/CMakeLists.txt
  18. 2  modules/arch/CMakeLists.txt
  19. 11  modules/arch/lc3b/CMakeLists.txt
  20. 50  modules/arch/x86/CMakeLists.txt
  21. 4  modules/dbgfmts/CMakeLists.txt
  22. 5  modules/dbgfmts/codeview/CMakeLists.txt
  23. 6  modules/dbgfmts/dwarf2/CMakeLists.txt
  24. 3  modules/dbgfmts/null/CMakeLists.txt
  25. 3  modules/dbgfmts/stabs/CMakeLists.txt
  26. 1  modules/listfmts/CMakeLists.txt
  27. 3  modules/listfmts/nasm/CMakeLists.txt
  28. 9  modules/objfmts/CMakeLists.txt
  29. 3  modules/objfmts/bin/CMakeLists.txt
  30. 27  modules/objfmts/coff/CMakeLists.txt
  31. 3  modules/objfmts/dbg/CMakeLists.txt
  32. 8  modules/objfmts/elf/CMakeLists.txt
  33. 5  modules/objfmts/macho/CMakeLists.txt
  34. 3  modules/objfmts/rdf/CMakeLists.txt
  35. 3  modules/objfmts/xdf/CMakeLists.txt
  36. 2  modules/parsers/CMakeLists.txt
  37. 11  modules/parsers/gas/CMakeLists.txt
  38. 21  modules/parsers/nasm/CMakeLists.txt
  39. 3  modules/preprocs/CMakeLists.txt
  40. 3  modules/preprocs/cpp/CMakeLists.txt
  41. 25  modules/preprocs/nasm/CMakeLists.txt
  42. 3  modules/preprocs/raw/CMakeLists.txt
  43. 20  plugins/README
  44. 45  plugins/dbg/CMakeLists.txt
  45. 15  plugins/dbg/README
  46. 175  plugins/dbg/dbg-objfmt.c
  47. 13  plugins/dbg/init_plugin.c
  48. 117  plugins/x86/CMakeLists.txt
  49. 10  plugins/x86/README
  50. 13  plugins/x86/init_plugin.c
  51. 3  tools/CMakeLists.txt
  52. 3  tools/genmacro/CMakeLists.txt
  53. 7  tools/genperf/CMakeLists.txt
  54. 11  tools/re2c/CMakeLists.txt
47  CMakeLists.txt
... ...
@@ -0,0 +1,47 @@
  1
+PROJECT(yasm)
  2
+CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
  3
+
  4
+SET(BUILD_SHARED_LIBS ON)
  5
+
  6
+# Where to look first for cmake modules
  7
+set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
  8
+
  9
+INCLUDE(YasmMacros)
  10
+
  11
+OPTION(ENABLE_NLS "Enable message translations" OFF)
  12
+
  13
+OPTION(YASM_BUILD_TESTS "Enable building of tests" ON)
  14
+
  15
+IF(YASM_BUILD_TESTS)
  16
+    ENABLE_TESTING()
  17
+ENDIF(YASM_BUILD_TESTS)
  18
+
  19
+# Default build type to debug if not set
  20
+IF(NOT CMAKE_BUILD_TYPE)
  21
+  SET(CMAKE_BUILD_TYPE Debug CACHE STRING
  22
+      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
  23
+      FORCE)
  24
+ENDIF(NOT CMAKE_BUILD_TYPE)
  25
+
  26
+set (YASM_VERSION_MAJOR 0)
  27
+set (YASM_VERSION_MINOR 6)
  28
+set (YASM_VERSION_SUBMINOR 99)
  29
+set (PACKAGE_INTVER "${YASM_VERSION_MAJOR}.${YASM_VERSION_MINOR}.${YASM_VERSION_SUBMINOR}")
  30
+set (PACKAGE_BUILD "HEAD")
  31
+set (PACKAGE_VERSION ${PACKAGE_BUILD})
  32
+set (PACKAGE_STRING "yasm ${PACKAGE_VERSION}")
  33
+
  34
+INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${yasm_SOURCE_DIR})
  35
+
  36
+INCLUDE(ConfigureChecks.cmake)
  37
+
  38
+ADD_SUBDIRECTORY(tools)
  39
+ADD_SUBDIRECTORY(libyasm)
  40
+ADD_SUBDIRECTORY(modules)
  41
+ADD_SUBDIRECTORY(frontends)
  42
+
  43
+INSTALL(FILES
  44
+    libyasm.h
  45
+    ${CMAKE_BINARY_DIR}/libyasm-stdint.h
  46
+    DESTINATION include
  47
+    )
70  ConfigureChecks.cmake
... ...
@@ -0,0 +1,70 @@
  1
+INCLUDE(CheckCSourceCompiles)
  2
+INCLUDE(CheckCCompilerFlag)
  3
+INCLUDE(CheckFunctionExists)
  4
+INCLUDE(CheckIncludeFile)
  5
+INCLUDE(CheckSymbolExists)
  6
+INCLUDE(CheckTypeSize)
  7
+INCLUDE(CheckLibraryExists)
  8
+
  9
+FIND_PROGRAM(CPP_PROG NAMES cpp)
  10
+
  11
+# Platform-specific include files (POSIX, Win32)
  12
+CHECK_INCLUDE_FILE(locale.h HAVE_LOCALE_H)
  13
+CHECK_INCLUDE_FILE(libgen.h HAVE_LIBGEN_H)
  14
+CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
  15
+CHECK_INCLUDE_FILE(direct.h HAVE_DIRECT_H)
  16
+CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H)
  17
+
  18
+CHECK_SYMBOL_EXISTS(abort "stdlib.h" HAVE_ABORT)
  19
+
  20
+CHECK_FUNCTION_EXISTS(getcwd HAVE_GETCWD)
  21
+CHECK_FUNCTION_EXISTS(toascii HAVE_TOASCII)
  22
+
  23
+CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_LIBDL)
  24
+
  25
+IF (HAVE_LIBDL)
  26
+    SET(LIBDL "dl")
  27
+ELSE (HAVE_LIBDL)
  28
+    SET(LIBDL "")
  29
+ENDIF (HAVE_LIBDL)
  30
+
  31
+CONFIGURE_FILE(libyasm-stdint.h.cmake
  32
+               ${CMAKE_CURRENT_BINARY_DIR}/libyasm-stdint.h)
  33
+CONFIGURE_FILE(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
  34
+
  35
+ADD_DEFINITIONS(-DHAVE_CONFIG_H)
  36
+INCLUDE(FindPythonInterp)
  37
+
  38
+IF (CMAKE_COMPILER_IS_GNUCXX)
  39
+    CHECK_C_COMPILER_FLAG(-pipe C_ACCEPTS_PIPE)
  40
+    CHECK_C_COMPILER_FLAG(-ansi C_ACCEPTS_ANSI)
  41
+    CHECK_C_COMPILER_FLAG(-pedantic C_ACCEPTS_PEDANTIC)
  42
+    CHECK_C_COMPILER_FLAG(-Wall C_ACCEPTS_WALL)
  43
+    CHECK_C_COMPILER_FLAG(-Wno-unused-parameter C_ACCEPTS_WNOUNUSEDPARAM)
  44
+
  45
+    IF (C_ACCEPTS_PIPE)
  46
+        ADD_DEFINITIONS(-pipe)
  47
+    ENDIF (C_ACCEPTS_PIPE)
  48
+
  49
+    IF (C_ACCEPTS_ANSI)
  50
+        ADD_DEFINITIONS(-ansi)
  51
+    ENDIF (C_ACCEPTS_ANSI)
  52
+
  53
+    IF (C_ACCEPTS_PEDANTIC)
  54
+        ADD_DEFINITIONS(-pedantic)
  55
+    ENDIF (C_ACCEPTS_PEDANTIC)
  56
+
  57
+    IF (C_ACCEPTS_WALL)
  58
+        ADD_DEFINITIONS(-Wall)
  59
+    ENDIF (C_ACCEPTS_WALL)
  60
+
  61
+    IF (C_ACCEPTS_WNOUNUSEDPARAM)
  62
+        ADD_DEFINITIONS(-Wno-unused-parameter)
  63
+    ENDIF (C_ACCEPTS_WNOUNUSEDPARAM)
  64
+ENDIF (CMAKE_COMPILER_IS_GNUCXX)
  65
+
  66
+# Disable some annoying Visual Studio warnings
  67
+IF (MSVC)
  68
+    ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
  69
+    ADD_DEFINITIONS(-D_CRT_NONSTDC_NO_WARNINGS)
  70
+ENDIF (MSVC)
1  cmake/CMakeLists.txt
... ...
@@ -0,0 +1 @@
  1
+ADD_SUBDIRECTORY(modules)
2  cmake/modules/CMakeLists.txt
... ...
@@ -0,0 +1,2 @@
  1
+FILE(GLOB cmakeFiles "${CMAKE_CURRENT_SOURCE_DIR}/*.cmake")
  2
+
4  cmake/modules/DummyCFile.c
... ...
@@ -0,0 +1,4 @@
  1
+int main()
  2
+{
  3
+  return 0;
  4
+}
89  cmake/modules/YasmMacros.cmake
... ...
@@ -0,0 +1,89 @@
  1
+# Portions based on kdelibs KDE4Macros.cmake:
  2
+#
  3
+# Copyright (c) 2006, 2007, Alexander Neundorf, <neundorf@kde.org>
  4
+# Copyright (c) 2006, 2007, Laurent Montel, <montel@kde.org>
  5
+# Copyright (c) 2007 Matthias Kretz <kretz@kde.org>
  6
+#
  7
+# Redistribution and use is allowed according to the terms of the BSD license.
  8
+#
  9
+# Changes for Yasm Copyright (c) 2007 Peter Johnson
  10
+
  11
+# add a unit test, which is executed when running make test
  12
+# it will be built with RPATH pointing to the build dir
  13
+# The targets are always created, but only built for the "all"
  14
+# target if the option YASM_BUILD_TESTS is enabled. Otherwise the rules for
  15
+# the target are created but not built by default. You can build them by
  16
+# manually building the target.
  17
+# The name of the target can be specified using TESTNAME <testname>, if it is
  18
+# not given the macro will default to the <name>
  19
+macro (YASM_ADD_UNIT_TEST _test_NAME)
  20
+    set(_srcList ${ARGN})
  21
+    set(_targetName ${_test_NAME})
  22
+    if( ${ARGV1} STREQUAL "TESTNAME" )
  23
+        set(_targetName ${ARGV2})
  24
+        LIST(REMOVE_AT _srcList 0 1)
  25
+    endif( ${ARGV1} STREQUAL "TESTNAME" )
  26
+    yasm_add_test_executable( ${_test_NAME} ${_srcList} )
  27
+    add_test( ${_targetName} ${EXECUTABLE_OUTPUT_PATH}/${_test_NAME} )
  28
+endmacro (YASM_ADD_UNIT_TEST)
  29
+
  30
+# add an test executable
  31
+# it will be built with RPATH pointing to the build dir
  32
+# The targets are always created, but only built for the "all"
  33
+# target if the option YASM_BUILD_TESTS is enabled. Otherwise the rules for
  34
+# the target are created but not built by default. You can build them by
  35
+# manually building the target.
  36
+macro (YASM_ADD_TEST_EXECUTABLE _target_NAME)
  37
+
  38
+   set(_add_executable_param)
  39
+
  40
+   if (NOT YASM_BUILD_TESTS)
  41
+      set(_add_executable_param EXCLUDE_FROM_ALL)
  42
+   endif (NOT YASM_BUILD_TESTS)
  43
+
  44
+   set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
  45
+
  46
+   set(_SRCS ${ARGN})
  47
+   add_executable(${_target_NAME} ${_add_executable_param} ${_SRCS})
  48
+
  49
+   set_target_properties(${_target_NAME} PROPERTIES
  50
+                         SKIP_BUILD_RPATH FALSE
  51
+                         BUILD_WITH_INSTALL_RPATH FALSE)
  52
+
  53
+endmacro (YASM_ADD_TEST_EXECUTABLE)
  54
+
  55
+macro (YASM_ADD_MODULE _module_NAME)
  56
+    list(APPEND YASM_MODULES_SRC ${ARGN})
  57
+    list(APPEND YASM_MODULES ${_module_NAME})
  58
+endmacro (YASM_ADD_MODULE)
  59
+
  60
+macro (YASM_GENPERF _in_NAME _out_NAME)
  61
+    get_target_property(_tmp_GENPERF_EXE genperf LOCATION)
  62
+    add_custom_command(
  63
+        OUTPUT ${_out_NAME}
  64
+        COMMAND ${_tmp_GENPERF_EXE} ${_in_NAME} ${_out_NAME}
  65
+        DEPENDS ${_tmp_GENPERF_EXE}
  66
+        MAIN_DEPENDENCY ${_in_NAME}
  67
+        )
  68
+endmacro (YASM_GENPERF)
  69
+
  70
+macro (YASM_RE2C _in_NAME _out_NAME)
  71
+    get_target_property(_tmp_RE2C_EXE re2c LOCATION)
  72
+    add_custom_command(
  73
+        OUTPUT ${_out_NAME}
  74
+        COMMAND ${_tmp_RE2C_EXE} ${ARGN} -o ${_out_NAME} ${_in_NAME}
  75
+        DEPENDS ${_tmp_RE2C_EXE}
  76
+        MAIN_DEPENDENCY ${_in_NAME}
  77
+        )
  78
+endmacro (YASM_RE2C)
  79
+
  80
+macro (YASM_GENMACRO _in_NAME _out_NAME _var_NAME)
  81
+    get_target_property(_tmp_GENMACRO_EXE genmacro LOCATION)
  82
+    add_custom_command(
  83
+        OUTPUT ${_out_NAME}
  84
+        COMMAND ${_tmp_GENMACRO_EXE} ${_out_NAME} ${_var_NAME} ${_in_NAME}
  85
+        DEPENDS ${_tmp_GENMACRO_EXE}
  86
+        MAIN_DEPENDENCY ${_in_NAME}
  87
+        )
  88
+endmacro (YASM_GENMACRO)
  89
+
51  config.h.cmake
... ...
@@ -0,0 +1,51 @@
  1
+/* config.h.  Generated by cmake from config.h.cmake */
  2
+
  3
+#define CMAKE_BUILD 1
  4
+
  5
+/* Define if messsage translations are enabled */
  6
+#cmakedefine ENABLE_NLS 1
  7
+
  8
+/* */
  9
+#undef HAVE_GETTEXT
  10
+
  11
+/* Define to 1 if you have the <libgen.h> header file. */
  12
+#cmakedefine HAVE_LIBGEN_H 1
  13
+
  14
+/* Define to 1 if you have the <unistd.h> header file. */
  15
+#cmakedefine HAVE_UNISTD_H 1
  16
+
  17
+/* Define to 1 if you have the <direct.h> header file. */
  18
+#cmakedefine HAVE_DIRECT_H 1
  19
+
  20
+/* Define to 1 if you have the `getcwd' function. */
  21
+#cmakedefine HAVE_GETCWD 1
  22
+
  23
+/* Define to 1 if you have the `toascii' function. */
  24
+#cmakedefine HAVE_TOASCII 1
  25
+
  26
+/* Name of package */
  27
+#define PACKAGE "yasm"
  28
+
  29
+/* Define to the address where bug reports for this package should be sent. */
  30
+#define PACKAGE_BUGREPORT "bug-yasm@tortall.net"
  31
+
  32
+/* Define to internal version of this package. */
  33
+#define PACKAGE_INTVER "@PACKAGE_INTVER@"
  34
+
  35
+/* Define to build version of this package. */
  36
+#define PACKAGE_BUILD "@PACKAGE_BUILD@"
  37
+
  38
+/* Define to the full name of this package. */
  39
+#define PACKAGE_NAME "yasm"
  40
+
  41
+/* Define to the full name and version of this package. */
  42
+#define PACKAGE_STRING "@PACKAGE_STRING@"
  43
+
  44
+/* Define to the version of this package. */
  45
+#define PACKAGE_VERSION "@PACKAGE_VERSION@"
  46
+
  47
+#define VERSION PACKAGE_VERSION
  48
+
  49
+/* Command name to run C preprocessor */
  50
+#define CPP_PROG "@CPP_PROG@"
  51
+
1  frontends/CMakeLists.txt
... ...
@@ -0,0 +1 @@
  1
+ADD_SUBDIRECTORY(yasm)
26  frontends/yasm/CMakeLists.txt
... ...
@@ -0,0 +1,26 @@
  1
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
  2
+
  3
+ADD_CUSTOM_COMMAND(
  4
+    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/license.c
  5
+    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/genstring.py
  6
+        license_msg
  7
+        ${CMAKE_CURRENT_BINARY_DIR}/license.c
  8
+        ${CMAKE_SOURCE_DIR}/COPYING
  9
+    MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/COPYING
  10
+    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/genstring.py
  11
+    )
  12
+
  13
+SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
  14
+
  15
+ADD_EXECUTABLE(yasm
  16
+    yasm.c
  17
+    yasm-options.c
  18
+    yasm-plugin.c
  19
+    )
  20
+TARGET_LINK_LIBRARIES(yasm libyasm ${LIBDL})
  21
+
  22
+SET_SOURCE_FILES_PROPERTIES(yasm.c PROPERTIES
  23
+    OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/license.c
  24
+    )
  25
+
  26
+INSTALL(TARGETS yasm RUNTIME DESTINATION bin)
41  frontends/yasm/genstring.py
... ...
@@ -0,0 +1,41 @@
  1
+#!/usr/bin/env python
  2
+# Generate array-of-const-string from text file.
  3
+#
  4
+#  Copyright (C) 2006-2007  Peter Johnson
  5
+#
  6
+# Redistribution and use in source and binary forms, with or without
  7
+# modification, are permitted provided that the following conditions
  8
+# are met:
  9
+# 1. Redistributions of source code must retain the above copyright
  10
+#    notice, this list of conditions and the following disclaimer.
  11
+# 2. Redistributions in binary form must reproduce the above copyright
  12
+#    notice, this list of conditions and the following disclaimer in the
  13
+#    documentation and/or other materials provided with the distribution.
  14
+#
  15
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  16
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  19
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25
+# POSSIBILITY OF SUCH DAMAGE.
  26
+
  27
+def file_to_string(fout, str_name, fin_name):
  28
+    from os.path import basename
  29
+    print >>fout, "/* This file auto-generated from %s by genstring.py - don't edit it */\n" % basename(fin_name)
  30
+    print >>fout, "static const char* %s[] = {" % str_name
  31
+    print >>fout, "\n".join('    "%s",' %
  32
+                            l.strip().replace('\\', '\\\\').replace('"', '\\"')
  33
+                            for l in open(fin_name))
  34
+    print >>fout, "};"
  35
+
  36
+if __name__ == "__main__":
  37
+    import sys
  38
+    if len(sys.argv) != 4:
  39
+        print >>sys.stderr, "Usage: genstring.py <string> <outfile> <file>"
  40
+        sys.exit(2)
  41
+    file_to_string(open(sys.argv[2], "w"), sys.argv[1], sys.argv[3])
119  frontends/yasm/yasm-plugin.c
... ...
@@ -0,0 +1,119 @@
  1
+/*
  2
+ * Semi-portable (Windows and Unix) plugin loading
  3
+ *
  4
+ *  Copyright (C) 2008  Peter Johnson
  5
+ *
  6
+ * Redistribution and use in source and binary forms, with or without
  7
+ * modification, are permitted provided that the following conditions
  8
+ * are met:
  9
+ * 1. Redistributions of source code must retain the above copyright
  10
+ *    notice, this list of conditions and the following disclaimer.
  11
+ * 2. Redistributions in binary form must reproduce the above copyright
  12
+ *    notice, this list of conditions and the following disclaimer in the
  13
+ *    documentation and/or other materials provided with the distribution.
  14
+ *
  15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  16
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  19
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25
+ * POSSIBILITY OF SUCH DAMAGE.
  26
+ */
  27
+#include <util.h>
  28
+/*@unused@*/ RCSID("$Id$");
  29
+
  30
+#include <string.h>
  31
+
  32
+#include "yasm-plugin.h"
  33
+
  34
+#if defined(_MSC_VER)
  35
+#include <windows.h>
  36
+#elif defined(__GNUC__)
  37
+#include <dlfcn.h>
  38
+#endif
  39
+
  40
+static void **loaded_plugins = NULL;
  41
+static int num_loaded_plugins = 0;
  42
+
  43
+static void *
  44
+load_dll(const char *name)
  45
+{
  46
+#if defined(_MSC_VER)
  47
+    return LoadLibrary(name);
  48
+#elif defined(__GNUC__)
  49
+    return dlopen(name, RTLD_NOW);
  50
+#else
  51
+    return NULL;
  52
+#endif
  53
+}
  54
+
  55
+int
  56
+load_plugin(const char *name)
  57
+{
  58
+    char *path;
  59
+    void *lib = NULL;
  60
+    void (*init_plugin) (void) = NULL;
  61
+
  62
+    /* Load library */
  63
+
  64
+    path = yasm_xmalloc(strlen(name)+5);
  65
+    strcpy(path, name);
  66
+#if defined(_MSC_VER)
  67
+    strcat(path, ".dll");
  68
+    lib = load_dll(path);
  69
+#elif defined(__GNUC__)
  70
+    strcat(path, ".so");
  71
+    lib = load_dll(path);
  72
+#endif
  73
+    yasm_xfree(path);
  74
+    if (!lib)
  75
+        lib = load_dll(name);
  76
+
  77
+    if (!lib)
  78
+        return 0;       /* Didn't load successfully */
  79
+
  80
+    /* Add to array of loaded plugins */
  81
+    loaded_plugins =
  82
+        yasm_xrealloc(loaded_plugins, (num_loaded_plugins+1)*sizeof(void *));
  83
+    loaded_plugins[num_loaded_plugins] = lib;
  84
+    num_loaded_plugins++;
  85
+
  86
+    /* Get yasm_init_plugin() function and run it */
  87
+
  88
+#if defined(_MSC_VER)
  89
+    init_plugin =
  90
+        (void (*)(void))GetProcAddress((HINSTANCE)lib, "yasm_init_plugin");
  91
+#elif defined(__GNUC__)
  92
+    init_plugin = (void (*)(void))dlsym(lib, "yasm_init_plugin");
  93
+#endif
  94
+
  95
+    if (!init_plugin)
  96
+        return 0;       /* Didn't load successfully */
  97
+
  98
+    init_plugin();
  99
+    return 1;
  100
+}
  101
+
  102
+void
  103
+unload_plugins(void)
  104
+{
  105
+    int i;
  106
+
  107
+    if (!loaded_plugins)
  108
+        return;
  109
+
  110
+    for (i = 0; i < num_loaded_plugins; i++) {
  111
+#if defined(_MSC_VER)
  112
+        FreeLibrary((HINSTANCE)loaded_plugins[i]);
  113
+#elif defined(__GNUC__)
  114
+        dlclose(loaded_plugins[i]);
  115
+#endif
  116
+    }
  117
+    yasm_xfree(loaded_plugins);
  118
+    num_loaded_plugins = 0;
  119
+}
34  frontends/yasm/yasm-plugin.h
... ...
@@ -0,0 +1,34 @@
  1
+/*
  2
+ * Semi-portable (Windows and Unix) plugin loading
  3
+ *
  4
+ *  Copyright (C) 2008  Peter Johnson
  5
+ *
  6
+ * Redistribution and use in source and binary forms, with or without
  7
+ * modification, are permitted provided that the following conditions
  8
+ * are met:
  9
+ * 1. Redistributions of source code must retain the above copyright
  10
+ *    notice, this list of conditions and the following disclaimer.
  11
+ * 2. Redistributions in binary form must reproduce the above copyright
  12
+ *    notice, this list of conditions and the following disclaimer in the
  13
+ *    documentation and/or other materials provided with the distribution.
  14
+ *
  15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  16
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  19
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25
+ * POSSIBILITY OF SUCH DAMAGE.
  26
+ */
  27
+#ifndef YASM_PLUGIN_H
  28
+#define YASM_PLUGIN_H
  29
+
  30
+/* Load a plugin.  Returns 0 on failure. */
  31
+int load_plugin(const char *name);
  32
+void unload_plugins(void);
  33
+
  34
+#endif
53  frontends/yasm/yasm.c
@@ -38,6 +38,10 @@
38 38
 
39 39
 #include "yasm-options.h"
40 40
 
  41
+#ifdef CMAKE_BUILD
  42
+#include "yasm-plugin.h"
  43
+#endif
  44
+
41 45
 #include "license.c"
42 46
 
43 47
 /* Preprocess-only buffer size */
@@ -102,6 +106,9 @@ static int opt_include_option(char *cmd, /*@null@*/ char *param, int extra);
102 106
 static int opt_preproc_option(char *cmd, /*@null@*/ char *param, int extra);
103 107
 static int opt_ewmsg_handler(char *cmd, /*@null@*/ char *param, int extra);
104 108
 static int opt_makedep_handler(char *cmd, /*@null@*/ char *param, int extra);
  109
+#ifdef CMAKE_BUILD
  110
+static int opt_plugin_handler(char *cmd, /*@null@*/ char *param, int extra);
  111
+#endif
105 112
 
106 113
 static /*@only@*/ char *replace_extension(const char *orig, /*@null@*/
107 114
                                           const char *ext, const char *def);
@@ -189,6 +196,10 @@ static opt_option options[] =
189 196
       N_("undefine a macro"), N_("macro") },
190 197
     { 'X', NULL, 1, opt_ewmsg_handler, 0,
191 198
       N_("select error/warning message style (`gnu' or `vc')"), N_("style") },
  199
+#ifdef CMAKE_BUILD
  200
+    { 'N', "plugin", 1, opt_plugin_handler, 0,
  201
+      N_("load plugin module"), N_("plugin") },
  202
+#endif
192 203
 };
193 204
 
194 205
 /* version message */
@@ -560,6 +571,24 @@ main(int argc, char *argv[])
560 571
     yasm_gettext_hook = handle_yasm_gettext;
561 572
     yasm_errwarn_initialize();
562 573
 
  574
+    /* Initialize BitVector (needed for intnum/floatnum). */
  575
+    if (BitVector_Boot() != ErrCode_Ok) {
  576
+        print_error(_("%s: could not initialize BitVector"), _("FATAL"));
  577
+        return EXIT_FAILURE;
  578
+    }
  579
+
  580
+    /* Initialize intnum and floatnum */
  581
+    yasm_intnum_initialize();
  582
+    yasm_floatnum_initialize();
  583
+
  584
+#ifdef CMAKE_BUILD
  585
+    /* Load standard modules */
  586
+    if (!load_plugin("libyasmstd")) {
  587
+        print_error(_("%s: could not load standard modules"), _("FATAL"));
  588
+        return EXIT_FAILURE;
  589
+    }
  590
+#endif
  591
+
563 592
     /* Initialize parameter storage */
564 593
     STAILQ_INIT(&preproc_options);
565 594
 
@@ -591,16 +620,6 @@ main(int argc, char *argv[])
591 620
             return EXIT_FAILURE;
592 621
     }
593 622
 
594  
-    /* Initialize BitVector (needed for intnum/floatnum). */
595  
-    if (BitVector_Boot() != ErrCode_Ok) {
596  
-        print_error(_("%s: could not initialize BitVector"), _("FATAL"));
597  
-        return EXIT_FAILURE;
598  
-    }
599  
-
600  
-    /* Initialize intnum and floatnum */
601  
-    yasm_intnum_initialize();
602  
-    yasm_floatnum_initialize();
603  
-
604 623
     /* If not already specified, default to bin as the object format. */
605 624
     if (!cur_objfmt_module) {
606 625
         if (!objfmt_keyword)
@@ -764,6 +783,9 @@ cleanup(yasm_object *object)
764 783
 
765 784
     if (errfile != stderr && errfile != stdout)
766 785
         fclose(errfile);
  786
+#ifdef CMAKE_BUILD
  787
+    unload_plugins();
  788
+#endif
767 789
 }
768 790
 
769 791
 /*
@@ -1118,6 +1140,17 @@ opt_makedep_handler(/*@unused@*/ char *cmd, /*@unused@*/ char *param,
1118 1140
     return 0;
1119 1141
 }
1120 1142
 
  1143
+#ifdef CMAKE_BUILD
  1144
+static int
  1145
+opt_plugin_handler(/*@unused@*/ char *cmd, char *param,
  1146
+                   /*@unused@*/ int extra)
  1147
+{
  1148
+    if (!load_plugin(param))
  1149
+        print_error(_("warning: could not load plugin `%s'"), param);
  1150
+    return 0;
  1151
+}
  1152
+#endif
  1153
+
1121 1154
 static void
1122 1155
 apply_preproc_builtins()
1123 1156
 {
20  libyasm-stdint.h.cmake
... ...
@@ -0,0 +1,20 @@
  1
+#cmakedefine HAVE_STDINT_H
  2
+
  3
+#ifdef HAVE_STDINT_H
  4
+#include <stdint.h>
  5
+#elif defined(_MSC_VER)
  6
+
  7
+#ifndef _UINTPTR_T_DEFINED
  8
+#ifdef _WIN64
  9
+#include <vadefs.h>
  10
+#else
  11
+typedef unsigned long uintptr_t;
  12
+#endif
  13
+#define _UINTPTR_T_DEFINED
  14
+#endif
  15
+
  16
+#else
  17
+typedef unsigned long uintptr_t;
  18
+#endif
  19
+
  20
+#undef HAVE_STDINT_H
70  libyasm/CMakeLists.txt
... ...
@@ -0,0 +1,70 @@
  1
+SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
  2
+
  3
+ADD_LIBRARY(libyasm SHARED
  4
+    assocdat.c
  5
+    bitvect.c
  6
+    bc-align.c
  7
+    bc-data.c
  8
+    bc-incbin.c
  9
+    bc-org.c
  10
+    bc-reserve.c
  11
+    bytecode.c
  12
+    cmake-module.c
  13
+    errwarn.c
  14
+    expr.c
  15
+    file.c
  16
+    floatnum.c
  17
+    hamt.c
  18
+    insn.c
  19
+    intnum.c
  20
+    inttree.c
  21
+    linemap.c
  22
+    md5.c
  23
+    mergesort.c
  24
+    phash.c
  25
+    section.c
  26
+    strcasecmp.c
  27
+    strsep.c
  28
+    symrec.c
  29
+    valparam.c
  30
+    value.c
  31
+    xmalloc.c
  32
+    xstrdup.c
  33
+    )
  34
+SET_TARGET_PROPERTIES(libyasm PROPERTIES OUTPUT_NAME "yasm")
  35
+
  36
+INSTALL(TARGETS libyasm
  37
+    LIBRARY DESTINATION lib
  38
+    ARCHIVE DESTINATION lib
  39
+    )
  40
+
  41
+INSTALL(FILES
  42
+    arch.h
  43
+    assocdat.h
  44
+    bitvect.h
  45
+    bytecode.h
  46
+    compat-queue.h
  47
+    coretype.h
  48
+    dbgfmt.h
  49
+    errwarn.h
  50
+    expr.h
  51
+    file.h
  52
+    floatnum.h
  53
+    hamt.h
  54
+    insn.h
  55
+    intnum.h
  56
+    inttree.h
  57
+    linemap.h
  58
+    listfmt.h
  59
+    md5.h
  60
+    module.h
  61
+    objfmt.h
  62
+    parser.h
  63
+    phash.h
  64
+    preproc.h
  65
+    section.h
  66
+    symrec.h
  67
+    valparam.h
  68
+    value.h
  69
+    DESTINATION include/libyasm
  70
+    )
127  libyasm/cmake-module.c
... ...
@@ -0,0 +1,127 @@
  1
+/*
  2
+ * YASM module loader
  3
+ *
  4
+ *  Copyright (C) 2004-2007  Peter Johnson
  5
+ *
  6
+ * Redistribution and use in source and binary forms, with or without
  7
+ * modification, are permitted provided that the following conditions
  8
+ * are met:
  9
+ * 1. Redistributions of source code must retain the above copyright
  10
+ *    notice, this list of conditions and the following disclaimer.
  11
+ * 2. Redistributions in binary form must reproduce the above copyright
  12
+ *    notice, this list of conditions and the following disclaimer in the
  13
+ *    documentation and/or other materials provided with the distribution.
  14
+ *
  15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND OTHER CONTRIBUTORS ``AS IS''
  16
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR OTHER CONTRIBUTORS BE
  19
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25
+ * POSSIBILITY OF SUCH DAMAGE.
  26
+ */
  27
+#include <util.h>
  28
+/*@unused@*/ RCSID("$Id: module.in 2080 2008-04-30 04:40:29Z peter $");
  29
+
  30
+#include <libyasm.h>
  31
+
  32
+
  33
+typedef struct loaded_module {
  34
+    const char *keyword;            /* module keyword */
  35
+    void *data;                     /* associated data */
  36
+} loaded_module;
  37
+
  38
+static HAMT *loaded_modules[] = {NULL, NULL, NULL, NULL, NULL, NULL};
  39
+
  40
+static void
  41
+load_module_destroy(/*@only@*/ void *data)
  42
+{
  43
+    /* do nothing */
  44
+}
  45
+
  46
+void *
  47
+yasm_load_module(yasm_module_type type, const char *keyword)
  48
+{
  49
+    if (!loaded_modules[type])
  50
+        return NULL;
  51
+    return HAMT_search(loaded_modules[type], keyword);
  52
+}
  53
+
  54
+void
  55
+yasm_register_module(yasm_module_type type, const char *keyword, void *data)
  56
+{
  57
+    int replace = 1;
  58
+
  59
+    assert(type < sizeof(loaded_modules));
  60
+
  61
+    if (!loaded_modules[type])
  62
+        loaded_modules[type] = HAMT_create(0, yasm_internal_error_);
  63
+
  64
+    HAMT_insert(loaded_modules[type], keyword, data, &replace,
  65
+                load_module_destroy);
  66
+}
  67
+
  68
+typedef struct {
  69
+    yasm_module_type type;
  70
+    void (*printfunc) (const char *name, const char *keyword);
  71
+} list_one_data;
  72
+
  73
+static int
  74
+yasm_list_one_module(void *node, void *d)
  75
+{
  76
+    list_one_data *data = (list_one_data *)d;
  77
+    yasm_arch_module *arch;
  78
+    yasm_dbgfmt_module *dbgfmt;
  79
+    yasm_objfmt_module *objfmt;
  80
+    yasm_listfmt_module *listfmt;
  81
+    yasm_parser_module *parser;
  82
+    yasm_preproc_module *preproc;
  83
+
  84
+    switch (data->type) {
  85
+        case YASM_MODULE_ARCH:
  86
+            arch = node;
  87
+            data->printfunc(arch->name, arch->keyword);
  88
+            break;
  89
+        case YASM_MODULE_DBGFMT:
  90
+            dbgfmt = node;
  91
+            data->printfunc(dbgfmt->name, dbgfmt->keyword);
  92
+            break;
  93
+        case YASM_MODULE_OBJFMT:
  94
+            objfmt = node;
  95
+            data->printfunc(objfmt->name, objfmt->keyword);
  96
+            break;
  97
+        case YASM_MODULE_LISTFMT:
  98
+            listfmt = node;
  99
+            data->printfunc(listfmt->name, listfmt->keyword);
  100
+            break;
  101
+        case YASM_MODULE_PARSER:
  102
+            parser = node;
  103
+            data->printfunc(parser->name, parser->keyword);
  104
+            break;
  105
+        case YASM_MODULE_PREPROC:
  106
+            preproc = node;
  107
+            data->printfunc(preproc->name, preproc->keyword);
  108
+            break;
  109
+    }
  110
+    return 0;
  111
+}
  112
+
  113
+void
  114
+yasm_list_modules(yasm_module_type type,
  115
+                  void (*printfunc) (const char *name, const char *keyword))
  116
+{
  117
+    list_one_data data;
  118
+
  119
+    /* Go through available list, and try to load each one */
  120
+    if (!loaded_modules[type])
  121
+        return;
  122
+
  123
+    data.type = type;
  124
+    data.printfunc = printfunc;
  125
+
  126
+    HAMT_traverse(loaded_modules[type], &data, yasm_list_one_module);
  127
+}
89  modules/CMakeLists.txt
... ...
@@ -0,0 +1,89 @@
  1
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
  2
+
  3
+INCLUDE(arch/CMakeLists.txt)
  4
+INCLUDE(listfmts/CMakeLists.txt)
  5
+INCLUDE(parsers/CMakeLists.txt)
  6
+INCLUDE(preprocs/CMakeLists.txt)
  7
+INCLUDE(dbgfmts/CMakeLists.txt)
  8
+INCLUDE(objfmts/CMakeLists.txt)
  9
+
  10
+MESSAGE(STATUS "Standard modules: ${YASM_MODULES}")
  11
+
  12
+#
  13
+# Generate init_plugin.c
  14
+# This file provides the yasm_init_plugin() function for yasmstd.
  15
+#
  16
+
  17
+SET(INIT_PLUGIN_C ${CMAKE_CURRENT_BINARY_DIR}/init_plugin.c)
  18
+SET(INIT_PLUGIN_C_REV 1)
  19
+
  20
+# Don't regen if no changes; default to regen
  21
+SET(regen_init_plugin_c TRUE)
  22
+IF(EXISTS ${INIT_PLUGIN_C})
  23
+    FILE(READ ${INIT_PLUGIN_C} _old_init_plugin_c)
  24
+    STRING(REGEX MATCHALL "[^\n]*\n" _lines "${_old_init_plugin_c}")
  25
+    #MESSAGE(STATUS "Lines: ${_lines}")
  26
+
  27
+    LIST(GET _lines 0 _line0)
  28
+    STRING(REGEX MATCH "([A-Za-z][A-Za-z0-9_]+[ ]?)+" _old_modules "${_line0}")
  29
+    #MESSAGE(STATUS "Old modules: ${_old_modules}")
  30
+    STRING(REPLACE ";" " " _modules_str "${YASM_MODULES}")
  31
+    STRING(COMPARE EQUAL "${_old_modules}" "${_modules_str} " _modules_match)
  32
+
  33
+    LIST(GET _lines 1 _line1)
  34
+    STRING(REGEX MATCH "rev [0-9]+" _old_modules_rev "${_line1}")
  35
+    #MESSAGE(STATUS "Old modules rev: ${_old_modules_rev}")
  36
+    STRING(COMPARE EQUAL "${_old_modules_rev}" "rev ${INIT_PLUGIN_C_REV}"
  37
+           _modules_rev_match)
  38
+
  39
+    IF(_modules_match AND _modules_rev_match)
  40
+        SET(regen_init_plugin_c FALSE)
  41
+    ENDIF(_modules_match AND _modules_rev_match)
  42
+ENDIF(EXISTS ${INIT_PLUGIN_C})
  43
+
  44
+IF(regen_init_plugin_c)
  45
+    MESSAGE(STATUS "Generating standard plugin initialization file")
  46
+    STRING(REPLACE ";" " " _modules_str "${YASM_MODULES}")
  47
+    FILE(WRITE ${INIT_PLUGIN_C} "/* ${_modules_str} \n")
  48
+    FILE(APPEND ${INIT_PLUGIN_C} "   rev ${INIT_PLUGIN_C_REV}\n")
  49
+    FILE(APPEND ${INIT_PLUGIN_C} " */\n\n")
  50
+    FILE(APPEND ${INIT_PLUGIN_C} "#include <libyasm.h>\n")
  51
+    FILE(APPEND ${INIT_PLUGIN_C} "#include <libyasm/module.h>\n\n")
  52
+    FOREACH(module ${YASM_MODULES})
  53
+        STRING(REGEX MATCHALL "[a-zA-Z][a-zA-Z0-9]+" _modulepath ${module})
  54
+        LIST(GET _modulepath 0 _type)
  55
+        LIST(GET _modulepath 1 _keyword)
  56
+        FILE(APPEND ${INIT_PLUGIN_C}
  57
+             "extern yasm_${_type}_module yasm_${_keyword}_LTX_${_type};\n")
  58
+    ENDFOREACH(module)
  59
+    FILE(APPEND ${INIT_PLUGIN_C} "\n#ifdef _MSC_VER\n")
  60
+    FILE(APPEND ${INIT_PLUGIN_C} "__declspec(dllexport)\n")
  61
+    FILE(APPEND ${INIT_PLUGIN_C} "#endif\n")
  62
+    FILE(APPEND ${INIT_PLUGIN_C} "void\n")
  63
+    FILE(APPEND ${INIT_PLUGIN_C} "yasm_init_plugin(void)\n")
  64
+    FILE(APPEND ${INIT_PLUGIN_C} "{\n")
  65
+    FOREACH(module ${YASM_MODULES})
  66
+        STRING(REGEX MATCHALL "[a-zA-Z][a-zA-Z0-9]+" _modulepath ${module})
  67
+        LIST(GET _modulepath 0 _type)
  68
+        LIST(GET _modulepath 1 _keyword)
  69
+        SET(_data "yasm_${_keyword}_LTX_${_type}")
  70
+        STRING(TOUPPER "${_type}" _type)
  71
+        FILE(APPEND ${INIT_PLUGIN_C}
  72
+             "    yasm_register_module(YASM_MODULE_${_type}, \"${_keyword}\", &${_data});\n")
  73
+    ENDFOREACH(module)
  74
+    FILE(APPEND ${INIT_PLUGIN_C} "}\n") 
  75
+ELSE(regen_init_plugin_c)
  76
+    MESSAGE(STATUS "Not regenerating static modules file (unchanged)")
  77
+ENDIF(regen_init_plugin_c)
  78
+
  79
+SET_SOURCE_FILES_PROPERTIES(init_plugin.c GENERATED)
  80
+
  81
+SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
  82
+
  83
+ADD_LIBRARY(yasmstd MODULE
  84
+    init_plugin.c
  85
+    ${YASM_MODULES_SRC}
  86
+    )
  87
+TARGET_LINK_LIBRARIES(yasmstd libyasm)
  88
+
  89
+INSTALL(TARGETS yasmstd LIBRARY DESTINATION lib)
2  modules/arch/CMakeLists.txt
... ...
@@ -0,0 +1,2 @@
  1
+INCLUDE(arch/lc3b/CMakeLists.txt)
  2
+INCLUDE(arch/x86/CMakeLists.txt)
11  modules/arch/lc3b/CMakeLists.txt
... ...
@@ -0,0 +1,11 @@
  1
+YASM_RE2C(
  2
+    ${CMAKE_CURRENT_SOURCE_DIR}/arch/lc3b/lc3bid.re
  3
+    ${CMAKE_CURRENT_BINARY_DIR}/lc3bid.c
  4
+    -s
  5
+    )
  6
+
  7
+YASM_ADD_MODULE(arch_lc3b
  8
+    arch/lc3b/lc3barch.c
  9
+    arch/lc3b/lc3bbc.c
  10
+    lc3bid.c
  11
+    )
50  modules/arch/x86/CMakeLists.txt
... ...
@@ -0,0 +1,50 @@
  1
+ADD_CUSTOM_COMMAND(
  2
+    OUTPUT
  3
+        ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c
  4
+        ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf
  5
+        ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf
  6
+    COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/gen_x86_insn.py
  7
+           ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c
  8
+           ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf
  9
+           ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf
  10
+    MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/gen_x86_insn.py
  11
+    )
  12
+
  13
+YASM_GENPERF(
  14
+    ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/x86cpu.gperf
  15
+    ${CMAKE_CURRENT_BINARY_DIR}/x86cpu.c
  16
+    )
  17
+
  18
+YASM_GENPERF(
  19
+    ${CMAKE_CURRENT_SOURCE_DIR}/arch/x86/x86regtmod.gperf
  20
+    ${CMAKE_CURRENT_BINARY_DIR}/x86regtmod.c
  21
+    )
  22
+
  23
+YASM_GENPERF(
  24
+    ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.gperf
  25
+    ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.c
  26
+    )
  27
+
  28
+YASM_GENPERF(
  29
+    ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.gperf
  30
+    ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.c
  31
+    )
  32
+
  33
+YASM_ADD_MODULE(arch_x86
  34
+    arch/x86/x86arch.c
  35
+    arch/x86/x86bc.c
  36
+    arch/x86/x86expr.c
  37
+    arch/x86/x86id.c
  38
+    x86cpu.c
  39
+    x86regtmod.c
  40
+    )
  41
+
  42
+SET(insn_DEPS
  43
+    ${CMAKE_CURRENT_BINARY_DIR}/x86insn_nasm.c
  44
+    ${CMAKE_CURRENT_BINARY_DIR}/x86insn_gas.c
  45
+    ${CMAKE_CURRENT_BINARY_DIR}/x86insns.c
  46
+    )
  47
+
  48
+SET_SOURCE_FILES_PROPERTIES(arch/x86/x86id.c PROPERTIES
  49
+    OBJECT_DEPENDS "${insn_DEPS}"
  50
+    )
4  modules/dbgfmts/CMakeLists.txt
... ...
@@ -0,0 +1,4 @@
  1
+INCLUDE(dbgfmts/codeview/CMakeLists.txt)
  2
+INCLUDE(dbgfmts/dwarf2/CMakeLists.txt)
  3
+INCLUDE(dbgfmts/null/CMakeLists.txt)
  4
+INCLUDE(dbgfmts/stabs/CMakeLists.txt)
5  modules/dbgfmts/codeview/CMakeLists.txt
... ...
@@ -0,0 +1,5 @@
  1
+YASM_ADD_MODULE(dbgfmt_cv8
  2
+    dbgfmts/codeview/cv-dbgfmt.c
  3
+    dbgfmts/codeview/cv-symline.c
  4
+    dbgfmts/codeview/cv-type.c
  5
+    )
6  modules/dbgfmts/dwarf2/CMakeLists.txt
... ...
@@ -0,0 +1,6 @@
  1
+YASM_ADD_MODULE(dbgfmt_dwarf2
  2
+    dbgfmts/dwarf2/dwarf2-dbgfmt.c
  3
+    dbgfmts/dwarf2/dwarf2-line.c
  4
+    dbgfmts/dwarf2/dwarf2-aranges.c
  5
+    dbgfmts/dwarf2/dwarf2-info.c
  6
+    )
3  modules/dbgfmts/null/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODULE(dbgfmt_null
  2
+    dbgfmts/null/null-dbgfmt.c
  3
+    )
3  modules/dbgfmts/stabs/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODULE(dbgfmt_stabs
  2
+    dbgfmts/stabs/stabs-dbgfmt.c
  3
+    )
1  modules/listfmts/CMakeLists.txt
... ...
@@ -0,0 +1 @@
  1
+INCLUDE(listfmts/nasm/CMakeLists.txt)
3  modules/listfmts/nasm/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODULE(listfmt_nasm
  2
+    listfmts/nasm/nasm-listfmt.c
  3
+    )
9  modules/objfmts/CMakeLists.txt
... ...
@@ -0,0 +1,9 @@
  1
+INCLUDE(objfmts/dbg/CMakeLists.txt)
  2
+INCLUDE(objfmts/bin/CMakeLists.txt)
  3
+INCLUDE(objfmts/elf/CMakeLists.txt)
  4
+INCLUDE(objfmts/coff/CMakeLists.txt)
  5
+INCLUDE(objfmts/macho/CMakeLists.txt)
  6
+INCLUDE(objfmts/rdf/CMakeLists.txt)
  7
+#INCLUDE(objfmts/win32/CMakeLists.txt)
  8
+#INCLUDE(objfmts/win64/CMakeLists.txt)
  9
+INCLUDE(objfmts/xdf/CMakeLists.txt)
3  modules/objfmts/bin/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODULE(objfmt_bin
  2
+    objfmts/bin/bin-objfmt.c
  3
+    )
27  modules/objfmts/coff/CMakeLists.txt
... ...
@@ -0,0 +1,27 @@
  1
+YASM_GENMACRO(
  2
+    ${CMAKE_CURRENT_SOURCE_DIR}/objfmts/coff/win64-nasm.mac
  3
+    ${CMAKE_CURRENT_BINARY_DIR}/win64-nasm.c
  4
+    win64_nasm_stdmac
  5
+    )
  6
+
  7
+YASM_GENMACRO(
  8
+    ${CMAKE_CURRENT_SOURCE_DIR}/objfmts/coff/win64-gas.mac
  9
+    ${CMAKE_CURRENT_BINARY_DIR}/win64-gas.c
  10
+    win64_gas_stdmac
  11
+    )
  12
+
  13
+SET(coff_DEPS
  14
+    ${CMAKE_CURRENT_BINARY_DIR}/win64-nasm.c
  15
+    ${CMAKE_CURRENT_BINARY_DIR}/win64-gas.c
  16
+    )
  17
+
  18
+SET_SOURCE_FILES_PROPERTIES(objfmts/coff/coff-objfmt.c PROPERTIES
  19
+    OBJECT_DEPENDS "${coff_DEPS}"
  20
+    )
  21
+
  22
+YASM_ADD_MODULE(objfmt_coff
  23
+    objfmts/coff/coff-objfmt.c
  24
+    objfmts/coff/win64-except.c
  25
+    )
  26
+list(APPEND YASM_MODULES objfmt_win32)
  27
+list(APPEND YASM_MODULES objfmt_win64)
3  modules/objfmts/dbg/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODULE(objfmt_dbg
  2
+    objfmts/dbg/dbg-objfmt.c
  3
+    )
8  modules/objfmts/elf/CMakeLists.txt
... ...
@@ -0,0 +1,8 @@
  1
+YASM_ADD_MODULE(objfmt_elf
  2
+    objfmts/elf/elf.c
  3
+    objfmts/elf/elf-objfmt.c
  4
+    objfmts/elf/elf-x86-x86.c
  5
+    objfmts/elf/elf-x86-amd64.c
  6
+    )
  7
+list(APPEND YASM_MODULES objfmt_elf32)
  8
+list(APPEND YASM_MODULES objfmt_elf64)
5  modules/objfmts/macho/CMakeLists.txt
... ...
@@ -0,0 +1,5 @@
  1
+YASM_ADD_MODULE(objfmt_macho
  2
+    objfmts/macho/macho-objfmt.c
  3
+    )
  4
+list(APPEND YASM_MODULES objfmt_macho32)
  5
+list(APPEND YASM_MODULES objfmt_macho64)
3  modules/objfmts/rdf/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODULE(objfmt_rdf
  2
+    objfmts/rdf/rdf-objfmt.c
  3
+    )
3  modules/objfmts/xdf/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODULE(objfmt_xdf
  2
+    objfmts/xdf/xdf-objfmt.c
  3
+    )
2  modules/parsers/CMakeLists.txt
... ...
@@ -0,0 +1,2 @@
  1
+INCLUDE(parsers/gas/CMakeLists.txt)
  2
+INCLUDE(parsers/nasm/CMakeLists.txt)
11  modules/parsers/gas/CMakeLists.txt
... ...
@@ -0,0 +1,11 @@
  1
+YASM_RE2C(
  2
+    ${CMAKE_CURRENT_SOURCE_DIR}/parsers/gas/gas-token.re
  3
+    ${CMAKE_CURRENT_BINARY_DIR}/gas-token.c
  4
+    -b
  5
+    )
  6
+
  7
+YASM_ADD_MODULE(parser_gas
  8
+    parsers/gas/gas-parser.c
  9
+    parsers/gas/gas-parse.c
  10
+    gas-token.c
  11
+    )
21  modules/parsers/nasm/CMakeLists.txt
... ...
@@ -0,0 +1,21 @@
  1
+YASM_GENMACRO(
  2
+    ${CMAKE_CURRENT_SOURCE_DIR}/parsers/nasm/nasm-std.mac
  3
+    ${CMAKE_CURRENT_BINARY_DIR}/nasm-macros.c
  4
+    nasm_standard_mac
  5
+    )
  6
+
  7
+SET_SOURCE_FILES_PROPERTIES(parsers/nasm/nasm-parser.c PROPERTIES
  8
+    OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/nasm-macros.c
  9
+    )
  10
+
  11
+YASM_RE2C(
  12
+    ${CMAKE_CURRENT_SOURCE_DIR}/parsers/nasm/nasm-token.re
  13
+    ${CMAKE_CURRENT_BINARY_DIR}/nasm-token.c
  14
+    -b
  15
+    )
  16
+
  17
+YASM_ADD_MODULE(parser_nasm
  18
+    parsers/nasm/nasm-parser.c
  19
+    parsers/nasm/nasm-parse.c
  20
+    nasm-token.c
  21
+    )
3  modules/preprocs/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+INCLUDE(preprocs/nasm/CMakeLists.txt)
  2
+INCLUDE(preprocs/raw/CMakeLists.txt)
  3
+INCLUDE(preprocs/cpp/CMakeLists.txt)
3  modules/preprocs/cpp/CMakeLists.txt
... ...
@@ -0,0 +1,3 @@
  1
+YASM_ADD_MODU