diff --git a/src/mlpack/bindings/cli/CMakeLists.txt b/src/mlpack/bindings/cli/CMakeLists.txt index 4b94805fe5..8ebc20583a 100644 --- a/src/mlpack/bindings/cli/CMakeLists.txt +++ b/src/mlpack/bindings/cli/CMakeLists.txt @@ -50,11 +50,21 @@ if (BUILD_CLI_EXECUTABLES) add_executable(mlpack_${name} ${name}_main.cpp ) - target_link_libraries(mlpack_${name} - mlpack - ${ARMADILLO_LIBRARIES} - ${COMPILER_SUPPORT_LIBRARIES} - ) + # Build mlpack CLI binding binaries statically. + if(NOT BUILD_SHARED_LIBS) + target_link_libraries(mlpack_${name} -static + mlpack + ${ARMADILLO_LIBRARIES} + ${COMPILER_SUPPORT_LIBRARIES} + ) + else() + # Build mlpack CLI binding binaries dynamically. + target_link_libraries(mlpack_${name} + mlpack + ${ARMADILLO_LIBRARIES} + ${COMPILER_SUPPORT_LIBRARIES} + ) + endif() # Make sure that we set BINDING_TYPE to cli so the command-line program is # compiled with the correct int main() call. set_target_properties(mlpack_${name} PROPERTIES COMPILE_FLAGS diff --git a/src/mlpack/tests/CMakeLists.txt b/src/mlpack/tests/CMakeLists.txt index de0f56d8df..0695ccb7b7 100644 --- a/src/mlpack/tests/CMakeLists.txt +++ b/src/mlpack/tests/CMakeLists.txt @@ -175,12 +175,21 @@ add_executable(mlpack_test main_tests/test_helper.hpp ) -# Link dependencies of test executable. -target_link_libraries(mlpack_test - mlpack - ${ARMADILLO_LIBRARIES} - ${COMPILER_SUPPORT_LIBRARIES} -) +if(NOT BUILD_SHARED_LIBS) +# Build mlpack test executable statically. + target_link_libraries(mlpack_test -static + mlpack + ${ARMADILLO_LIBRARIES} + ${COMPILER_SUPPORT_LIBRARIES} + ) +else() + # Build mlpack test executable dynamically. + target_link_libraries(mlpack_test + mlpack + ${ARMADILLO_LIBRARIES} + ${COMPILER_SUPPORT_LIBRARIES} + ) +endif() set_target_properties(mlpack_test PROPERTIES COTIRE_CXX_PREFIX_HEADER_INIT "../core.hpp") cotire(mlpack_test)