summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Johnson <peter@tortall.net>2014-08-10 21:38:48 -0700
committerPeter Johnson <peter@tortall.net>2014-08-10 23:18:46 -0700
commit636dc92558efd052cd0553203f67068171a3116c (patch)
tree5bb4f3aea44713caf767c4296ebeac2699cd0ccb
parent24e01c833fa94947ff815099170311355ad39949 (diff)
downloadyasm-636dc92558efd052cd0553203f67068171a3116c.tar.gz
Allow building of static executables with cmake.
-rw-r--r--CMakeLists.txt4
-rw-r--r--config.h.cmake3
-rw-r--r--frontends/tasm/CMakeLists.txt20
-rw-r--r--frontends/tasm/tasm.c12
-rw-r--r--frontends/vsyasm/CMakeLists.txt20
-rw-r--r--frontends/vsyasm/vsyasm.c18
-rw-r--r--frontends/yasm/CMakeLists.txt20
-rw-r--r--frontends/yasm/yasm.c18
-rw-r--r--libyasm-stdint.h.cmake11
-rw-r--r--libyasm/CMakeLists.txt16
-rw-r--r--modules/CMakeLists.txt36
11 files changed, 127 insertions, 51 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b63d14b7..974a34b9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@ if (COMMAND cmake_policy)
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")
@@ -31,7 +31,7 @@ VERSION_GEN(PACKAGE_VERSION "${CMAKE_BINARY_DIR}/YASM-VERSION-FILE" "1.1.0")
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)
diff --git a/config.h.cmake b/config.h.cmake
index 50ed93ab..e0026778 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -2,6 +2,9 @@
#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
diff --git a/frontends/tasm/CMakeLists.txt b/frontends/tasm/CMakeLists.txt
index 982b95d1..e275ab84 100644
--- a/frontends/tasm/CMakeLists.txt
+++ b/frontends/tasm/CMakeLists.txt
@@ -15,12 +15,20 @@ ADD_CUSTOM_COMMAND(
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
diff --git a/frontends/tasm/tasm.c b/frontends/tasm/tasm.c
index b0b89de7..58954b64 100644
--- a/frontends/tasm/tasm.c
+++ b/frontends/tasm/tasm.c
@@ -38,7 +38,7 @@
#include "tasm-options.h"
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
#include "yasm-plugin.h"
#endif
@@ -46,6 +46,10 @@
#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;
@@ -457,10 +461,14 @@ main(int argc, char *argv[])
#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 */
@@ -640,7 +648,7 @@ cleanup(yasm_object *object)
if (errfile != stderr && errfile != stdout)
fclose(errfile);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
unload_plugins();
#endif
}
diff --git a/frontends/vsyasm/CMakeLists.txt b/frontends/vsyasm/CMakeLists.txt
index 62c7405c..6815b18d 100644
--- a/frontends/vsyasm/CMakeLists.txt
+++ b/frontends/vsyasm/CMakeLists.txt
@@ -15,12 +15,20 @@ ADD_CUSTOM_COMMAND(
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
diff --git a/frontends/vsyasm/vsyasm.c b/frontends/vsyasm/vsyasm.c
index 4ab46369..905145fa 100644
--- a/frontends/vsyasm/vsyasm.c
+++ b/frontends/vsyasm/vsyasm.c
@@ -37,12 +37,16 @@
#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;
@@ -107,7 +111,7 @@ static int opt_preproc_option(char *cmd, /*@null@*/ char *param, int extra);
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
@@ -207,7 +211,7 @@ static opt_option options[] =
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
@@ -542,10 +546,14 @@ main(int argc, char *argv[])
#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 */
@@ -783,7 +791,7 @@ cleanup(void)
if (errfile != stderr && errfile != stdout)
fclose(errfile);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
unload_plugins();
#endif
}
@@ -1201,7 +1209,7 @@ opt_suffix_handler(/*@unused@*/ char *cmd, char *param, /*@unused@*/ int extra)
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)
diff --git a/frontends/yasm/CMakeLists.txt b/frontends/yasm/CMakeLists.txt
index 6d963eb4..b11d7f82 100644
--- a/frontends/yasm/CMakeLists.txt
+++ b/frontends/yasm/CMakeLists.txt
@@ -12,12 +12,20 @@ ADD_CUSTOM_COMMAND(
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
diff --git a/frontends/yasm/yasm.c b/frontends/yasm/yasm.c
index 44358549..ff4c59e2 100644
--- a/frontends/yasm/yasm.c
+++ b/frontends/yasm/yasm.c
@@ -37,7 +37,7 @@
#include "yasm-options.h"
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
#include "yasm-plugin.h"
#endif
@@ -108,10 +108,14 @@ static int opt_ewmsg_handler(char *cmd, /*@null@*/ char *param, int extra);
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, ...);
@@ -204,7 +208,7 @@ static opt_option options[] =
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
@@ -611,10 +615,14 @@ main(int argc, char *argv[])
#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 */
@@ -811,7 +819,7 @@ cleanup(yasm_object *object)
if (errfile != stderr && errfile != stdout)
fclose(errfile);
-#ifdef CMAKE_BUILD
+#if defined(CMAKE_BUILD) && defined(BUILD_SHARED_LIBS)
unload_plugins();
#endif
}
@@ -1192,7 +1200,7 @@ opt_suffix_handler(/*@unused@*/ char *cmd, char *param, /*@unused@*/ int extra)
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)
diff --git a/libyasm-stdint.h.cmake b/libyasm-stdint.h.cmake
index f2361d4c..3759a035 100644
--- a/libyasm-stdint.h.cmake
+++ b/libyasm-stdint.h.cmake
@@ -20,8 +20,13 @@ typedef unsigned long uintptr_t;
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
@@ -33,5 +38,9 @@ typedef unsigned long uintptr_t;
#endif
#undef HAVE_STDINT_H
+#ifdef BUILD_SHARED_LIBS_UNDEF
+#undef BUILD_SHARED_LIBS
+#undef BUILD_SHARED_LIBS_UNDEF
+#endif
#endif
diff --git a/libyasm/CMakeLists.txt b/libyasm/CMakeLists.txt
index f886f734..bd9b7b28 100644
--- a/libyasm/CMakeLists.txt
+++ b/libyasm/CMakeLists.txt
@@ -1,6 +1,6 @@
SET(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
-ADD_LIBRARY(libyasm SHARED
+ADD_LIBRARY(libyasm
assocdat.c
bitvect.c
bc-align.c
@@ -31,10 +31,16 @@ ADD_LIBRARY(libyasm SHARED
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
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt
index 48a3b5cf..e3f8eb11 100644
--- a/modules/CMakeLists.txt
+++ b/modules/CMakeLists.txt
@@ -56,9 +56,11 @@ IF(regen_init_plugin_c)
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")
@@ -80,14 +82,22 @@ SET_SOURCE_FILES_PROPERTIES(init_plugin.c GENERATED)
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)