Skip to content

Commit

Permalink
Allow passing absolute path to conanfile argument.
Browse files Browse the repository at this point in the history
Now with tests too!
Fixes: #239
  • Loading branch information
rasjani committed May 25, 2020
1 parent 4ea2603 commit 7b94c32
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
9 changes: 6 additions & 3 deletions conan.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ function(conan_cmake_settings result)
message(STATUS "Conan: Automatic detection of conan settings from cmake")

parse_arguments(${ARGV})

if(ARGUMENTS_BUILD_TYPE)
set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE})
elseif(CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -357,7 +356,11 @@ function(conan_cmake_install)
endif()
set(CONAN_OPTIONS "")
if(ARGUMENTS_CONANFILE)
set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE})
if(IS_ABSOLUTE ${ARGUMENTS_CONANFILE})
set(CONANFILE ${ARGUMENTS_CONANFILE})
else()
set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE})
endif()
# A conan file has been specified - apply specified options as well if provided
foreach(ARG ${ARGUMENTS_OPTIONS})
set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG})
Expand Down Expand Up @@ -465,7 +468,7 @@ endmacro()

macro(conan_cmake_run)
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
36 changes: 32 additions & 4 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ def setUp(self):
os.path.join(folder, "conan.cmake"))
os.chdir(folder)
content = textwrap.dedent("""
#include "hello.h"
#include "hello.h"
int main(){
hello();
int main(){
hello();
}
""")
save("main.cpp", content)
Expand Down Expand Up @@ -578,10 +578,38 @@ def test_existing_conanfile(self):
cmd = os.sep.join([".", "bin", "main"])
run(cmd)

def test_absolute_path_conanfile(self):
content = textwrap.dedent("""
set(CMAKE_CXX_COMPILER_WORKS 1)
set(CMAKE_CXX_ABI_COMPILED 1)
cmake_minimum_required(VERSION 2.8)
project(ProjectHello CXX)
message(STATUS "CMAKE VERSION: ${CMAKE_VERSION}")
include(conan.cmake)
conan_cmake_run(CONANFILE ${CMAKE_BINARY_DIR}/conanfile.txt
BASIC_SETUP CMAKE_TARGETS
BUILD missing)
add_executable(main main.cpp)
target_link_libraries(main CONAN_PKG::hello)
""")
save("CMakeLists.txt", content)

os.makedirs("build")
save("build/conanfile.txt", "[requires]\nhello/1.0\n"
"[generators]\ncmake")

os.chdir("build")
run("cmake .. %s -DCMAKE_BUILD_TYPE=Release" % self.generator)
run("cmake --build . --config Release")
cmd = os.sep.join([".", "bin", "main"])
run(cmd)

def test_version_in_cmake(self):
with open("conan.cmake", "r") as handle:
if "# version: " not in handle.read():
raise Exception("Version missing in conan.cmake")
raise Exception("Version missing in conan.cmake")

@unittest.skipIf(platform.system() != "Windows", "toolsets only in Windows")
def test_vs_toolset(self):
Expand Down

0 comments on commit 7b94c32

Please sign in to comment.