Skip to content

Commit

Permalink
external/ci: set macOS minimum version to 11.0 (Vita3K#3361)
Browse files Browse the repository at this point in the history
* external: download MoltenVK when configuring build system

* external: add option to build OpenSSL on macOS

* external: build custom boost with specific arch on macOS

* cmake: unify mixed and wrong indentations with tabs

* vita3K/ci: set macOS minimun version with 11.0
  • Loading branch information
KhoraLee authored Sep 11, 2024
1 parent 206f152 commit c94189d
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 1,247 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- os: macos-latest
version: zip
cache_path: ~/Library/Caches/ccache
extra_cmake_args: -DCMAKE_OSX_ARCHITECTURES="x86_64"
extra_cmake_args: -DCMAKE_OSX_ARCHITECTURES="x86_64" -DFORCE_BUILD_OPENSSL_MAC=ON -DVITA3K_FORCE_CUSTOM_BOOST=ON
cmake_preset: macos-ninja
exclude:
- os: macos-latest
Expand All @@ -61,10 +61,6 @@ jobs:
- name: Set up build environment (macos-latest)
run: |
brew install ccache ninja create-dmg
brew fetch --force --bottle-tag=x86_64_monterey boost openssl@3 molten-vk
brew install $(brew --cache --bottle-tag=x86_64_monterey boost)
brew install $(brew --cache --bottle-tag=x86_64_monterey molten-vk)
brew reinstall $(brew --cache --bottle-tag=x86_64_monterey openssl@3)
echo "$(brew --prefix ccache)/libexec" >> $GITHUB_PATH
ccache --set-config=compiler_check=content
if: matrix.os == 'macos-latest'
Expand Down
248 changes: 131 additions & 117 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,35 @@ project(Vita3K)
include(ProcessorCount)
ProcessorCount(CPU_COUNT)

# Define the Architecture variable, right now it should only contain "x86_64" or "arm64"
include("external/dynarmic/CMakeModules/DetectArchitecture.cmake")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_OSX_DEPLOYMENT_TARGET 12.0)
set(CMAKE_OSX_DEPLOYMENT_TARGET 11.0)

option(USE_DISCORD_RICH_PRESENCE "Build Vita3K with Discord Rich Presence" ON)
option(USE_VITA3K_UPDATE "Build Vita3K with updater." ON)
option(BUILD_APPIMAGE "Build an AppImage." OFF)

option(FORCE_BUILD_OPENSSL_MAC OFF)

if("${CMAKE_CXX_COMPILER_LAUNCHER}" STREQUAL "")
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
endif()

if(MSVC)
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "/Zi" "/Z7" CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO}")
endif()

enable_testing()
Expand All @@ -41,19 +46,19 @@ set(USE_LTO RELEASE_ONLY CACHE STRING "Use interprocedural optimization/link tim
set_property(CACHE USE_LTO PROPERTY STRINGS ${lto_usage_mode})

if (NOT (USE_LTO STREQUAL "NEVER"))
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_supported_error)

if( ipo_supported )
if (USE_LTO STREQUAL "ALWAYS")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif (USE_LTO STREQUAL "RELEASE_ONLY")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
endif()
else()
message(STATUS "IPO / LTO not supported: <${ipo_supported_error}>")
set(USE_LTO NEVER CACHE STRING "Use interprocedural optimization/link time optimization")
endif()
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_supported_error)

if( ipo_supported )
if (USE_LTO STREQUAL "ALWAYS")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
elseif (USE_LTO STREQUAL "RELEASE_ONLY")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE)
endif()
else()
message(STATUS "IPO / LTO not supported: <${ipo_supported_error}>")
set(USE_LTO NEVER CACHE STRING "Use interprocedural optimization/link time optimization")
endif()
endif()


Expand All @@ -67,47 +72,47 @@ macro(b2_build)
execute_process(
COMMAND ${BOOST_SOURCEDIR}/bootstrap.bat --with-toolset=${BOOST_TOOLSET}
WORKING_DIRECTORY ${BOOST_SOURCEDIR}
OUTPUT_QUIET
OUTPUT_QUIET
)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
execute_process(
COMMAND chmod +x ${BOOST_SOURCEDIR}/tools/build/src/engine/build.sh
COMMAND sh ${BOOST_SOURCEDIR}/bootstrap.sh
WORKING_DIRECTORY ${BOOST_SOURCEDIR}
OUTPUT_QUIET
OUTPUT_QUIET
)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
execute_process(
COMMAND chmod +x ${BOOST_SOURCEDIR}/tools/build/src/engine/build.sh
COMMAND sh ${BOOST_SOURCEDIR}/bootstrap.sh --with-toolset=${BOOST_TOOLSET}
WORKING_DIRECTORY ${BOOST_SOURCEDIR}
OUTPUT_QUIET
OUTPUT_QUIET
)
endif()
endmacro(b2_build)

