Permalink
Browse files

Enable selective CMake configuration, improve messaging (#1678)

* Enable building only parts of vowpal wabbit

* update readme

* Add BUILD_PYTHON to setup.py
  • Loading branch information...
jackgerrits authored and lokitoth committed Nov 13, 2018
1 parent 7222467 commit fdc14769939a81ca393575b477df72fbb6681912
Showing with 85 additions and 42 deletions.
  1. +30 −14 CMakeLists.txt
  2. +13 −3 README.md
  3. +2 −2 build-linux.sh
  4. +4 −2 cluster/CMakeLists.txt
  5. +6 −4 java/CMakeLists.txt
  6. +3 −1 python/CMakeLists.txt
  7. +1 −0 python/setup.py
  8. +26 −16 vowpalwabbit/CMakeLists.txt
@@ -14,11 +14,11 @@ endif()
# Read version into variable
file(READ version.txt PACKAGE_VERSION)
string(STRIP ${PACKAGE_VERSION} PACKAGE_VERSION)
message("Version: ${PACKAGE_VERSION}")
message(STATUS "VowpalWabbit Version: ${PACKAGE_VERSION}")

include(ProcessorCount)
ProcessorCount(NumProcessors)
message("Number of processors: ${NumProcessors}")
message(STATUS "Number of processors: ${NumProcessors}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/nprocs.txt ${NumProcessors})

set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug, Release" FORCE)
@@ -28,7 +28,12 @@ option(VALGRIND_PROFILE "Turn on flags required for profiling with valgrind" OFF
option(GCOV "Turn on flags required for gcov" OFF)
option(WARNINGS "Turn on warning flags. ON by default." ON)
option(STATIC_LINK_VW "Link VW executable statically. Off by default." OFF)
option(VW_TEST "Turn on CMake testing target. On by default." ON)

option(VW_INSTALL "Add install targets." ON)
option(BUILD_TESTS "Build and enable tests." ON)
option(BUILD_JAVA "Add Java targets." Off)
option(BUILD_PYTHON "Add Python targets." Off)
option(BUILD_DOCS "Add documentation targets." Off)

# Add -ffast-math for speed, remove for testability.
set(linux_release_config -O3 -fomit-frame-pointer -fno-strict-aliasing -msse2 -mfpmath=sse)
@@ -83,29 +88,40 @@ find_package(ZLIB REQUIRED)

add_subdirectory(cluster)
add_subdirectory(library)
add_subdirectory(doc)
add_subdirectory(vowpalwabbit)
add_subdirectory(java)
add_subdirectory(python)

if(VW_TEST)
enable_testing()
if(BUILD_DOCS)
add_subdirectory(doc)
endif()
add_subdirectory(test)

# Don't offer these make dependent targets on Windows
if(NOT WIN32)
if(BUILD_JAVA)
add_subdirectory(java)
endif()

if(BUILD_PYTHON)
add_subdirectory(python)
endif()

if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)

# Don't offer these make dependent targets on Windows
if(NOT WIN32)
# make bigtests BIG_TEST_ARGS="<args here>"
add_custom_target(bigtests
DEPENDS vw
COMMAND make \${BIG_TEST_ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/big_tests)
endif()
endif()

# TODO convert cs directory to cmake
# TODO convert c_test directory to cmake

# PkgConfig
configure_file(libvw.pc.in libvw.pc)
configure_file(libvw_c_wrapper.pc.in libvw_c_wrapper.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libvw.pc ${CMAKE_CURRENT_BINARY_DIR}/libvw_c_wrapper.pc DESTINATION lib/pkgconfig)
if(VW_INSTALL)
configure_file(libvw.pc.in libvw.pc)
configure_file(libvw_c_wrapper.pc.in libvw_c_wrapper.pc)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libvw.pc ${CMAKE_CURRENT_BINARY_DIR}/libvw_c_wrapper.pc DESTINATION lib/pkgconfig)
endif()
@@ -88,12 +88,17 @@ cmake .. -DCMAKE_TOOLCHAIN_FILE=<vcpkg root>/scripts/buildsystems/vcpkg.cmake

The CMake definition supports the following options that can be set when invoking `cmake`:
```
CMAKE_BUILD_TYPE - Controls base flags for building. Release includes optimization, Debug is unoptimized. ([Debug|Release], default: Debug)
CMAKE_BUILD_TYPE - Controls base flags for building. Release includes optimization, Debug is unoptimized ([Debug|Release], default: Debug)
PROFILE - Turn on flags required for profiling ([ON|OFF], default: OFF)
VALGRIND_PROFILE - Turn on flags required for profiling with valgrind in gcc ([ON|OFF], default: OFF)
GCOV - Turn on flags required for code coverage in gcc ([ON|OFF], default: OFF)
WARNINGS - Turn on warning flags. ([ON|OFF], default: ON)
WARNINGS - Turn on warning flags ([ON|OFF], default: ON)
STATIC_LINK_VW - Link VW executable statically ([ON|OFF], default: OFF)
VW_INSTALL - Add install targets ([ON|OFF], default: ON)
BUILD_TESTS - Build and enable tests ([ON|OFF], default: ON)
BUILD_JAVA - Add Java targets ([ON|OFF], default: Off)
BUILD_PYTHON - Add Python targets ([ON|OFF], default: Off)
BUILD_DOCS - Add documentation targets ([ON|OFF], default: Off)
```

Options can be specified at configuration time on the command line:
@@ -233,7 +238,12 @@ python setup.py install
## Code Documentation
To browse the code more easily, do

`make doc`
```
mkdir build
cd build
cmake .. -DBUILD_DOCS=On
make doc
```

and then point your browser to `doc/html/index.html`.

@@ -19,7 +19,7 @@ sudo ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
cd /vw
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DWARNINGS=Off -DDO_NOT_BUILD_VW_C_WRAPPER=On
cmake .. -DCMAKE_BUILD_TYPE=Release -DWARNINGS=Off -DDO_NOT_BUILD_VW_C_WRAPPER=On -DBUILD_JAVA=On -DBUILD_PYTHON=On -DBUILD_TESTS=On
NUM_PROCESSORS=$(cat nprocs.txt)
make all -j ${NUM_PROCESSORS}
make test_with_output
@@ -42,7 +42,7 @@ cd ..
rm -rf build
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DGCOV=ON -DWARNINGS=OFF
cmake .. -DCMAKE_BUILD_TYPE=Release -DGCOV=ON -DWARNINGS=OFF -DBUILD_JAVA=Off -DBUILD_PYTHON=Off -DBUILD_TESTS=On
make vw-bin -j ${NUM_PROCESSORS}
cd ..
cd test
@@ -13,5 +13,7 @@ endif()
target_include_directories(spanning_tree PRIVATE ${vowpal_wabbit_dir})
target_link_libraries(spanning_tree PRIVATE Threads::Threads)

install(TARGETS spanning_tree
RUNTIME DESTINATION bin)
if(VW_INSTALL)
install(TARGETS spanning_tree
RUNTIME DESTINATION bin)
endif()
@@ -48,8 +48,10 @@ if(JNI_FOUND)
set(JAVA_INSTALL_PATH /Library/Java/Extensions)
endif()

install(TARGETS vw_jni
RUNTIME DESTINATION ${JAVA_INSTALL_PATH}
LIBRARY DESTINATION ${JAVA_INSTALL_PATH}
)
if(VW_INSTALL)
install(TARGETS vw_jni
RUNTIME DESTINATION ${JAVA_INSTALL_PATH}
LIBRARY DESTINATION ${JAVA_INSTALL_PATH}
)
endif()
endif()
@@ -1,5 +1,8 @@
if(NOT DEFINED PY_VERSION)
set(PY_VERSION 2.7)
message(WARNING "No PY_VERSION specified, Python ${PY_VERSION} will be used for VowpalWabbit Python bindings")
else()
message(STATUS "Python ${PY_VERSION} will be used for VowpalWabbit Python bindings")
endif()
string(REPLACE . "" PY_VERSION_STRIPPED ${PY_VERSION})

@@ -15,7 +18,6 @@ else(Boost_MINOR_VERSION GREATER 66)
endif(PY_VERSION_STRIPPED_FIRST_CHAR STREQUAL "2")
endif(Boost_MINOR_VERSION GREATER 66)

message("Building Python module for Python version ${PY_VERSION}")
find_package(PythonLibs ${PY_VERSION} REQUIRED)
find_package(Boost REQUIRED COMPONENTS system python${BOOST_PY_VERSION_SUFFIX})

@@ -44,6 +44,7 @@ def build_cmake(self, ext):
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(lib_output_dir),
'-DCMAKE_BUILD_TYPE=' + config,
'-DPY_VERSION=' + '{v[0]}.{v[1]}'.format(v=version_info),
'-DBUILD_PYTHON=On',
'-DWARNINGS=Off'
]

@@ -97,9 +97,12 @@ endif(WARNINGS)
if(NOT WIN32)
add_executable(active_interactor active_interactor.cc)

install(TARGETS active_interactor
RUNTIME DESTINATION bin
)
if(VW_INSTALL)
install(TARGETS active_interactor
RUNTIME DESTINATION bin
)
endif()


target_compile_definitions(active_interactor PUBLIC _FILE_OFFSET_BITS=64)
target_compile_definitions(active_interactor PUBLIC $<$<CONFIG:RELEASE>:NDEBUG>)
@@ -113,7 +116,10 @@ if(NOT WIN32)
--name="Vowpal Wabbit -- fast online learning tool" $<TARGET_FILE:vw-bin>
--output=$<TARGET_FILE:vw-bin>.1
DEPENDS vw-bin)
install(FILES $<TARGET_FILE:vw-bin>.1 DESTINATION share/man/man1)

