Skip to content

Commit

Permalink
export symbols when building windows shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
vigsterkr committed Mar 14, 2020
1 parent bac8cda commit 682862a
Show file tree
Hide file tree
Showing 31 changed files with 159 additions and 147 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ SET(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON)
#### set required C++ standard level of the compiler
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_CXX_EXTENSIONS OFF)
if (MSVC)
if (MSVC_VERSION VERSION_LESS 1900)
Expand All @@ -47,6 +48,8 @@ if (MSVC)
endif()
endif()

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

#### check for c++17 features - not all compilers support c++17 in 2019
include(CheckCXXSourceCompiles)

Expand Down
1 change: 0 additions & 1 deletion cmake/ShogunFindLAPACK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ IF (LAPACK_FOUND)
MESSAGE(STATUS "Enabling MKL as BLAS/Lapack backend for Eigen.")
SET(EIGEN_USE_MKL_ALL 1)
target_include_directories(shogun PUBLIC ${MKL_INCLUDE_DIR})
target_include_directories(libshogun PRIVATE ${MKL_INCLUDE_DIR})
IF (LIBSHOGUN_BUILD_STATIC)
target_include_directories(shogun-static PUBLIC ${MKL_INCLUDE_DIR})
ENDIF()
Expand Down
6 changes: 1 addition & 5 deletions cmake/ShogunInterfaces.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ SET(SWIG_MODULE_${INTERFACE_NAME}_EXTRA_DEPS ${INTERFACE_FILES})
SWIG_ADD_MODULE(${INTERFACE_TARGET} ${INTERFACE_NAME} shogun.i)
SET(INTERFACE_REAL_NAME ${SWIG_MODULE_interface_${INTERFACE_NAME}_REAL_NAME})

IF (WIN32)
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} shogun::shogun-static)
ELSE ()
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} shogun::shogun)
ENDIF ()
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} shogun::shogun)
IF (NOT "${INTERFACE_LIBRARIES}" STREQUAL "NO")
SWIG_LINK_LIBRARIES(${INTERFACE_TARGET} ${INTERFACE_LIBRARIES})
ENDIF()
Expand Down
18 changes: 10 additions & 8 deletions cmake/ShogunUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ MACRO(AddLibShogunExample EXAMPLE_CPP)
STRING(REGEX REPLACE ".cpp\$" "" EXAMPLE "${EXAMPLE_CPP}")

add_executable(${EXAMPLE} EXCLUDE_FROM_ALL ${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_CPP})
if(WIN32)
target_link_libraries(${EXAMPLE} shogun::shogun-static ${SANITIZER_LIBRARY})
else()
target_link_libraries(${EXAMPLE} shogun::shogun ${SANITIZER_LIBRARY})
endif()
target_link_libraries(${EXAMPLE} shogun::shogun ${SANITIZER_LIBRARY})
IF(SANITIZER_FLAGS)
set_target_properties(${EXAMPLE} PROPERTIES COMPILE_FLAGS ${SANITIZER_FLAGS})
ENDIF()
Expand Down Expand Up @@ -196,7 +192,7 @@ macro(ADD_LIBRARY_DEPENDENCY)
endmacro()

macro(SHOGUN_DEPENDENCIES)
ADD_LIBRARY_DEPENDENCY(TARGETS shogun shogun-static libshogun shogun_deps ${ARGN})
ADD_LIBRARY_DEPENDENCY(TARGETS shogun shogun-static shogun_deps ${ARGN})
endmacro()

function(SHOGUN_LINK_LIBS)
Expand All @@ -210,7 +206,6 @@ endfunction()