# Macro to compile Boost
macro(boost_compile)
list(TRANSFORM BOOST_MODULES_TO_FIND PREPEND --with- OUTPUT_VARIABLE b2_cmd_line_common)
set(b2_cmd_line_common ${b2} ${b2_cmd_line_common} -j${CPU_COUNT} --build-dir=${BOOST_INSTALLDIR} --stagedir=${BOOST_INSTALLDIR} cxxflags=${BOOST_CXX_FLAGS})
list(TRANSFORM BOOST_MODULES_TO_FIND PREPEND --with- OUTPUT_VARIABLE b2_cmd_line_common)
set(b2_cmd_line_common ${b2} ${b2_cmd_line_common} -j${CPU_COUNT} --build-dir=${BOOST_INSTALLDIR} --stagedir=${BOOST_INSTALLDIR} cxxflags=${BOOST_CXX_FLAGS})
set(Boost_USE_DEBUG_RUNTIME "")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
execute_process(
COMMAND ${b2_cmd_line_common} address-model=64 --architecture=x64 toolset=${BOOST_TOOLSET} variant=debug,release stage
WORKING_DIRECTORY ${BOOST_SOURCEDIR}
OUTPUT_QUIET
OUTPUT_QUIET
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
execute_process(
COMMAND ${b2_cmd_line_common} stage
COMMAND ${b2_cmd_line_common} architecture=${BOOST_ARCHITECTURE} cxxflags="-mmacosx-version-min=11.0" stage
WORKING_DIRECTORY ${BOOST_SOURCEDIR}
OUTPUT_QUIET
OUTPUT_QUIET
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
execute_process(
COMMAND ${b2_cmd_line_common} --ignore-site-config toolset=${BOOST_TOOLSET} stage
WORKING_DIRECTORY ${BOOST_SOURCEDIR}
OUTPUT_QUIET
OUTPUT_QUIET
)
endif()
endmacro(boost_compile)
Expand All @@ -121,89 +126,98 @@ set(BOOST_MODULES_TO_FIND filesystem system)
# If build process isn't set to forcefully use system Boost
macro(get_boost)
if(NOT VITA3K_FORCE_SYSTEM_BOOST)
# find_package(Boost ...) setting
set(Boost_USE_STATIC_LIBS ON)

set(Boost_NO_WARN_NEW_VERSIONS 1)

# First, try to find Boost without any hints (system Boost)
if(NOT VITA3K_FORCE_CUSTOM_BOOST)
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} QUIET)
endif()

# If system Boost hasn't been found, then enable hints to find custom Boost
if (NOT Boost_FOUND)
message(STATUS "A Boost distribution that meets the requirements needed for the project hasn't been found in your system. Falling back to custom Boost distribution...")

# Set path hints for Boost search inside the repository folder and assist in compilation if needed
set(BOOST_SOURCEDIR "${CMAKE_SOURCE_DIR}/external/boost") # For internal use
set(BOOST_INSTALLDIR "${CMAKE_BINARY_DIR}/external/boost") # For internal use
set(BOOST_ROOT "${BOOST_SOURCEDIR}") # find_package(Boost ...) hint
set(BOOST_INCLUDEDIR "${BOOST_SOURCEDIR}") # find_package(Boost ...) hint
set(BOOST_LIBRARYDIR "${BOOST_INSTALLDIR}/lib") # find_package(Boost ...) hint

# Find Boost again to check for a existing compilation of the custom distribution
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} PATHS ${BOOST_INSTALLDIR} QUIET NO_DEFAULT_PATH)

# If no build of the custom distribution is found, compile it
if(NOT Boost_FOUND)
message(STATUS "No existing custom distribution of Boost has been found in ${BOOST_INSTALLDIR}. Proceeding to compile Boost...")

# Set compilation toolset for b2 and Boost builds
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_GENERATOR_TOOLSET STREQUAL "ClangCL")
# Proper toolset should be "clang-win", but b2 has a bug that makes it spam Visual Studio instances if set
# Since Clang for Windows is ABI-compatible with MSVC, using MSVC is fine
set(BOOST_TOOLSET "msvc")
else()
message(WARNING "Boost compilation on Windows requires the use of a clang-cl compiler running inside a Visual Studio Developer CLI environment with a Windows C++ SDK available.")
set(BOOST_TOOLSET "msvc")
endif()
else()
set(BOOST_TOOLSET "msvc")
endif()
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(BOOST_TOOLSET "clang")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(BOOST_TOOLSET "gcc")
endif()
endif()

# Determine b2 executable name depending on host system
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(b2_EXECUTABLE_NAME "b2.exe")
else()
set(b2_EXECUTABLE_NAME "b2")
endif()

# Find b2
find_program(b2 NAME ${b2_EXECUTABLE_NAME} PATHS ${BOOST_SOURCEDIR} NO_CACHE NO_DEFAULT_PATH)

