cmake_policy(SET CMP0003 NEW)
endif (COMMAND cmake_policy)
-SET(BUILD_SHARED_LIBS ON)
+OPTION(BUILD_SHARED_LIBS "Build shared libraries" ON)
# Where to look first for cmake modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
set (PACKAGE_STRING "yasm ${PACKAGE_VERSION}")
-INCLUDE_DIRECTORIES(BEFORE ${CMAKE_BINARY_DIR} ${yasm_SOURCE_DIR})
+INCLUDE_DIRECTORIES(AFTER ${CMAKE_BINARY_DIR} ${yasm_SOURCE_DIR})
INCLUDE(ConfigureChecks.cmake)
#define CMAKE_BUILD 1
+/* Define if shared libs are being built */
+#cmakedefine BUILD_SHARED_LIBS 1
+
/* Define if messsage translations are enabled */
#cmakedefine ENABLE_NLS 1
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
-ADD_EXECUTABLE(ytasm
- tasm.c
- tasm-options.c
- ${yasm_SOURCE_DIR}/frontends/yasm/yasm-plugin.c
- )
-TARGET_LINK_LIBRARIES(ytasm libyasm ${LIBDL})
+IF(BUILD_SHARED_LIBS)
+ ADD_EXECUTABLE(ytasm
+ tasm.c
+ tasm-options.c
+ ${yasm_SOURCE_DIR}/frontends/yasm/yasm-plugin.c
+ )
+ TARGET_LINK_LIBRARIES(ytasm libyasm ${LIBDL})
+ELSE(BUILD_SHARED_LIBS)
+ ADD_EXECUTABLE(ytasm
+ tasm.c
+ tasm-options.c
+ )
+ TARGET_LINK_LIBRARIES(ytasm yasmstd libyasm)
+ENDIF(BUILD_SHARED_LIBS)
SET_SOURCE_FILES_PROPERTIES(tasm.c PROPERTIES
OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/license.c
#include "tasm-options.h"
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
#include "yasm-plugin.h"
#endif
#define DEFAULT_OBJFMT_MODULE "bin"
+#if defined(CMAKE_BUILD) && !defined(BUILD_SHARED_LIBS)
+void yasm_init_plugin(void);
+#endif
+
/*@null@*/ /*@only@*/ static char *obj_filename = NULL, *in_filename = NULL;
/*@null@*/ /*@only@*/ static char *list_filename = NULL, *xref_filename = NULL;
/*@null@*/ /*@only@*/ static char *machine_name = NULL;
#ifdef CMAKE_BUILD
/* Load standard modules */
+#ifdef BUILD_SHARED_LIBS
if (!load_plugin("yasmstd")) {
print_error(_("%s: could not load standard modules"), _("FATAL"));
return EXIT_FAILURE;
}
+#else
+ yasm_init_plugin();
+#endif
#endif
/* Initialize parameter storage */
if (errfile != stderr && errfile != stdout)
fclose(errfile);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
unload_plugins();
#endif
}
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
-ADD_EXECUTABLE(vsyasm
- vsyasm.c
- ${yasm_SOURCE_DIR}/frontends/yasm/yasm-options.c
- ${yasm_SOURCE_DIR}/frontends/yasm/yasm-plugin.c
- )
-TARGET_LINK_LIBRARIES(vsyasm libyasm ${LIBDL})
+IF(BUILD_SHARED_LIBS)
+ ADD_EXECUTABLE(vsyasm
+ vsyasm.c
+ ${yasm_SOURCE_DIR}/frontends/yasm/yasm-options.c
+ ${yasm_SOURCE_DIR}/frontends/yasm/yasm-plugin.c
+ )
+ TARGET_LINK_LIBRARIES(vsyasm libyasm ${LIBDL})
+ELSE(BUILD_SHARED_LIBS)
+ ADD_EXECUTABLE(vsyasm
+ vsyasm.c
+ ${yasm_SOURCE_DIR}/frontends/yasm/yasm-options.c
+ )
+ TARGET_LINK_LIBRARIES(vsyasm yasmstd libyasm)
+ENDIF(BUILD_SHARED_LIBS)
SET_SOURCE_FILES_PROPERTIES(vsyasm.c PROPERTIES
OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/license.c
#include "frontends/yasm/yasm-options.h"
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
#include "frontends/yasm/yasm-plugin.h"
#endif
#include "license.c"
+#if defined(CMAKE_BUILD) && !defined(BUILD_SHARED_LIBS)
+void yasm_init_plugin(void);
+#endif
+
/*@null@*/ /*@only@*/ static char *objdir_pathname = NULL;
/*@null@*/ /*@only@*/ static char *global_prefix = NULL, *global_suffix = NULL;
/*@null@*/ /*@only@*/ static char *listdir_pathname = NULL;
static int opt_ewmsg_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_prefix_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_suffix_handler(char *cmd, /*@null@*/ char *param, int extra);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
static int opt_plugin_handler(char *cmd, /*@null@*/ char *param, int extra);
#endif
N_("append argument to name of all external symbols"), N_("suffix") },
{ 0, "postfix", 1, opt_suffix_handler, 0,
N_("append argument to name of all external symbols"), N_("suffix") },
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
{ 'N', "plugin", 1, opt_plugin_handler, 0,
N_("load plugin module"), N_("plugin") },
#endif
#ifdef CMAKE_BUILD
/* Load standard modules */
+#ifdef BUILD_SHARED_LIBS
if (!load_plugin("yasmstd")) {
print_error(_("%s: could not load standard modules"), _("FATAL"));
return EXIT_FAILURE;
}
+#else
+ yasm_init_plugin();
+#endif
#endif
/* Initialize parameter storage */
if (errfile != stderr && errfile != stdout)
fclose(errfile);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
unload_plugins();
#endif
}
return 0;
}
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
static int
opt_plugin_handler(/*@unused@*/ char *cmd, char *param,
/*@unused@*/ int extra)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
-ADD_EXECUTABLE(yasm
- yasm.c
- yasm-options.c
- yasm-plugin.c
- )
-TARGET_LINK_LIBRARIES(yasm libyasm ${LIBDL})
+IF(BUILD_SHARED_LIBS)
+ ADD_EXECUTABLE(yasm
+ yasm.c
+ yasm-options.c
+ yasm-plugin.c
+ )
+ TARGET_LINK_LIBRARIES(yasm libyasm ${LIBDL})
+ELSE(BUILD_SHARED_LIBS)
+ ADD_EXECUTABLE(yasm
+ yasm.c
+ yasm-options.c
+ )
+ TARGET_LINK_LIBRARIES(yasm yasmstd libyasm)
+ENDIF(BUILD_SHARED_LIBS)
SET_SOURCE_FILES_PROPERTIES(yasm.c PROPERTIES
OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/license.c
#include "yasm-options.h"
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
#include "yasm-plugin.h"
#endif
static int opt_makedep_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_prefix_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_suffix_handler(char *cmd, /*@null@*/ char *param, int extra);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
static int opt_plugin_handler(char *cmd, /*@null@*/ char *param, int extra);
#endif
+#if defined(CMAKE_BUILD) && !defined(BUILD_SHARED_LIBS)
+void yasm_init_plugin(void);
+#endif
+
static /*@only@*/ char *replace_extension(const char *orig, /*@null@*/
const char *ext, const char *def);
static void print_error(const char *fmt, ...);
N_("append argument to name of all external symbols"), N_("suffix") },
{ 0, "postfix", 1, opt_suffix_handler, 0,
N_("append argument to name of all external symbols"), N_("suffix") },
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
{ 'N', "plugin", 1, opt_plugin_handler, 0,
N_("load plugin module"), N_("plugin") },
#endif
#ifdef CMAKE_BUILD
/* Load standard modules */
+#ifdef BUILD_SHARED_LIBS
if (!load_plugin("yasmstd")) {
print_error(_("%s: could not load standard modules"), _("FATAL"));
return EXIT_FAILURE;
}
+#else
+ yasm_init_plugin();
+#endif
#endif
/* Initialize parameter storage */
if (errfile != stderr && errfile != stdout)
fclose(errfile);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
unload_plugins();
#endif
}
return 0;
}
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
static int
opt_plugin_handler(/*@unused@*/ char *cmd, char *param,
/*@unused@*/ int extra)
typedef unsigned long uintptr_t;
#endif
+#ifndef BUILD_SHARED_LIBS
+#cmakedefine BUILD_SHARED_LIBS
+#define BUILD_SHARED_LIBS_UNDEF
+#endif
+
#ifndef YASM_LIB_DECL
-# ifdef _MSC_VER
+# if defined(BUILD_SHARED_LIBS) && defined(_MSC_VER)
# ifdef YASM_LIB_SOURCE
# define YASM_LIB_DECL __declspec(dllexport)
# else
#endif
#undef HAVE_STDINT_H
+#ifdef BUILD_SHARED_LIBS_UNDEF
+#undef BUILD_SHARED_LIBS
+#undef BUILD_SHARED_LIBS_UNDEF
+#endif
#endif
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
-ADD_LIBRARY(libyasm SHARED
+ADD_LIBRARY(libyasm
assocdat.c
bitvect.c
bc-align.c
xmalloc.c
xstrdup.c
)
-SET_TARGET_PROPERTIES(libyasm PROPERTIES
- OUTPUT_NAME "yasm"
- COMPILE_FLAGS -DYASM_LIB_SOURCE
- )
+IF(BUILD_SHARED_LIBS)
+ SET_TARGET_PROPERTIES(libyasm PROPERTIES
+ OUTPUT_NAME "yasm"
+ COMPILE_FLAGS -DYASM_LIB_SOURCE
+ )
+ELSE(BUILD_SHARED_LIBS)
+ SET_TARGET_PROPERTIES(libyasm PROPERTIES
+ COMPILE_FLAGS -DYASM_LIB_SOURCE
+ )
+ENDIF(BUILD_SHARED_LIBS)
INSTALL(TARGETS libyasm
RUNTIME DESTINATION bin
FILE(APPEND ${INIT_PLUGIN_C}
"extern yasm_${_type}_module yasm_${_keyword}_LTX_${_type};\n")
ENDFOREACH(module)
- FILE(APPEND ${INIT_PLUGIN_C} "\n#ifdef _MSC_VER\n")
- FILE(APPEND ${INIT_PLUGIN_C} "__declspec(dllexport)\n")
- FILE(APPEND ${INIT_PLUGIN_C} "#endif\n")
+ IF(BUILD_SHARED_LIBS)
+ FILE(APPEND ${INIT_PLUGIN_C} "\n#ifdef _MSC_VER\n")
+ FILE(APPEND ${INIT_PLUGIN_C} "__declspec(dllexport)\n")
+ FILE(APPEND ${INIT_PLUGIN_C} "#endif\n")
+ ENDIF(BUILD_SHARED_LIBS)
FILE(APPEND ${INIT_PLUGIN_C} "void\n")
FILE(APPEND ${INIT_PLUGIN_C} "yasm_init_plugin(void)\n")
FILE(APPEND ${INIT_PLUGIN_C} "{\n")
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
-ADD_LIBRARY(yasmstd MODULE
- init_plugin.c
- ${YASM_MODULES_SRC}
- )
-TARGET_LINK_LIBRARIES(yasmstd libyasm)
+IF(BUILD_SHARED_LIBS)
+ ADD_LIBRARY(yasmstd MODULE
+ init_plugin.c
+ ${YASM_MODULES_SRC}
+ )
+ TARGET_LINK_LIBRARIES(yasmstd libyasm)
-IF(WIN32)
- INSTALL(TARGETS yasmstd LIBRARY DESTINATION bin)
-ELSE(WIN32)
- INSTALL(TARGETS yasmstd LIBRARY DESTINATION lib)
-ENDIF(WIN32)
+ IF(WIN32)
+ INSTALL(TARGETS yasmstd LIBRARY DESTINATION bin)
+ ELSE(WIN32)
+ INSTALL(TARGETS yasmstd LIBRARY DESTINATION lib)
+ ENDIF(WIN32)
+ELSE(BUILD_SHARED_LIBS)
+ ADD_LIBRARY(yasmstd
+ init_plugin.c
+ ${YASM_MODULES_SRC}
+ )
+ TARGET_LINK_LIBRARIES(yasmstd libyasm)
+ENDIF(BUILD_SHARED_LIBS)