diff --git a/CMakeLists.txt b/CMakeLists.txt index bd9e8180..65e9fb65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,10 @@ cmake_minimum_required(VERSION 3.10) project(Vita3K) +# Detects the amount of processors of the host machine and forwards the restult to CPU_COUNT +include(ProcessorCount) +ProcessorCount(CPU_COUNT) + set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -16,7 +20,54 @@ endif() enable_testing() -macro(pre_configure_boost) +############################ +########## Boost ########### +############################ + +# Configures Boost +macro(boost_configure) + # Sets the location of the source root and the binary installation path for Boost + # Building Boost right at the CMake binary path should allow to build Vita3K for different target platforms + # without having to delete the boost-build folder each time the target platform changes + set(BOOST_SOURCEDIR "${CMAKE_SOURCE_DIR}/external/boost") + set(BOOST_INSTALLDIR "${CMAKE_BINARY_DIR}/external/boost/") + + if (WIN32) + execute_process( + COMMAND ${BOOST_SOURCEDIR}/bootstrap.bat + WORKING_DIRECTORY ${BOOST_SOURCEDIR} + ) + elseif(UNIX) + execute_process( + COMMAND chmod +x ${BOOST_SOURCEDIR}/tools/build/src/engine/build.sh + COMMAND sh ${BOOST_SOURCEDIR}/bootstrap.sh + WORKING_DIRECTORY ${BOOST_SOURCEDIR} + ) + endif() +endmacro(boost_configure) + +# Compiles Boost +macro(boost_compile) + if (CMAKE_SYSTEM_NAME STREQUAL Windows) + execute_process( + COMMAND ${BOOST_SOURCEDIR}/b2 -j${CPU_COUNT} --build-dir=${BOOST_INSTALLDIR} --stagedir=${BOOST_INSTALLDIR} toolset=msvc stage + WORKING_DIRECTORY ${BOOST_SOURCEDIR} + ) + elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) + execute_process( + COMMAND ${BOOST_SOURCEDIR}/b2 -j${CPU_COUNT} --build-dir=${BOOST_INSTALLDIR} --stagedir=${BOOST_INSTALLDIR} stage + WORKING_DIRECTORY ${BOOST_SOURCEDIR} + ) + elseif(CMAKE_SYSTEM_NAME STREQUAL Linux) + execute_process( + COMMAND ${BOOST_SOURCEDIR}/b2 --ignore-site-config -j${CPU_COUNT} --build-dir=${BOOST_INSTALLDIR} --stagedir=${BOOST_INSTALLDIR} stage + WORKING_DIRECTORY ${BOOST_SOURCEDIR} + ) + endif() +endmacro(boost_compile) + +# Adjusts CMake paths to enable Boost as a findable package for other dependencies in the project +macro(boost_set_paths) set (Boost_USE_STATIC_LIBS ON) find_package(Boost COMPONENTS filesystem system program_options QUIET) @@ -27,16 +78,20 @@ macro(pre_configure_boost) message("Setting up ext-boost environment variables") set(BOOST_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/external/boost") set(BOOST_INCLUDEDIR "${BOOST_ROOT}/boost") - set(BOOST_LIBRARYDIR "${CMAKE_CURRENT_SOURCE_DIR}/external/boost-build/lib") + set(BOOST_LIBRARYDIR "${BOOST_INSTALLDIR}/lib") endif() message("Using Boost_VERSION: ${BOOST_ROOT}") message("Using Boost_INCLUDE_DIRS: ${BOOST_INCLUDEDIR}") message("Using Boost_LIBRARY_DIRS: ${BOOST_LIBRARYDIR}") -endmacro(pre_configure_boost) +endmacro(boost_set_paths) + + if(NOT CI) - pre_configure_boost() + boost_configure() + boost_compile() + boost_set_paths() endif() include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/GetStandard.cmake") diff --git a/cmake/toolchain/linux-x64.cmake b/cmake/toolchain/linux-x64.cmake new file mode 100644 index 00000000..92caec50 --- /dev/null +++ b/cmake/toolchain/linux-x64.cmake @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR x64) + +# Fixes issue with setting CMAKE_SYSYEM_NAME manually and the cross-compilation check +if(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) + set(CMAKE_CROSSCOMPILING FALSE) +else() + set(CMAKE_CROSSCOMPILING TRUE) +endif() + +# Compiler settings +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) + +# Disables cross-compilation +if (CMAKE_CROSSCOMPILING) + message(FATAL_ERROR "Vita3K cross-compilation for Linux isn't supported.") +endif() diff --git a/cmake/toolchain/macos-x64.cmake b/cmake/toolchain/macos-x64.cmake new file mode 100644 index 00000000..bc91db09 --- /dev/null +++ b/cmake/toolchain/macos-x64.cmake @@ -0,0 +1,18 @@ +set(CMAKE_SYSTEM_NAME Darwin) +set(CMAKE_SYSTEM_PROCESSOR x64) + +# Fixes issue with setting CMAKE_SYSYEM_NAME manually and the cross-compilation check +if(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) + set(CMAKE_CROSSCOMPILING FALSE) +else() + set(CMAKE_CROSSCOMPILING TRUE) +endif() + +# Compiler settings +set(CMAKE_C_COMPILER clang) +set(CMAKE_CXX_COMPILER clang++) + +# Disables cross-compilation +if (CMAKE_CROSSCOMPILING) + message(FATAL_ERROR "Vita3K cross-compilation for macOS isn't supported.") +endif() diff --git a/cmake/toolchain/windows-x64.cmake b/cmake/toolchain/windows-x64.cmake new file mode 100644 index 00000000..e286e66c --- /dev/null +++ b/cmake/toolchain/windows-x64.cmake @@ -0,0 +1,17 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR x64) + +# Fixes issue with setting CMAKE_SYSYEM_NAME manually and the cross-compilation check +if(CMAKE_HOST_SYSTEM_NAME STREQUAL CMAKE_SYSTEM_NAME) + set(CMAKE_CROSSCOMPILING FALSE) +else() + set(CMAKE_CROSSCOMPILING TRUE) +endif() + +# Compiler settings +set(CMAKE_C_COMPILER cl) +set(CMAKE_CXX_COMPILER cl) + +if (CMAKE_CROSSCOMPILING) + message(FATAL_ERROR "Vita3K cross-compilation for Windows isn't supported.") +endif()