Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: remove the CMAKE_OSX_DEPLOYMENT_TARGET auto detect by CMake #628

Open
wants to merge 4 commits into
base: develop2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function(detect_os OS OS_API_LEVEL OS_SDK OS_SUBSYSTEM OS_VERSION)
message(STATUS "CMake-Conan: cmake_osx_sysroot=${CMAKE_OSX_SYSROOT}")
set(${OS_SDK} ${_OS_SDK} PARENT_SCOPE)
endif()
if(DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
if(CONAN_USE_CMAKE_OSX_DEPLOYMENT_TARGET)
message(STATUS "CMake-Conan: cmake_osx_deployment_target=${CMAKE_OSX_DEPLOYMENT_TARGET}")
set(${OS_VERSION} ${CMAKE_OSX_DEPLOYMENT_TARGET} PARENT_SCOPE)
endif()
Expand Down Expand Up @@ -611,6 +611,19 @@ macro(conan_provide_dependency_check)
endmacro()


macro(set_osx_deployment_target_flag)
if(NOT DEFINED $CACHE{CONAN_USE_CMAKE_OSX_DEPLOYMENT_TARGET})
if (DEFINED CMAKE_OSX_DEPLOYMENT_TARGET)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to do if DEFINED $CACHE{...} OR DEFINED $ENV{...} as both are valid ways for the user to express intent.

the non-cache CMAKE_OSX_DEPLOYMENT_TARGET can be defined too - we may want to ignore it, or raise a warning (since CMake documentation says that it may be overwritten completely during the call to project) - that could be an elseif()

set(CONAN_USE_CMAKE_OSX_DEPLOYMENT_TARGET TRUE CACHE BOOL
"Specifies whether CMAKE_OSX_DEPLOYMENT_TARGET should be use")
else()
set(CONAN_USE_CMAKE_OSX_DEPLOYMENT_TARGET FALSE CACHE BOOL
"Specifies whether CMAKE_OSX_DEPLOYMENT_TARGET should be use")
endif()
endif ()
endmacro()


# Add a deferred call at the end of processing the top-level directory
# to check if the dependency provider was invoked at all.
cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}" CALL conan_provide_dependency_check)
Expand All @@ -620,6 +633,8 @@ set(CONAN_HOST_PROFILE "default;auto-cmake" CACHE STRING "Conan host profile")
set(CONAN_BUILD_PROFILE "default" CACHE STRING "Conan build profile")
set(CONAN_INSTALL_ARGS "--build=missing" CACHE STRING "Command line arguments for conan install")

set_osx_deployment_target_flag()

find_program(_cmake_program NAMES cmake NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH)
if(NOT _cmake_program)
get_filename_component(PATH_TO_CMAKE_BIN "${CMAKE_COMMAND}" DIRECTORY)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,14 +477,24 @@ def test_os_version(self, capfd, basic_cmake_project):
"-DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15")
out, _ = capfd.readouterr()
assert "os.version=10.15" in out
# Simulates a second execution to see if the cache variable is working
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} "
"-DCMAKE_BUILD_TYPE=Release -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15")
out, _ = capfd.readouterr()
assert "os.version=10.15" in out

def test_no_os_version(self, capfd, basic_cmake_project):
"If CMAKE_OSX_DEPLOYMENT_TARGET is not set, os.version is not added to the Conan profile"
source_dir, binary_dir = basic_cmake_project
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} "
"-DCMAKE_BUILD_TYPE=Release")
out, _ = capfd.readouterr()
assert "os.version=10.15" not in out
assert "os.version=" not in out
# Simulates a second execution to see if the cache variable is working
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} "
"-DCMAKE_BUILD_TYPE=Release")
out, _ = capfd.readouterr()
assert "os.version=" not in out

class TestAndroid:
def test_android_armv8(self, capfd, basic_cmake_project):
Expand Down
Loading