if(VW_INSTALL)
install(FILES $<TARGET_FILE:vw-bin>.1 DESTINATION share/man/man1)
endif()
else()
message(STATUS "help2man not found, please install it to generate manpages")
endif()
@@ -135,23 +141,27 @@ if(NOT DEFINED DO_NOT_BUILD_VW_C_WRAPPER)
target_compile_definitions(vw_c_wrapper PUBLIC VWDLL_EXPORTS _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_DEPRECATE ZLIB_WINAPI)
target_link_libraries(vw_c_wrapper PUBLIC vw)

install(TARGETS vw_c_wrapper
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
if(VW_INSTALL)
install(TARGETS vw_c_wrapper
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
endif()
endif()

# Install executables
install(TARGETS vw-bin
if(VW_INSTALL)
# Install executables
install(TARGETS vw-bin
RUNTIME DESTINATION bin
)
)

# Install headers
install(FILES ${vw_install_headers} ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include/vowpalwabbit/vowpalwabbit)
install(FILES ${explore_all_headers} DESTINATION include/vowpalwabbit/vowpalwabbit/explore)
# Install headers
install(FILES ${vw_install_headers} ${CMAKE_CURRENT_BINARY_DIR}/config.h DESTINATION include/vowpalwabbit/vowpalwabbit)
install(FILES ${explore_all_headers} DESTINATION include/vowpalwabbit/vowpalwabbit/explore)

# Install libs
install(TARGETS allreduce vw
# Install libs
install(TARGETS allreduce vw
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
endif()

0 comments on commit fdc1476

Please sign in to comment.