Skip to content

Commit d8a2939

Browse files
committed
Port to conan 2
1 parent f4fbd47 commit d8a2939

File tree

5 files changed

+36
-38
lines changed

5 files changed

+36
-38
lines changed

CMakeLists.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.23)
22
project(steam_controller)
33

44
set(CMAKE_CXX_STANDARD 14)
55

6-
if(steam_controller_INCLUDE_CONAN)
7-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
8-
conan_basic_setup(TARGETS KEEP_RPATHS)
9-
endif()
10-
116
# Canonize platform selection
127
set(steam_controller_PLATFORM Undefined)
138
if(WIN32)

build.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

conanfile.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from conans import ConanFile, CMake
1+
from conan import ConanFile
2+
from conan.tools.cmake import CMake, cmake_layout
23

34

45
class SteamControllerConan(ConanFile):
@@ -10,33 +11,36 @@ class SteamControllerConan(ConanFile):
1011
description = "Access the Steam Controller without Steam"
1112
topics = ("hardware", "gamepad")
1213
settings = "os", "compiler", "build_type", "arch"
13-
options = {"shared": [True, False]}
14-
default_options = "shared=False"
15-
generators = "cmake"
14+
options = {"shared": [True, False], "fPIC": [True, False]}
15+
default_options = {"shared": False, "fPIC": True}
16+
generators = "CMakeDeps", "CMakeToolchain"
1617
exports_sources = "source/*", "externals/*",\
1718
"!externals/hidapi/LICENSE-*.txt",\
1819
"include/*", "CMakeLists.txt",\
1920
"demo/*"
2021

21-
def _configured_cmake(self):
22-
cmake = CMake(self)
23-
cmake.configure(source_folder=".", defs={
24-
'steam_controller_INCLUDE_CONAN': True
25-
})
26-
return cmake
27-
22+
def config_options(self):
23+
if self.settings.os == "Windows":
24+
del self.options.fPIC
25+
2826
def build(self):
29-
self._configured_cmake().build()
27+
cmake = CMake(self)
28+
cmake.configure()
29+
cmake.build()
3030

3131
def package(self):
32-
self._configured_cmake().install()
32+
cmake = CMake(self)
33+
cmake.install()
34+
35+
def layout(self):
36+
cmake_layout(self)
3337

3438
def package_info(self):
3539
self.cpp_info.libs = ["steam_controller"]
3640
if self.settings.os == "Windows":
37-
self.cpp_info.libs.append("Setupapi")
41+
self.cpp_info.system_libs.append("Setupapi")
3842
if self.settings.os == "Linux":
39-
self.cpp_info.libs.append("udev")
43+
self.cpp_info.system_libs.append("udev")
4044
if self.settings.os == "Macos":
4145
self.cpp_info.exelinkflags.append("-framework CoreFoundation")
4246
self.cpp_info.exelinkflags.append("-framework IOKit")

test_package/CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
cmake_minimum_required(VERSION 2.8.12)
1+
cmake_minimum_required(VERSION 3.25)
22
project(PackageTest CXX)
33

44
set(CMAKE_CXX_STANDARD 14)
55

6-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
7-
conan_basic_setup()
6+
find_package(steam_controller CONFIG REQUIRED)
87

98
add_executable(example example.cpp)
10-
target_link_libraries(example ${CONAN_LIBS})
9+
target_link_libraries(example steam_controller::steam_controller)
1110

test_package/conanfile.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
import os
22

3-
from conans import ConanFile, CMake, tools
4-
3+
from conan import ConanFile
4+
from conan.tools.cmake import CMake, cmake_layout
5+
from conan.tools.build import can_run
56

67
class SteamControllerTestConan(ConanFile):
78
settings = "os", "compiler", "build_type", "arch"
8-
generators = "cmake"
9+
generators = "CMakeDeps", "CMakeToolchain"
10+
11+
def requirements(self):
12+
self.requires(self.tested_reference_str)
913

1014
def build(self):
1115
cmake = CMake(self)
1216
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
1317
# in "test_package"
1418
cmake.configure()
1519
cmake.build()
20+
21+
def layout(self):
22+
cmake_layout(self)
1623

1724
def test(self):
18-
if not tools.cross_building(self.settings):
19-
os.chdir("bin")
20-
self.run(".%sexample" % os.sep)
25+
if can_run(self):
26+
cmd = os.path.join(self.cpp.build.bindir, "example")
27+
self.run(cmd, env="conanrun")

0 commit comments

Comments
 (0)