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: Add OUTPUT_FOLDER to conan install #403

Merged
merged 9 commits into from
Mar 24, 2022
Merged
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ and also call to `conan_basic_setup`:

```cmake

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
```

Please [check the cmake generator documentation](https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#cmake-generator)
Expand Down Expand Up @@ -108,7 +108,7 @@ pass all the arguments that the command supports. Also, you can pass the auto-de
`conan_cmake_autodetect` in the `SETTINGS` argument.

It can receive as arguments: `UPDATE`, `NO_IMPORTS`, `PATH_OR_REFERENCE`, `REFERENCE`, `REMOTE`,
`LOCKFILE`, `LOCKFILE_OUT`, `LOCKFILE_NODE_ID`, `INSTALL_FOLDER`, `GENERATOR`, `BUILD` (if this
`LOCKFILE`, `LOCKFILE_OUT`, `LOCKFILE_NODE_ID`, `INSTALL_FOLDER`, `OUTPUT_FOLDER`, `GENERATOR`, `BUILD` (if this
parameter takes the `all` value, Conan will build everything from source), `ENV`, `ENV_HOST`,
`ENV_BUILD`, `OPTIONS_HOST`, `OPTIONS`, `OPTIONS_BUILD`, `PROFILE`, `PROFILE_HOST`, `PROFILE_BUILD`,
`SETTINGS`, `SETTINGS_HOST`, `SETTINGS_BUILD`. For more information, check [conan
Expand Down Expand Up @@ -268,9 +268,9 @@ include(conan.cmake)
conan_cmake_run(CONFIGURATION_TYPES "Release;Debug;RelWithDebInfo")
```

Use it to set the different configurations when using multi-configuration generators. The default
configurations used for multi-configuration generators are `Debug` and `Release` if the argument
`CONFIGURATION_TYPES` is not specified The build types passed through this argument should exist
Use it to set the different configurations when using multi-configuration generators. The default
configurations used for multi-configuration generators are `Debug` and `Release` if the argument
`CONFIGURATION_TYPES` is not specified The build types passed through this argument should exist
in *settings.yml*.

### PROFILE
Expand Down
26 changes: 16 additions & 10 deletions conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ macro(_conan_check_system_name)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "QNX")
set(CONAN_SYSTEM_NAME Neutrino)
endif()
endif()
set(CONAN_SUPPORTED_PLATFORMS Windows Linux Macos Android iOS FreeBSD WindowsStore WindowsCE watchOS tvOS FreeBSD SunOS AIX Arduino Emscripten Neutrino)
list (FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index)
if (${_index} GREATER -1)
Expand Down Expand Up @@ -281,7 +281,7 @@ function(conan_cmake_settings result)
string(REGEX MATCH "[^=]*" MANUAL_SETTING "${ARG}")
message(STATUS "Conan: ${MANUAL_SETTING} was added as an argument. Not using the autodetected one.")
list(REMOVE_ITEM ARGUMENTS_PROFILE_AUTO "${MANUAL_SETTING}")
endforeach()
endforeach()

# Automatic from CMake
foreach(ARG ${ARGUMENTS_PROFILE_AUTO})
Expand Down Expand Up @@ -398,7 +398,7 @@ function(conan_cmake_detect_vs_runtime result)

if(build_type)
string(TOUPPER "${build_type}" build_type)
endif()
endif()
set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS)
foreach(variable ${variables})
if(NOT "${${variable}}" STREQUAL "")
Expand Down Expand Up @@ -444,7 +444,7 @@ endfunction()

macro(conan_parse_arguments)
set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS SKIP_STD)
set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND)
set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER OUTPUT_FOLDER CONAN_COMMAND)
set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE
PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO
INSTALL_ARGS CONFIGURATION_TYPES PROFILE_BUILD BUILD_REQUIRES)
Expand Down Expand Up @@ -502,6 +502,10 @@ function(old_conan_cmake_install)
if(ARGUMENTS_INSTALL_FOLDER)
set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER})
endif()
set(CONAN_OUTPUT_FOLDER "")
if(ARGUMENTS_OUTPUT_FOLDER)
set(CONAN_OUTPUT_FOLDER -of=${ARGUMENTS_OUTPUT_FOLDER})
endif()
foreach(ARG ${ARGUMENTS_GENERATORS})
set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG})
endforeach()
Expand Down Expand Up @@ -539,7 +543,7 @@ function(conan_cmake_install)
endif()

set(installOptions UPDATE NO_IMPORTS OUTPUT_QUIET ERROR_QUIET)
set(installOneValueArgs PATH_OR_REFERENCE REFERENCE REMOTE LOCKFILE LOCKFILE_OUT LOCKFILE_NODE_ID INSTALL_FOLDER)
set(installOneValueArgs PATH_OR_REFERENCE REFERENCE REMOTE LOCKFILE LOCKFILE_OUT LOCKFILE_NODE_ID INSTALL_FOLDER OUTPUT_FOLDER)
set(installMultiValueArgs GENERATOR BUILD ENV ENV_HOST ENV_BUILD OPTIONS_HOST OPTIONS OPTIONS_BUILD PROFILE
PROFILE_HOST PROFILE_BUILD SETTINGS SETTINGS_HOST SETTINGS_BUILD)
cmake_parse_arguments(ARGS "${installOptions}" "${installOneValueArgs}" "${installMultiValueArgs}" ${ARGN})
Expand All @@ -560,6 +564,8 @@ function(conan_cmake_install)
set(flag "--lockfile-node-id")
elseif("${arg}" STREQUAL "INSTALL_FOLDER")
set(flag "--install-folder")
elseif("${arg}" STREQUAL "OUTPUT_FOLDER")
set(flag "--output-folder")
endif()
set(${arg} ${${arg}} ${flag} ${ARGS_${arg}})
endif()
Expand Down Expand Up @@ -611,13 +617,13 @@ function(conan_cmake_install)
if(DEFINED NO_IMPORTS)
set(NO_IMPORTS --no-imports)
endif()
set(install_args install ${PATH_OR_REFERENCE} ${REFERENCE} ${UPDATE} ${NO_IMPORTS} ${REMOTE} ${LOCKFILE} ${LOCKFILE_OUT} ${LOCKFILE_NODE_ID} ${INSTALL_FOLDER}
${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD}
set(install_args install ${PATH_OR_REFERENCE} ${REFERENCE} ${UPDATE} ${NO_IMPORTS} ${REMOTE} ${LOCKFILE} ${LOCKFILE_OUT} ${LOCKFILE_NODE_ID} ${INSTALL_FOLDER} ${OUTPUT_FOLDER}
${GENERATOR} ${BUILD} ${ENV} ${ENV_HOST} ${ENV_BUILD} ${OPTIONS} ${OPTIONS_HOST} ${OPTIONS_BUILD}
${PROFILE} ${PROFILE_HOST} ${PROFILE_BUILD} ${SETTINGS} ${SETTINGS_HOST} ${SETTINGS_BUILD})

string(REPLACE ";" " " _install_args "${install_args}")
message(STATUS "Conan executing: ${CONAN_CMD} ${_install_args}")

if(ARGS_OUTPUT_QUIET)
set(OUTPUT_OPT OUTPUT_QUIET)
endif()
Expand Down Expand Up @@ -734,7 +740,7 @@ endmacro()

macro(conan_cmake_run)
conan_parse_arguments(${ARGV})

if(ARGUMENTS_CONFIGURATION_TYPES AND NOT CMAKE_CONFIGURATION_TYPES)
message(WARNING "CONFIGURATION_TYPES should only be specified for multi-configuration generators")
elseif(ARGUMENTS_CONFIGURATION_TYPES AND ARGUMENTS_BUILD_TYPE)
Expand Down Expand Up @@ -812,7 +818,7 @@ macro(conan_check)
if(NOT "${return_code}" STREQUAL "0")
message(FATAL_ERROR "Conan --version failed='${return_code}'")
endif()

if(NOT CONAN_DETECT_QUIET)
string(STRIP "${CONAN_VERSION_OUTPUT}" _CONAN_VERSION_OUTPUT)
message(STATUS "Conan: Version found ${_CONAN_VERSION_OUTPUT}")
Expand Down
26 changes: 25 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,31 @@ def test_conan_cmake_install_args(self):
os.chdir("build")
run("cmake .. {} -DCMAKE_BUILD_TYPE=Release".format(generator))
run("cmake --build . --config Release")


def test_conan_cmake_install_outputfolder(self):
content = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(MyProject)
include(conan.cmake)
conan_cmake_autodetect(settings)
conan_cmake_install(PATH_OR_REFERENCE ${CMAKE_SOURCE_DIR}/conanfile.py
GENERATOR CMakeDeps
OUTPUT_FOLDER myoutputfolder
SETTINGS ${settings})
""")
save("CMakeLists.txt", content)
save("conanfile.py", textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
settings = "os", "compiler", "build_type", "arch"
def layout(self):
pass
"""))
os.makedirs("build")
os.chdir("build")
run("cmake .. {} -DCMAKE_BUILD_TYPE=Release".format(generator))
assert os.path.isdir("myoutputfolder")

def test_conan_cmake_install_find_package(self):
content = textwrap.dedent("""
cmake_minimum_required(VERSION 3.5)
Expand Down