Skip to content

Commit

Permalink
kram - builds - cmake cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alecazam committed Sep 15, 2024
1 parent 6236411 commit d706b1e
Showing 1 changed file with 32 additions and 58 deletions.
90 changes: 32 additions & 58 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,37 @@ set(BUILD_WIN FALSE)

#-----------------------------------------------------

# SYSROOT must be set before project,
# SYSROOT is max OS, deployment is min OS on Apple.
# If SYSROOT not set, then cmake uses min OS from deployment target. Ugh.
# so have to force SYSROOT to latest SDK.

# don't change these to set_property(GLOBAL) or set_target_properties, the need to be set prior to project
# and only seem to work if set() is used to force the global value.

# suppress ZERO_CHECK project
set(CMAKE_SUPPRESS_REGENERATION true)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_DEFAULT_STARTUP_PROJECT "kramc")

#-----------------------------------------------------
# still building Win using Cmake

if (BUILD_WIN)
message("build for win x64")
set(BUILD_WIN TRUE)

# use clang-cl on Win
set(CMAKE_CXX_COMPILER "clang-cl")


# cmake translates project to sln in Win, but to xcode projects on Mac.
# No way to make xcode workspaces, but could do manually.
set(myTargetWorkspace kramWorkspace)

project(${myTargetWorkspace} LANGUAGES C CXX)

#-----------------------------------------------------

# use clang-cl on Win
set(CMAKE_CXX_COMPILER "clang-cl")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_DEFAULT_STARTUP_PROJECT "kramc")

#-----------------------------------------------------

# the kram static library libkram which should build on iOS/Android/Mac/Win
# this doesn't set a project, but maybe it should
add_subdirectory(libkram)
Expand Down Expand Up @@ -80,16 +76,28 @@ if (BUILD_MAC)
message("build for macOS universal (unmaintained)")
set(BUILD_MAC TRUE)

# CMAKE_OSX_DEPLOYMENT_TARGET must be set as a CACHE variable, or it will be stripped
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0" CACHE STRING "Minimum macOS")
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)" CACHE STRING "Architecture macOS")

# cmake translates project to sln in Win, but to xcode projects on Mac.
# No way to make xcode workspaces, but could do manually.
set(myTargetWorkspace kramWorkspace)

project(${myTargetWorkspace} LANGUAGES C CXX OBJCXX)

#-----------------------------------------------------

# CMAKE_OSX_DEPLOYMENT_TARGET must be set as a CACHE variable, or it will be stripped
set(CMAKE_OSX_DEPLOYMENT_TARGET "13.0" CACHE STRING "Minimum macOS")
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)" CACHE STRING "Architecture macOS")

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)

set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_DEFAULT_STARTUP_PROJECT "kramc")

#-----------------------------------------------------

# the kram static library libkram which should build on iOS/Android/Mac/Win
# this doesn't set a project, but maybe it should
add_subdirectory(libkram)
Expand All @@ -102,40 +110,6 @@ if (BUILD_MAC)

# ps plugin that uses libkram
add_subdirectory(plugin)

#-----------------------------------------------------

# https://discourse.cmake.org/t/specifying-cmake-osx-sysroot-breaks-xcode-projects-but-no-other-choice/2532/8
# use snipet from Alian Martin to validate SDK

if(NOT DEFINED CMAKE_OSX_SYSROOT)
message(FATAL_ERROR "Cannot check SDK version if CMAKE_OSX_SYSROOT is not defined."
)
endif()

# check the Xcode app itself for it's version
set(XCODE_MIN_SDK_MACOS 13.0)
set(XCODE_MIN_APP 13.0)

if(XCODE AND XCODE_VERSION VERSION_LESS XCODE_MIN_APP)
message(FATAL_ERROR "This project requires at least Xcode ${XCODE_MIN_APP}")
endif()

# check the SDK
execute_process(
COMMAND xcrun --sdk "${CMAKE_OSX_SYSROOT}" --show-sdk-version
OUTPUT_VARIABLE SDK_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message("macOS SDK ${SDK_VERSION}")
message("macOS deploy ${CMAKE_OSX_DEPLOYMENT_TARGET}")
message("macOS arch ${CMAKE_OSX_ARCHITECTURES}")

if (SDK_VERSION VERSION_LESS XCODE_MIN_SDK_MACOS)
message(FATAL_ERROR "This project requires at least macOS SDK ${XCODE_MIN_SDK_MACOS}"
)
endif()

#-----------------------------------------------------

Expand Down

0 comments on commit d706b1e

Please sign in to comment.