Skip to content

Commit

Permalink
Merge pull request #161 from HerveAncher/master
Browse files Browse the repository at this point in the history
Manage export for static library under Windows
  • Loading branch information
slayoo authored Mar 21, 2020
2 parents 126ce71 + 8916547 commit 839fc5e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ add_custom_target(lib DEPENDS blitz)

# Configuration files.

CreatePkgConfigInfo(blitz)
CreatePkgConfigInfo(blitz "")
CreatePkgConfigInfo(blitz-static static)

write_basic_package_version_file(
cmake/${PROJECT_NAME}ConfigVersion.cmake
Expand All @@ -77,6 +78,7 @@ configure_package_config_file(
install(EXPORT ${PROJECT_NAME}Targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake)
install(FILES
${CMAKE_BINARY_DIR}/blitz.pc
${CMAKE_BINARY_DIR}/blitz-static.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}Config.cmake
Expand Down
30 changes: 15 additions & 15 deletions blitz/blitz.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ namespace blitz {
using namespace std;
#endif

#ifdef _WIN32
#ifdef BZ_GENERATE_GLOBAL_INSTANCES
#define _bz_global __declspec(dllexport)
#define BZ_GLOBAL_INIT(X) =X
#if defined(_WIN32) && !defined(BZ_STATIC_LIB)
# ifdef BZ_GENERATE_GLOBAL_INSTANCES
# define _bz_global __declspec(dllexport)
# define BZ_GLOBAL_INIT(X) =X
# else
# define _bz_global __declspec(dllimport)
# define BZ_GLOBAL_INIT(X)
# endif
#else
#define _bz_global __declspec(dllimport)
#define BZ_GLOBAL_INIT(X)
#endif
#else
#ifdef BZ_GENERATE_GLOBAL_INSTANCES
#define _bz_global
#define BZ_GLOBAL_INIT(X) =X
#else
#define _bz_global extern
#define BZ_GLOBAL_INIT(X)
#endif
# ifdef BZ_GENERATE_GLOBAL_INSTANCES
# define _bz_global
# define BZ_GLOBAL_INIT(X) =X
# else
# define _bz_global extern
# define BZ_GLOBAL_INIT(X)
# endif
#endif

/* Define types for indexing, depending on whether 64- or 32-bit
Expand Down
20 changes: 17 additions & 3 deletions cmake/CreatePkgConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
function (CreatePkgConfigInfo filename)
function (CreatePkgConfigInfo filename mode)
set(template_filename ${filename}.pc.in)
if (EXISTS ${CMAKE_SOURCE_DIR}/${template_filename})
set(PKGCONFIG_TEMPLATE ${CMAKE_SOURCE_DIR}/${template_filename})
else()
# Under MinGW, add stdc++ library
set(addlink)
if (MINGW)
set(addlink -lstdc++)
endif()
set(cflags)
set(static)
if ("${mode}" STREQUAL "static")
set(static -static)
# Under Windows and MinGW, add BZ_STATIC_LIB flag
if (WIN32 OR MINGW)
set(cflags -DBZ_STATIC_LIB)
endif()
endif()
file(WRITE ${CMAKE_BINARY_DIR}/${template_filename}
"# generated by cmake. remove this line to disable regeneration
prefix=@pkgconfig_prefix@
Expand All @@ -15,8 +29,8 @@ Name: @pkgconfig_package_name@
Description: @pkgconfig_package_description@
Version: @CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@
Requires: @PACKAGE_REQUIRES@
Libs: -L\${libdir} @PKGCONFIG_LIBS@
Cflags: -I\${includedir} -I\${confdir} @CPPFLAGS@")
Libs: -L\${libdir} ${static} @PKGCONFIG_LIBS@ ${addlink}
Cflags: -I\${includedir} -I\${confdir} @CPPFLAGS@ ${cflags}")
set(PKGCONFIG_TEMPLATE ${CMAKE_BINARY_DIR}/${template_filename})
endif()

Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ set_target_properties(blitz-static PROPERTIES
${BLITZ-STATIC-DEFS}
CLEAN_DIRECT_OUTPUT 1)

# Under Windows and MinGW, set BZ_STATIC_LIB flag during compilation
if (WIN32 OR MINGW)
target_compile_options(blitz-static PUBLIC -DBZ_STATIC_LIB)
endif()

install(TARGETS ${BLITZ_LIBS}
EXPORT ${PROJECT_NAME}Targets
Expand Down

0 comments on commit 839fc5e

Please sign in to comment.