Skip to content
Snippets Groups Projects
Commit b0ddd38e authored by Martin Beseda's avatar Martin Beseda
Browse files

ENH: Added compilation parallelism even for Windows

parent e086ee2a
No related branches found
No related tags found
No related merge requests found
...@@ -3,14 +3,40 @@ project(lib4neuro) ...@@ -3,14 +3,40 @@ project(lib4neuro)
message("Using CMake ${CMAKE_VERSION}") message("Using CMake ${CMAKE_VERSION}")
#TODO request newer version of CMake >=3.12 #TODO request newer version of CMake >=3.13
#TODO use 'option' instead of 'set' for boolean variables! #TODO use 'option' instead of 'set' for boolean variables!
#-------------------------------------#
# Set a flag for parallel compilation #
#-------------------------------------#
set(ENV{PARALLEL_BUILD_FLAG} "-j")
if(WIN32)
set(ENV{PARALLEL_BUILD_FLAG} "/MP")
endif()
#------------------------------------------#
# Detect maximum available number of cores #
# and set corresponding build options #
#------------------------------------------#
message("Detecting available cores count...")
include(ProcessorCount)
ProcessorCount(N_CORES)
if(N_CORES GREATER 1)
math(EXPR N_CORES "${N_CORES}-1")
set(CTEST_BUILD_FLAGS ${PARALLEL_BUILD_FLAG}${N_CORES})
set(ENV{N_CORES} ${N_CORES})
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N_CORES})
endif()
set(ENV{CMAKE_BUILD_PARALLEL_LEVEL} ${CMAKE_MAKE_PROGRAM})
message("Build will be performed on ${N_CORES} cores.")
#TODO rewrite to use add_compile_definitions #TODO rewrite to use add_compile_definitions
#TODO use just locally, where needed
if(WIN32) if(WIN32)
add_compile_options("/D BOOST_ALL_NO_LIB") add_compile_options("/D BOOST_ALL_NO_LIB")
add_compile_options("/D NOMINMAX") add_compile_options("/D NOMINMAX")
add_compile_options("${PARALLEL_BUILD_FLAG} ${N_CORES}")
else() else()
add_compile_options("-DBOOST_TEST_DYN_LINK") add_compile_options("-DBOOST_TEST_DYN_LINK")
endif() endif()
...@@ -71,21 +97,6 @@ if (NOT ${MATCH} STREQUAL ${CMAKE_CURRENT_LIST_DIR}) ...@@ -71,21 +97,6 @@ if (NOT ${MATCH} STREQUAL ${CMAKE_CURRENT_LIST_DIR})
message(FATAL_ERROR "Illegal character(s) found in the path to the current directory!") message(FATAL_ERROR "Illegal character(s) found in the path to the current directory!")
endif() endif()
#------------------------------------------#
# Detect maximum available number of cores #
# and set corresponding build options #
#------------------------------------------#
message("Detecting available cores count...")
include(ProcessorCount)
ProcessorCount(N_CORES)
if(N_CORES GREATER 1)
math(EXPR N_CORES "${N_CORES}-1")
set(CTEST_BUILD_FLAGS -j${N_CORES})
set(ENV{N_CORES} ${N_CORES})
set(ctest_test_args ${ctest_test_args} PARALLEL_LEVEL ${N_CORES})
endif()
message("Build will be performed on ${N_CORES} cores.")
#---------------# #---------------#
# Set variables # # Set variables #
#---------------# #---------------#
...@@ -121,9 +132,6 @@ option(ALLOW_DEPENDENCIES_DOWNLOAD "Allow external dependencies to be downloaded ...@@ -121,9 +132,6 @@ option(ALLOW_DEPENDENCIES_DOWNLOAD "Allow external dependencies to be downloaded
option(Boost_USE_MULTITHREADED ON) option(Boost_USE_MULTITHREADED ON)
option(Boost_DEBUG OFF) option(Boost_DEBUG OFF)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(Boost_DEBUG ON)
endif()
find_package( find_package(
Boost Boost
......
...@@ -42,10 +42,10 @@ FetchContent_Populate(boost) ...@@ -42,10 +42,10 @@ FetchContent_Populate(boost)
############### ###############
set(BOOTSTRAP_CMD sh bootstrap.sh) set(BOOTSTRAP_CMD sh bootstrap.sh)
set(B2_CMD ./b2 -j${N_CORES}) set(B2_CMD ./b2 ${PARALLEL_BUILD_FLAG}${N_CORES})
if(WIN32) if(WIN32)
set(BOOTSTRAP_CMD bootstrap.bat) set(BOOTSTRAP_CMD bootstrap.bat)
set(B2_CMD b2 -j${N_CORES}) set(B2_CMD b2 ${PARALLEL_BUILD_FLAG}${N_CORES})
endif() endif()
execute_process( execute_process(
......
...@@ -29,13 +29,17 @@ if(NOT rv STREQUAL "0") ...@@ -29,13 +29,17 @@ if(NOT rv STREQUAL "0")
message("OpenBLAS build: cmake .: ${rv}") message("OpenBLAS build: cmake .: ${rv}")
endif() endif()
# Add a compile flag -lgfortran and -lpthreads
set_target_properties(${LIB_PREFIX}openblas.${LIB_SUFFIX} LINK_FLAGS "-lgfortran -lpthreads")
# Build library
execute_process( execute_process(
COMMAND cmake --build . -j ${N_CORES} --config Release COMMAND cmake --build . ${PARALLEL_BUILD_FLAG} ${N_CORES} --config Release
WORKING_DIRECTORY ${OPENBLAS_LOCAL_PATH} WORKING_DIRECTORY ${OPENBLAS_LOCAL_PATH}
RESULT_VARIABLE rv RESULT_VARIABLE rv
) )
if(NOT rv STREQUAL "0") if(NOT rv STREQUAL "0")
message("OpenBLAS build: cmake --build . -j ${N_CORES}: ${rv}") message("OpenBLAS build: cmake --build . ${PARALLEL_BUILD_FLAG} ${N_CORES}: ${rv}")
endif() endif()
set(OpenBLAS_DIR ${CMAKE_CURRENT_LIST_DIR}/external_dependencies/OpenBLAS) set(OpenBLAS_DIR ${CMAKE_CURRENT_LIST_DIR}/external_dependencies/OpenBLAS)
......
...@@ -112,11 +112,11 @@ then ...@@ -112,11 +112,11 @@ then
cd ../.. cd ../..
cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_C_COMPILER=${C_COMPILER} -DBOOST_LIBRARYDIR=${BOOST_LIBRARYDIR} -DBOOST_INCLUDEDIR=${BOOST_INCLUDEDIR} -DBUILD_TESTS=${BUILD_TESTS} -DBUILD_EXAMPLES=${BUILD_EXAMPLES} -DBUILD_LIB=${BUILD_LIB} -DLIB4NEURO_DIR=${PWD}/build/lib -DDEPENDENCIES_LINK_TYPE=${LINK_TYPE} -DLIB4NEURO_INCLUDE_DIR=${LIB4NEURO_INCLUDE_DIR} . || { echo "${RED}Makefile preparation finished with errors${NC}!"; BUILD_ERROR_OCCURED=1; } cmake -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=${CXX_COMPILER} -DCMAKE_C_COMPILER=${C_COMPILER} -DBOOST_LIBRARYDIR=${BOOST_LIBRARYDIR} -DBOOST_INCLUDEDIR=${BOOST_INCLUDEDIR} -DBUILD_TESTS=${BUILD_TESTS} -DBUILD_EXAMPLES=${BUILD_EXAMPLES} -DBUILD_LIB=${BUILD_LIB} -DDEPENDENCIES_LINK_TYPE=${LINK_TYPE} . || { echo "${RED}Makefile preparation finished with errors${NC}!"; BUILD_ERROR_OCCURED=1; }
if [ ${BUILD_ERROR_OCCURED} = "0" ] if [ ${BUILD_ERROR_OCCURED} = "0" ]
then then
echo "Building the '${CYAN}lib4neuro${NC}' project for ${WHITE}Debug${NC} (building)" echo "Building the '${CYAN}lib4neuro${NC}' project for ${WHITE}Debug${NC} (building)"
cmake --build . --config Debug -- -j${N_CORES} && echo "${GREEN}Build complete${NC}." || { echo "${RED}Build finished with errors${NC}!"; BUILD_ERROR_OCCURED=1; } cmake --build . --config Debug -- ${PARALLEL_BUILD_FLAG}${N_CORES} && echo "${GREEN}Build complete${NC}." || { echo "${RED}Build finished with errors${NC}!"; BUILD_ERROR_OCCURED=1; }
fi fi
cd build_scripts/linux cd build_scripts/linux
......
...@@ -108,7 +108,7 @@ IF "%BUILD_SOMETHING_LIB%"=="yes" ( ...@@ -108,7 +108,7 @@ IF "%BUILD_SOMETHING_LIB%"=="yes" (
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=%CXX_COMPILER% -DCMAKE_C_COMPILER=%C_COMPILER% -DBOOST_ROOT=%BOOST_ROOT% -DBOOST_LIBRARYDIR=%BOOST_LIBRARYDIR% -DBOOST_INCLUDEDIR=%BOOST_INCLUDEDIR% -DBUILD_TESTS=%BUILD_TESTS% -DBUILD_EXAMPLES=%BUILD_EXAMPLES% -DBUILD_LIB=%BUILD_LIB% -DLIB4NEURO_DIR=build\lib -DDEPENDENCIES_LINK_TYPE=%LINK_TYPE% -DLIB4NEURO_INCLUDE_DIR=%LIB4NEURO_INCLUDE_DIR% . || goto error_occured_lib cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=%CXX_COMPILER% -DCMAKE_C_COMPILER=%C_COMPILER% -DBOOST_ROOT=%BOOST_ROOT% -DBOOST_LIBRARYDIR=%BOOST_LIBRARYDIR% -DBOOST_INCLUDEDIR=%BOOST_INCLUDEDIR% -DBUILD_TESTS=%BUILD_TESTS% -DBUILD_EXAMPLES=%BUILD_EXAMPLES% -DBUILD_LIB=%BUILD_LIB% -DLIB4NEURO_DIR=build\lib -DDEPENDENCIES_LINK_TYPE=%LINK_TYPE% -DLIB4NEURO_INCLUDE_DIR=%LIB4NEURO_INCLUDE_DIR% . || goto error_occured_lib
rem cmake -G "mingw32-make" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=%CXX_COMPILER% -DCMAKE_C_COMPILER=%C_COMPILER% -DBOOST_ROOT=%BOOST_ROOT% -DBOOST_LIBRARYDIR=%BOOST_LIBRARYDIR% -DBOOST_INCLUDEDIR=%BOOST_INCLUDEDIR% -DBUILD_TESTS=%BUILD_TESTS% -DBUILD_EXAMPLES=%BUILD_EXAMPLES% -DBUILD_LIB=%BUILD_LIB% -DLIB4NEURO_DIR=build\lib -DDEPENDENCIES_LINK_TYPE=%LINK_TYPE% -DLIB4NEURO_INCLUDE_DIR=%LIB4NEURO_INCLUDE_DIR% . || goto error_occured_lib rem cmake -G "mingw32-make" -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=%CXX_COMPILER% -DCMAKE_C_COMPILER=%C_COMPILER% -DBOOST_ROOT=%BOOST_ROOT% -DBOOST_LIBRARYDIR=%BOOST_LIBRARYDIR% -DBOOST_INCLUDEDIR=%BOOST_INCLUDEDIR% -DBUILD_TESTS=%BUILD_TESTS% -DBUILD_EXAMPLES=%BUILD_EXAMPLES% -DBUILD_LIB=%BUILD_LIB% -DLIB4NEURO_DIR=build\lib -DDEPENDENCIES_LINK_TYPE=%LINK_TYPE% -DLIB4NEURO_INCLUDE_DIR=%LIB4NEURO_INCLUDE_DIR% . || goto error_occured_lib
title Building the 'lib4neuro' project for Debug [building] title Building the 'lib4neuro' project for Debug [building]
cmake --build . --config Debug && echo "Build complete." || goto error_occured_lib cmake --build . ${PARALLEL_BUILD_FLAG}${N_CORES} --config Debug && echo "Build complete." || goto error_occured_lib
cd build_scripts\windows cd build_scripts\windows
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment