Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If we are building mlpack statically then build executable statically #2931

Merged
merged 7 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ Options are specified with the -D flag. The allowed options include:
BUILD_R_BINDINGS=(ON/OFF): whether or not to build R bindings
R_EXECUTABLE=(/path/to/R): Path to specific R executable
BUILD_TESTS=(ON/OFF): whether or not to build tests
BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries as opposed to
static libraries
BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries and executables as
opposed to static libraries
DISABLE_DOWNLOADS=(ON/OFF): whether to disable all downloads during build
DOWNLOAD_ENSMALLEN=(ON/OFF): If ensmallen is not found, download it
ENSMALLEN_INCLUDE_DIR=(/path/to/ensmallen/include): path to include directory
Expand All @@ -224,6 +224,11 @@ Options are specified with the -D flag. The allowed options include:
BUILD_DOCS=(ON/OFF): build Doxygen documentation, if Doxygen is available
(default ON)

For example, to build mlpack library and CLI bindings statically the following
command can be used:

$ cmake -D BUILD_SHARED_LIBS=OFF ../

Other tools can also be used to configure CMake, but those are not documented
here. See [this section of the build guide](https://www.mlpack.org/doc/mlpack-git/doxygen/build.html#build_config)
for more details, including a full list of options, and their default values.
Expand Down
14 changes: 12 additions & 2 deletions doc/guide/build.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ The full list of options mlpack allows:
and Gonum exist. (default OFF)
- BUILD_JULIA_BINDINGS=(ON/OFF): compile Julia bindings, if Julia is found
(default OFF)
- BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries as opposed to
- BUILD_SHARED_LIBS=(ON/OFF): compile shared libraries and executables as opposed to
static libraries (default ON)
- TEST_VERBOSE=(ON/OFF): run test cases in \c mlpack_test with verbose output
(default OFF)
Expand All @@ -209,17 +209,27 @@ The full list of options mlpack allows:
Each option can be specified to CMake with the '-D' flag. Other tools can also
be used to configure CMake, but those are not documented here.

For example, if you would like to build mlpack and its CLI bindings statically, then
you need to execute the following commands:

@code
$ cd build
$ cmake -D BUILD_SHARED_LIBS=OFF ../
@endcode

In addition, the following directories may be specified, to find include files
and libraries. These also use the '-D' flag.

- ARMADILLO_INCLUDE_DIR=(/path/to/armadillo/include/): path to Armadillo headers
- ARMADILLO_LIBRARY=(/path/to/armadillo/libarmadillo.so): location of Armadillo
library
- BOOST_ROOT=(/path/to/boost/): path to root of boost installation
- CEREAL_INCLUDE_DIR=(/path/to/cereal/include): path to include directory for
cereal
- ENSMALLEN_INCLUDE_DIR=(/path/to/ensmallen/include): path to include directory
for ensmallen
- STB_IMAGE_INCLUDE_DIR=(/path/to/stb/include): path to include directory for
STB image library
STB image library
- MATHJAX_ROOT=(/path/to/mathjax): path to root of MathJax installation

@section build_build Building mlpack
Expand Down
20 changes: 15 additions & 5 deletions src/mlpack/bindings/cli/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 15 additions & 6 deletions src/mlpack/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down