function(SHOGUN_COMPILE_OPTS)
set(SCOPE PRIVATE)
target_compile_options(libshogun ${SCOPE} ${ARGN})
target_compile_options(shogun ${SCOPE} ${ARGN})
if (LIBSHOGUN_BUILD_STATIC)
target_compile_options(shogun-static ${SCOPE} ${ARGN})
Expand All @@ -227,7 +222,6 @@ function(SHOGUN_INCLUDE_DIRS)
if(SHOGUN_INCLUDE_DIRS_SYSTEM)
set(SYSTEM "SYSTEM")
endif()
target_include_directories(libshogun ${SYSTEM} ${SHOGUN_INCLUDE_DIRS_SCOPE} ${DIRS})
target_include_directories(shogun ${SYSTEM} ${SHOGUN_INCLUDE_DIRS_SCOPE} ${DIRS})
if (LIBSHOGUN_BUILD_STATIC)
target_include_directories(shogun-static ${SYSTEM} ${SHOGUN_INCLUDE_DIRS_SCOPE} ${DIRS})
Expand Down Expand Up @@ -328,3 +322,11 @@ function(ADD_SHOGUN_BENCHMARK REL_BENCHMARK_NAME)
set_tests_properties(${BENCHMARK_NAME} PROPERTIES ${ARGN})
endif()
endfunction()