# Compile b2 if it isn't found
if(b2 STREQUAL "b2-NOTFOUND")
message(STATUS "The b2 buildsystem executable hasn't been found in your system. Compiling b2...")
b2_build()

# Find b2 again after compilation
find_program(b2 NAME ${b2_EXECUTABLE_NAME} PATHS ${BOOST_SOURCEDIR} NO_CACHE NO_DEFAULT_PATH REQUIRED)
endif()

# Compile Boost
message(STATUS "Compiling Boost...")
boost_compile()

# Find Boost again
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} PATHS ${BOOST_INSTALLDIR} NO_DEFAULT_PATH REQUIRED)
else()
message(STATUS "Custom Boost distribution found in ${BOOST_INSTALLDIR}")
endif()
endif()
# find_package(Boost ...) setting
set(Boost_USE_STATIC_LIBS ON)

set(Boost_NO_WARN_NEW_VERSIONS 1)

# First, try to find Boost without any hints (system Boost)
if(NOT VITA3K_FORCE_CUSTOM_BOOST)
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} QUIET)
endif()

# If system Boost hasn't been found, then enable hints to find custom Boost
if (NOT Boost_FOUND)
message(STATUS "A Boost distribution that meets the requirements needed for the project hasn't been found in your system. Falling back to custom Boost distribution...")

# Set path hints for Boost search inside the repository folder and assist in compilation if needed
set(BOOST_SOURCEDIR "${CMAKE_SOURCE_DIR}/external/boost") # For internal use
set(BOOST_INSTALLDIR "${CMAKE_BINARY_DIR}/external/boost") # For internal use
set(BOOST_ROOT "${BOOST_SOURCEDIR}") # find_package(Boost ...) hint
set(BOOST_INCLUDEDIR "${BOOST_SOURCEDIR}") # find_package(Boost ...) hint
set(BOOST_LIBRARYDIR "${BOOST_INSTALLDIR}/lib") # find_package(Boost ...) hint

# Find Boost again to check for a existing compilation of the custom distribution
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} PATHS ${BOOST_INSTALLDIR} NO_DEFAULT_PATH)

# If no build of the custom distribution is found, compile it
if(NOT Boost_FOUND)
message(STATUS "No existing custom distribution of Boost has been found in ${BOOST_INSTALLDIR}. Proceeding to compile Boost...")

# Set compilation toolset for b2 and Boost builds
if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_GENERATOR_TOOLSET STREQUAL "ClangCL")
# Proper toolset should be "clang-win", but b2 has a bug that makes it spam Visual Studio instances if set
# Since Clang for Windows is ABI-compatible with MSVC, using MSVC is fine
set(BOOST_TOOLSET "msvc")
else()
message(WARNING "Boost compilation on Windows requires the use of a clang-cl compiler running inside a Visual Studio Developer CLI environment with a Windows C++ SDK available.")
set(BOOST_TOOLSET "msvc")
endif()
else()
set(BOOST_TOOLSET "msvc")
endif()
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(BOOST_TOOLSET "clang")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(BOOST_TOOLSET "gcc")
endif()
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(BOOST_TOOLSET "clang-darwin")
if (ARCHITECTURE STREQUAL "x86_64")
set(BOOST_ARCHITECTURE "x86")
elseif (ARCHITECTURE STREQUAL "arm64")
set(BOOST_ARCHITECTURE "arm")
else()
set(BOOST_ARCHITECTURE "arm+x86")
endif()
endif()

# Determine b2 executable name depending on host system
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(b2_EXECUTABLE_NAME "b2.exe")
else()
set(b2_EXECUTABLE_NAME "b2")
endif()

# Find b2
find_program(b2 NAME ${b2_EXECUTABLE_NAME} PATHS ${BOOST_SOURCEDIR} NO_CACHE NO_DEFAULT_PATH)

# Compile b2 if it isn't found
if(b2 STREQUAL "b2-NOTFOUND")
message(STATUS "The b2 buildsystem executable hasn't been found in your system. Compiling b2...")
b2_build()

# Find b2 again after compilation
find_program(b2 NAME ${b2_EXECUTABLE_NAME} PATHS ${BOOST_SOURCEDIR} NO_CACHE NO_DEFAULT_PATH REQUIRED)
endif()

# Compile Boost
message(STATUS "Compiling Boost...")
boost_compile()

# Find Boost again
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} PATHS ${BOOST_INSTALLDIR} NO_DEFAULT_PATH REQUIRED)
else()
message(STATUS "Custom Boost distribution found in ${BOOST_INSTALLDIR}")
endif()
endif()
else()
# Try to find Boost on the system and CMake's default paths
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} REQUIRED)
# Try to find Boost on the system and CMake's default paths
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost 1.81 COMPONENTS ${BOOST_MODULES_TO_FIND} REQUIRED)
endif()
endmacro(get_boost)

Expand Down
Loading

0 comments on commit c94189d

Please sign in to comment.