From 78147d3d10c0276514ebd8cd5129aca223d39959 Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Fri, 12 Aug 2022 22:44:14 +0200 Subject: [PATCH] Optimized lib type switching --- CMakeLists.txt | 10 +++++++++- RSPModelLib/CMakeLists.txt | 20 +++++++++++--------- RSPModelLib/include/RSPModel.h | 31 +++++++++++++++++-------------- RSPModelLib/src/RSPModel.c | 10 +++++----- RSPModelLib/src/options.h | 2 ++ 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c268bb..4133d60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,9 @@ else() # Standalone project mode, should not be used for release. endif() set(RSP_MODEL_LIB_NAME RSPModel${PROJECT_VERSION_MAJOR}${PROJECT_VERSION_MINOR}) +# Compilation option +option(RSPMODEL_SHARED "Build shared lib" ON) + # Push compile infos to source configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSPModelLib/src/config.h @ONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/RSEModel/src/config.h @ONLY) @@ -57,7 +60,12 @@ add_subdirectory(RSEModel) set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables") set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries") set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers") -install(TARGETS rse-model rsp-model-lib rsp-model-libstatic +if(RSPMODEL_SHARED) + set(RSE_MODEL_TARGETS_LIST rse-model rsp-model-lib rsp-model-libstatic) +else() + set(RSE_MODEL_TARGETS_LIST rse-model rsp-model-libstatic) +endif() +install(TARGETS ${RSE_MODEL_TARGETS_LIST} RUNTIME DESTINATION ${INSTALL_BIN_DIR} LIBRARY DESTINATION ${INSTALL_LIB_DIR} ARCHIVE DESTINATION ${INSTALL_LIB_DIR} diff --git a/RSPModelLib/CMakeLists.txt b/RSPModelLib/CMakeLists.txt index 52fd59e..9f0beaf 100644 --- a/RSPModelLib/CMakeLists.txt +++ b/RSPModelLib/CMakeLists.txt @@ -29,18 +29,20 @@ endif() # Declare the shared library instance -add_library(rsp-model-lib SHARED ${RSP_MOD_SOURCES}) -set_property(TARGET rsp-model-lib PROPERTY C_STANDARD 90) +if(RSPMODEL_SHARED) + add_library(rsp-model-lib SHARED ${RSP_MOD_SOURCES}) + set_property(TARGET rsp-model-lib PROPERTY C_STANDARD 90) -target_include_directories(rsp-model-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) + target_include_directories(rsp-model-lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -set_target_properties(rsp-model-lib PROPERTIES OUTPUT_NAME ${RSP_MODEL_LIB_NAME}) -set_target_properties(rsp-model-lib PROPERTIES DEFINE_SYMBOL RSPMODEL_DLL) + set_target_properties(rsp-model-lib PROPERTIES OUTPUT_NAME ${RSP_MODEL_LIB_NAME}) + set_target_properties(rsp-model-lib PROPERTIES DEFINE_SYMBOL RSPMODEL_DLL) -if(MSVC) - # msvc does not append 'lib' - do it here to have consistent name - set_target_properties(rsp-model-lib PROPERTIES PREFIX "lib") - set_target_properties(rsp-model-lib PROPERTIES IMPORT_PREFIX "lib") + if(MSVC) + # msvc does not append 'lib' - do it here to have consistent name + set_target_properties(rsp-model-lib PROPERTIES PREFIX "lib") + set_target_properties(rsp-model-lib PROPERTIES IMPORT_PREFIX "lib") + endif() endif() diff --git a/RSPModelLib/include/RSPModel.h b/RSPModelLib/include/RSPModel.h index dd0cac9..001d25a 100644 --- a/RSPModelLib/include/RSPModel.h +++ b/RSPModelLib/include/RSPModel.h @@ -14,25 +14,28 @@ #define RSPMODEL_H_ -#if defined(RSPMODEL_SHARED) || defined(RSPMODEL_DLL) -# if defined(_MSC_VER) -# define RSPMODEL_ABI_EXPORT __declspec(dllexport) -# define RSPMODEL_ABI_IMPORT __declspec(dllimport) -# elif __GNUC__ >= 4 -# define RSPMODEL_ABI_EXPORT __attribute__ ((visibility("default"))) -# define RSPMODEL_ABI_IMPORT __attribute__ ((visibility("default"))) -# else -# define RSPMODEL_ABI_EXPORT -# define RSPMODEL_ABI_IMPORT -# endif -# if defined(WINDOWS) || defined(WIN32) -# ifdef RSPMODEL_DLL +#if defined(_MSC_VER) +# define RSPMODEL_ABI_EXPORT __declspec(dllexport) +# define RSPMODEL_ABI_IMPORT __declspec(dllimport) +#elif __GNUC__ >= 4 +# define RSPMODEL_ABI_EXPORT __attribute__ ((visibility("default"))) +# define RSPMODEL_ABI_IMPORT __attribute__ ((visibility("default"))) +#else +# define RSPMODEL_ABI_EXPORT +# define RSPMODEL_ABI_IMPORT +#endif + +#if defined(RSPMODEL_DLL) +# if defined(WIN32) +# if defined(RSPMODEL_DLLBUILD) # define RSPMODEL_EXTERN extern RSPMODEL_ABI_EXPORT # else # define RSPMODEL_EXTERN extern RSPMODEL_ABI_IMPORT # endif # endif -#else +#endif + +#ifndef RSPMODEL_EXTERN # define RSPMODEL_EXTERN extern #endif diff --git a/RSPModelLib/src/RSPModel.c b/RSPModelLib/src/RSPModel.c index ec9e26a..4ddadaf 100644 --- a/RSPModelLib/src/RSPModel.c +++ b/RSPModelLib/src/RSPModel.c @@ -1,9 +1,9 @@ /** - * \file RSPModel.c - * \date 11/08/2022 - * \author JackCarterSmith - * \copyright GPL-v3.0 - * \brief HOB model parser and export to Waveform OBJ format. + * @file RSPModel.c + * @date 11/08/2022 + * @author JackCarterSmith + * @copyright GPL-v3.0 + * @brief HOB model parser and export to Waveform OBJ format. * */ diff --git a/RSPModelLib/src/options.h b/RSPModelLib/src/options.h index d731673..1168992 100644 --- a/RSPModelLib/src/options.h +++ b/RSPModelLib/src/options.h @@ -9,6 +9,8 @@ #ifndef OPTIONS_H_ #define OPTIONS_H_ +#define RSPMODEL_DLLBUILD + /// Options structure typedef union u_prog_options { struct {