macro(ADD_SHOGUN_DEPENDENCY DEPENDENT)
add_dependencies(shogun ${DEPENDENT})
if (LIBSHOGUN_BUILD_STATIC)
add_dependencies(shogun-static ${DEPENDENT})
endif()
endmacro()
2 changes: 1 addition & 1 deletion cmake/external/ARPREC.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ExternalProject_Add(

SET(ARPREC_INCLUDE_DIR ${THIRD_PARTY_DIR}/include/arprec)
SET(ARPREC_LIBRARIES ${THIRD_PARTY_DIR}/libs/arprec/libarprec.a)
LIST(APPEND SHOGUN_DEPENDS ARPREC)
ADD_SHOGUN_DEPENDENCY(ARPREC)
2 changes: 1 addition & 1 deletion cmake/external/ColPack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ ExternalProject_Add(
SET(COLPACK_INCLUDE_DIRS ${THIRD_PARTY_DIR}/include/ColPack)
SET(COLPACK_LDFLAGS ${THIRD_PARTY_DIR}/libs/ColPack/libColPack.a)

LIST(APPEND SHOGUN_DEPENDS COLPACK)
ADD_SHOGUN_DEPENDENCY(COLPACK)
2 changes: 1 addition & 1 deletion cmake/external/Eigen3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ExternalProject_Add(
-DEIGEN_BUILD_PKGCONFIG=0
)

add_dependencies(libshogun Eigen3)
ADD_SHOGUN_DEPENDENCY(Eigen3)

UNSET(C_COMPILER)
UNSET(CXX_COMPILER)
2 changes: 1 addition & 1 deletion cmake/external/Jemalloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ExternalProject_Add(

SET(Jemalloc_INCLUDE_DIR ${THIRD_PARTY_DIR}/include/jemalloc)
SET(Jemalloc_LIBRARIES ${THIRD_PARTY_DIR}/libs/jemalloc/libjemalloc_pic.a)
add_dependencies(libshogun Jemalloc)
ADD_SHOGUN_DEPENDENCY(Jemalloc)
2 changes: 1 addition & 1 deletion cmake/external/MSIntTypes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ ExternalProject_Add(

ExternalProject_Get_Property(MSIntTypes SOURCE_DIR)
SET(MSINTTYPES_INCLUDE_DIR ${SOURCE_DIR})
add_dependencies(libshogun MSIntTypes)
ADD_SHOGUN_DEPENDENCY(MSIntTypes)
2 changes: 1 addition & 1 deletion cmake/external/NLopt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ExternalProject_Add(

SET(NLOPT_INCLUDE_DIR ${THIRD_PARTY_DIR}/include/nlopt)
SET(NLOPT_LIBRARIES ${THIRD_PARTY_DIR}/libs/nlopt/libnlopt.a)
LIST(APPEND SHOGUN_DEPENDS NLopt)
ADD_SHOGUN_DEPENDENCY(NLopt)
2 changes: 1 addition & 1 deletion cmake/external/RapidJSON.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ ExternalProject_Add(
INSTALL_COMMAND ""
)

LIST(APPEND SHOGUN_DEPENDS RapidJSON)
ADD_SHOGUN_DEPENDENCY(RapidJSON)
2 changes: 1 addition & 1 deletion cmake/external/TCMalloc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ ExternalProject_Add(

SET(TCMalloc_INCLUDE_DIR ${THIRD_PARTY_DIR}/include/tcmalloc)
SET(TCMalloc_LIBRARIES ${THIRD_PARTY_DIR}/libs/tcmalloc/libtcmalloc_minimal.a)
add_dependencies(libshogun TCMalloc)
ADD_SHOGUN_DEPENDENCY(TCMalloc)
2 changes: 1 addition & 1 deletion cmake/external/TFLogger.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ExternalProject_Add(
BUILD_COMMAND ""
)

add_dependencies(libshogun tflogger)
ADD_SHOGUN_DEPENDENCY(tflogger)

set(TFLogger_INCLUDE_DIR ${THIRD_PARTY_INCLUDE_DIR})

Expand Down
2 changes: 1 addition & 1 deletion cmake/external/bitsery.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ ExternalProject_Add(
INSTALL_COMMAND ""
)

LIST(APPEND SHOGUN_DEPENDS bitsery)
ADD_SHOGUN_DEPENDENCY(bitsery)
3 changes: 1 addition & 2 deletions cmake/external/rxcpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ ExternalProject_Add(
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory ${RXCPP_SOURCE_DIR}/src/Rx/v2/src/ ${THIRD_PARTY_INCLUDE_DIR}/
)

add_dependencies(libshogun rxcpp)

set(rxcpp_INCLUDE_DIR ${THIRD_PARTY_INCLUDE_DIR})
ADD_SHOGUN_DEPENDENCY(rxcpp)
2 changes: 1 addition & 1 deletion cmake/external/variant.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ ExternalProject_Add(
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_if_different ${VARIANT_SOURCE_DIR}/${VARIANT_RELEASE_VERSION}/variant.hpp ${VARIANT_INCLUDE_DIR}/variant.hpp
)

add_dependencies(libshogun variant)
ADD_SHOGUN_DEPENDENCY(variant)
10 changes: 2 additions & 8 deletions examples/meta/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ FOREACH(META_EXAMPLE ${META_EXAMPLES})
# assume a structure <target_language>/<category>/listing.sg
GET_META_EXAMPLE_VARS(${META_EXAMPLE} EXAMPLE_NAME EXAMPLE_REL_DIR EXAMPLE_NAME_WITH_DIR)

if(WIN32)
SET(SHOGUN_LIBRARY shogun::shogun-static)
else()
SET(SHOGUN_LIBRARY shogun::shogun)
endif()

# meta examples have to be generated before executable and test is added
SET(GENERATED_CPP ${EXAMPLE_REL_DIR}/${EXAMPLE_NAME}.cpp)
SET(GENERATED_CPP_BINARY cpp-${EXAMPLE_REL_DIR}-${EXAMPLE_NAME})
Expand All @@ -20,10 +14,10 @@ FOREACH(META_EXAMPLE ${META_EXAMPLES})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXAMPLE_REL_DIR})

ADD_EXECUTABLE(${GENERATED_CPP_BINARY} ${GENERATED_CPP})
ADD_DEPENDENCIES(${GENERATED_CPP_BINARY} meta_examples ${SHOGUN_LIBRARY})
ADD_DEPENDENCIES(${GENERATED_CPP_BINARY} meta_examples shogun::shogun)
SET_SOURCE_FILES_PROPERTIES(${GENERATED_CPP} PROPERTIES GENERATED 1)

TARGET_LINK_LIBRARIES(${GENERATED_CPP_BINARY} ${SHOGUN_LIBRARY} ${SANITIZER_LIBRARY})
TARGET_LINK_LIBRARIES(${GENERATED_CPP_BINARY} shogun::shogun ${SANITIZER_LIBRARY})

# Suppress unused variable warnings
# if we are not testing the meta_examples
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/swig/SGBase.i
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ public void readExternal(java.io.ObjectInput in) throws java.io.IOException, jav
%shared_ptr(shogun::RandomMixin<shogun::SGObject, std::mt19937_64>)
%shared_ptr(shogun::StoppableSGObject)

// ignore SHOGUN_EXPORT
#define SHOGUN_EXPORT
#define SHOGUN_DEPRECATED

%include <shogun/lib/common.h>
%include <shogun/lib/exception/ShogunException.h>

Expand Down

0 comments on commit 682862a

Please sign in to comment.