diff --git a/CMakeLists.txt b/CMakeLists.txt index 3dc2478..af03599 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,22 +3,12 @@ project(microprofile) option(MICROPROFILE_USE_CONFIG_FILE "Use user provided configuration in microprofile.config.h file." OFF) -set(MICROPROFILE_EXPORT_FILENAME microprofile.export.h) set(MICROPROFILE_CONFIG_HEADER ${PROJECT_SOURCE_DIR}/microprofile.config.h) -set(MICROPROFILE_PUBLIC_HEADERS - ${PROJECT_SOURCE_DIR}/microprofile.h - ${CMAKE_CURRENT_BINARY_DIR}/${MICROPROFILE_EXPORT_FILENAME} -) +set(MICROPROFILE_PUBLIC_HEADERS ${PROJECT_SOURCE_DIR}/microprofile.h) set(THREADS_PREFER_PTHREAD_FLAG ON) -add_library(${PROJECT_NAME} microprofile.cpp) - -include(GenerateExportHeader) -generate_export_header(${PROJECT_NAME} - EXPORT_MACRO_NAME MICROPROFILE_API - EXPORT_FILE_NAME ${MICROPROFILE_EXPORT_FILENAME} -) +add_library(${PROJECT_NAME} SHARED microprofile.cpp) target_include_directories(${PROJECT_NAME} PUBLIC $ @@ -26,7 +16,12 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ ) -target_compile_definitions(${PROJECT_NAME} PUBLIC MICROPROFILE_EXPORT) +target_compile_definitions(${PROJECT_NAME} + PUBLIC + MICROPROFILE_SHARED + PRIVATE + MICROPROFILE_EXPORT_SYMBOLS +) if (MICROPROFILE_USE_CONFIG_FILE) target_compile_definitions(${PROJECT_NAME} PUBLIC MICROPROFILE_USE_CONFIG) diff --git a/meson.build b/meson.build index 1821c5b..8cf0986 100644 --- a/meson.build +++ b/meson.build @@ -12,7 +12,8 @@ project( 'cpp_std=c++11' ], license: 'MIT', - meson_version: '>=0.46.0' + meson_version: '>=0.46.0', + version: '5.0' ) # Dependencies @@ -20,6 +21,12 @@ project( deps = [dependency('threads')] extra_args = [] +private_args = [] + +if get_option('default_library') == 'shared' + private_args += '-DMICROPROFILE_EXPORT_SYMBOLS' + extra_args += '-DMICROPROFILE_SHARED' +endif compiler = meson.get_compiler('cpp') @@ -79,7 +86,9 @@ include_dir = include_directories('.') if get_option('microprofile_use_config') extra_args += '-DMICROPROFILE_USE_CONFIG' - install_headers('microprofile.config.h') + if get_option('install') + install_headers('microprofile.config.h') + endif endif # Main build target @@ -87,25 +96,26 @@ endif libmicroprofile = library( 'microprofile', 'microprofile.cpp', - cpp_args: extra_args, + cpp_args: extra_args + private_args, dependencies: deps, include_directories: include_dir, - install: true + install: get_option('install') ) # Headers and pkg-config installation - -install_headers( - 'microprofile.h', - 'microprofile_html.h' -) - -import('pkgconfig').generate( - libmicroprofile, - description: 'microprofile is an embeddable profiler', - extra_cflags: extra_args, - url: 'https://github.com/jonasmr/microprofile' -) +if get_option('install') + install_headers( + 'microprofile.h', + 'microprofile_html.h' + ) + + import('pkgconfig').generate( + libmicroprofile, + description: 'microprofile is an embeddable profiler', + extra_cflags: extra_args, + url: 'https://github.com/jonasmr/microprofile' + ) +endif # Declaring the dependency so that microprofile can be used as a subproject diff --git a/meson_options.txt b/meson_options.txt index 3363ed3..fe87e47 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1 +1,2 @@ option('microprofile_use_config', type: 'boolean', value: false, description: 'Use custom microprofile.config.h') +option('install', type: 'boolean', value: false, description: 'Install microprofile?') \ No newline at end of file diff --git a/microprofile.h b/microprofile.h index cf52999..d9766be 100644 --- a/microprofile.h +++ b/microprofile.h @@ -463,12 +463,40 @@ typedef uint16_t MicroProfileGroupId; #include -#ifdef MICROPROFILE_EXPORT -#include "microprofile.export.h" -#else -#ifndef MICROPROFILE_API -#define MICROPROFILE_API -#endif +#ifndef MICROPROFILE_EXPORT +# if defined _WIN32 || defined __CYGWIN__ +# ifdef __GNUC__ +# define MICROPROFILE_EXPORT __attribute__( ( dllexport ) ) +# else // __GNUC__ +# define MICROPROFILE_EXPORT __declspec( dllexport ) +# endif // __GNUC__ +# elif defined __GNUC__ && __GNUC__ >= 4 +# define MICROPROFILE_EXPORT __attribute__( ( visibility( "default" ) ) ) +# else +# define MICROPROFILE_EXPORT +# endif +#endif // MICROPROFILE_EXPORT + +#ifndef MICROPROFILE_IMPORT +# if defined _WIN32 || defined __CYGWIN__ +# ifdef __GNUC__ +# define MICROPROFILE_IMPORT __attribute__( ( dllimport ) ) +# else // __GNUC__ +# define MICROPROFILE_IMPORT __declspec( dllimport ) +# endif // __GNUC__ +# else +# define MICROPROFILE_IMPORT +# endif +#endif // MICROPROFILE_IMPORT + +#if defined( MICROPROFILE_SHARED ) +# if defined MICROPROFILE_EXPORT_SYMBOLS +# define MICROPROFILE_API MICROPROFILE_EXPORT +# else +# define MICROPROFILE_API MICROPROFILE_IMPORT +# endif +#else // MICROPROFILE_SHARED is not defined, building a static library +# define MICROPROFILE_API #endif #ifdef MICROPROFILE_PS4