Skip to content

Commit a137a87

Browse files
committed
wip: using conan for getting dependencies
1 parent dac3892 commit a137a87

File tree

11 files changed

+159
-91
lines changed

11 files changed

+159
-91
lines changed

.github/workflows/build-test-run-reusable-workflow.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
with:
3131
python-version: '3.11'
3232
- run: |
33+
python -u Scripts/ConanSetup.py
3334
python -u Scripts/BuildAndInstallExternalLibs.py --TargetPlatform ${{ inputs.target-platform }}
3435
python -u Scripts/BuildAndInstallCoDeLib.py --TargetPlatform ${{ inputs.target-platform }}
3536
python -u Scripts/BuildBenchmark.py --TargetPlatform ${{ inputs.target-platform }}

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ Test*.txt*
1818

1919
# Python
2020
__pycache__/
21+
.venv
2122

2223
# Custom
2324
AddedFlags.cmake
24-
tmp
25+
tmp
26+
27+
# Conan
28+
build/

CoDeLib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
cmake_minimum_required(VERSION 3.28)
22
project(COMPRESSION_DECOMPRESSION_LIB VERSION 0.0.1 LANGUAGES C)
33

4+
list(APPEND CMAKE_PREFIX_PATH ${MINIZIP_INSTALL_PATH})
5+
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
6+
47
add_compile_definitions("$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
58

69
# Required for FileUtils.c (and its tests) to use the correct versions of ftello and similar functions

CoDeLib/Deflate_zlib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ target_include_directories(Deflate_zlib PUBLIC
66
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
77
)
88

9-
set(ZLIB_USE_STATIC_LIBS "ON")
109
find_package(ZLIB REQUIRED)
1110
target_link_libraries(Deflate_zlib PRIVATE ZLIB::ZLIB)
1211

CoDeLib/Inflate_zlib/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ target_include_directories(Inflate_zlib PUBLIC
66
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
77
)
88

9-
set(ZLIB_USE_STATIC_LIBS "ON")
109
find_package(ZLIB REQUIRED)
1110
target_link_libraries(Inflate_zlib PRIVATE ZLIB::ZLIB)
1211

DevEnvSetup.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,35 @@ Install the recommended packages for this reposity (see `./vscode/extensions.jso
3232
- Install **C development packages**: `$ apt install build-essential`
3333
- Install **CMake**: https://cmake.org/download/ (>= 3.28)
3434

35+
# Conan
36+
37+
```sh
38+
$ python -m venv .venv
39+
```
40+
41+
On Windows:
42+
43+
```cmd
44+
> call .venv/Scripts/activate
45+
```
46+
47+
On Unix:
48+
49+
```sh
50+
$ source .venv/bin/activate
51+
```
52+
53+
```sh
54+
$ cd .venv
55+
$ pip install conan
56+
$ cd ../
57+
58+
$ conan profile detect --force
59+
$ conan install . --output-folder=build --build=missing --settings=build_type=Debug
60+
$ conan install . --output-folder=build --build=missing --settings=build_type=Release
61+
```
62+
63+
3564
# Verify
3665
Now you should be able build and run:
3766

Scripts/BuildAndInstallCoDeLib.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ def BuildAndInstallCoDeLib(
4646
buildEnv.GetTargetPlatform()
4747
)
4848

49-
ExternalZlibLibInstallPath = Path(
50-
ExternalLibPath / "zlib/Install" / targetPlatformString / BuildTypeString
51-
)
5249
ExternalMinizipNgLibInstallPath = Path(
5350
ExternalLibPath / "minizip-ng/Install" / targetPlatformString / BuildTypeString
5451
)
@@ -73,14 +70,19 @@ def BuildAndInstallCoDeLib(
7370
print("==============================")
7471
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
7572
print("==============================")
76-
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S "{2}" -B "{3}" -DCMAKE_INSTALL_PREFIX="{4}" -DCMAKE_BUILD_TYPE={5} -DZLIB_ROOT="{6}" -DCMAKE_PREFIX_PATH="{7}"'.format(
73+
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S "{2}" -B "{3}" -DCMAKE_INSTALL_PREFIX="{4}" -DCMAKE_BUILD_TYPE={5} -DMINIZIP_INSTALL_PATH="{6}"'.format(
7774
buildEnv.GetCmakeGenerator(),
78-
buildEnv.GetCustomToolChainPath(),
75+
Path(
76+
RepositoryRootPath
77+
/ "build/conan/build"
78+
/ BuildTypeString
79+
/ "generators"
80+
/ "conan_toolchain.cmake"
81+
),
7982
CoDeLibRootPath,
8083
BuildDirectory,
8184
InstallDirectory,
8285
BuildTypeString,
83-
ExternalZlibLibInstallPath,
8486
ExternalMinizipNgLibInstallPath,
8587
)
8688
print(configureCommand)
@@ -93,7 +95,9 @@ def BuildAndInstallCoDeLib(
9395
print("==============================")
9496
print(ProjectName + ": Building ({})".format(BuildTypeString))
9597
print("==============================")
96-
buildCommand = "cmake --build {0} -- -j 4".format(BuildDirectory)
98+
buildCommand = "cmake --build {0} --config {1} -- -j 4".format(
99+
BuildDirectory, BuildTypeString
100+
)
97101
print(buildCommand)
98102
subprocess.run(
99103
buildCommand,

Scripts/BuildAndInstallExternalLibs.py

Lines changed: 3 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -36,82 +36,6 @@
3636
ExternalLibPath = Path(RepositoryRootPath / "External")
3737

3838

39-
##############################
40-
# zlib
41-
##############################
42-
def BuildAndInstallZlib(
43-
buildEnv: EnvironmentConfig.EnvironmentConfiguration,
44-
buildConfig: EnvironmentConfig.BuildConfig = EnvironmentConfig.BuildConfig.DEBUG,
45-
):
46-
ProjectName = "zlib"
47-
48-
BuildTypeString = EnvironmentConfig.BuildConfig.ToCMakeBuildType(buildConfig)
49-
targetPlatformString = EnvironmentConfig.Platform.PlatformToOsName(
50-
buildEnv.GetTargetPlatform()
51-
)
52-
53-
TopLevelCMakeListsDirectory = Path(ExternalLibPath / ProjectName)
54-
BuildDirectory = Path(
55-
ExternalLibPath / ProjectName / "Build" / targetPlatformString / BuildTypeString
56-
)
57-
InstallDirectory = Path(
58-
ExternalLibPath
59-
/ ProjectName
60-
/ "Install"
61-
/ targetPlatformString
62-
/ BuildTypeString
63-
)
64-
65-
if not BuildDirectory.exists():
66-
BuildDirectory.mkdir(parents=True)
67-
68-
if InstallDirectory.exists():
69-
shutil.rmtree(InstallDirectory)
70-
InstallDirectory.mkdir(parents=True)
71-
72-
os.chdir(RepositoryRootPath)
73-
74-
print("==============================")
75-
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
76-
print("==============================")
77-
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S {2} -B {3} -DCMAKE_INSTALL_PREFIX="{4}" -DZLIB_BUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE={5} -DZLIB_BUILD_SHARED=OFF'.format(
78-
buildEnv.GetCmakeGenerator(),
79-
buildEnv.GetCustomToolChainPath(),
80-
TopLevelCMakeListsDirectory,
81-
BuildDirectory,
82-
InstallDirectory,
83-
BuildTypeString,
84-
)
85-
print(configureCommand)
86-
subprocess.run(
87-
configureCommand,
88-
shell=True,
89-
check=True,
90-
)
91-
92-
print("==============================")
93-
print(ProjectName + ": Building ({})".format(BuildTypeString))
94-
print("==============================")
95-
buildCommand = "cmake --build {0} -- -j 4".format(BuildDirectory)
96-
print(buildCommand)
97-
subprocess.run(
98-
buildCommand,
99-
shell=True,
100-
check=True,
101-
)
102-
103-
print("==============================")
104-
print(ProjectName + ": Installing ({})".format(BuildTypeString))
105-
print("==============================")
106-
installCommand = "cmake --install {0}".format(BuildDirectory)
107-
print(installCommand)
108-
subprocess.run(
109-
installCommand,
110-
shell=True,
111-
check=True,
112-
)
113-
114-
11539
##############################
11640
# minizip-ng
11741
##############################
@@ -170,7 +94,9 @@ def BuildAndInstallMinizipNg(
17094
print("==============================")
17195
print(ProjectName + ": Building ({})".format(BuildTypeString))
17296
print("==============================")
173-
buildCommand = "cmake --build {0}".format(BuildDirectory)
97+
buildCommand = "cmake --build {0} --config {1} -- -j 4".format(
98+
BuildDirectory, BuildTypeString
99+
)
174100
print(buildCommand)
175101
subprocess.run(
176102
buildCommand,
@@ -194,10 +120,6 @@ def BuildAndInstallMinizipNg(
194120
RepositoryRootPath, targetPlatform
195121
)
196122

197-
# zlib
198-
BuildAndInstallZlib(BuildEnv, EnvironmentConfig.BuildConfig.DEBUG)
199-
BuildAndInstallZlib(BuildEnv, EnvironmentConfig.BuildConfig.RELEASE)
200-
201123
# minizip-ng
202124
BuildAndInstallMinizipNg(BuildEnv, EnvironmentConfig.BuildConfig.DEBUG)
203125
BuildAndInstallMinizipNg(BuildEnv, EnvironmentConfig.BuildConfig.RELEASE)

Scripts/ConanSetup.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import os
2+
from pathlib import Path
3+
import EnvironmentConfig
4+
import subprocess
5+
6+
hostPlatform = EnvironmentConfig.Platform.OsNameToPlatform(os.name)
7+
8+
currentScriptPath = Path(os.path.dirname(os.path.abspath(__file__)))
9+
repositoryRootPath = Path(currentScriptPath.parent)
10+
11+
venvPath = Path(repositoryRootPath / ".venv")
12+
if not venvPath.exists():
13+
print("Creating virtual environment at {}".format(venvPath))
14+
subprocess.run(
15+
"python -m venv {}".format(venvPath),
16+
shell=True,
17+
check=True,
18+
)
19+
else:
20+
print("Virtual environment already exists at {}".format(venvPath))
21+
22+
print("Activating virtual environment...")
23+
24+
VirtualEnvPythonPath = Path(
25+
venvPath
26+
/ ("Scripts" if hostPlatform == EnvironmentConfig.Platform.WINDOWS else "bin")
27+
/ "python"
28+
)
29+
30+
31+
print("Upgrading pip...")
32+
pipUpgradeCommand = "{} -m pip install --upgrade pip".format(VirtualEnvPythonPath)
33+
print(pipUpgradeCommand)
34+
subprocess.run(
35+
pipUpgradeCommand,
36+
shell=True,
37+
check=True,
38+
)
39+
40+
requirementsFilePath = Path(repositoryRootPath / "requirements.txt")
41+
if requirementsFilePath.exists():
42+
print("Installing required packages from {}".format(requirementsFilePath))
43+
installCommand = "{} -m pip install -r {}".format(
44+
VirtualEnvPythonPath, requirementsFilePath
45+
)
46+
print(installCommand)
47+
subprocess.run(
48+
installCommand,
49+
shell=True,
50+
check=True,
51+
)
52+
else:
53+
print(
54+
"No requirements.txt file found at {}, skipping package installation.".format(
55+
requirementsFilePath
56+
)
57+
)
58+
59+
print("Virtual environment setup complete.")
60+
61+
VirtualEnvConanPath = Path(
62+
venvPath
63+
/ ("Scripts" if hostPlatform == EnvironmentConfig.Platform.WINDOWS else "bin")
64+
/ "conan"
65+
)
66+
67+
print("Getting conan profile...")
68+
conanProfileCommand = "{} profile detect --force".format(VirtualEnvConanPath)
69+
print(conanProfileCommand)
70+
subprocess.run(
71+
conanProfileCommand,
72+
shell=True,
73+
check=True,
74+
)
75+
76+
print("Getting Conan dependencies...")
77+
buildTypes = ["Debug", "Release"]
78+
for buildType in buildTypes:
79+
conanInstallCommand = '{0} install "{1}" --output-folder="{2}" --build=missing --settings=build_type={3}'.format(
80+
VirtualEnvConanPath,
81+
Path(repositoryRootPath / "conanfile.py"),
82+
Path(repositoryRootPath / "build" / "conan"),
83+
buildType,
84+
)
85+
print(conanInstallCommand)
86+
subprocess.run(
87+
conanInstallCommand,
88+
shell=True,
89+
check=True,
90+
)

conanfile.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from conan import ConanFile
2+
from conan.tools.cmake import cmake_layout
3+
4+
5+
class ExampleRecipe(ConanFile):
6+
settings = "os", "compiler", "build_type", "arch"
7+
generators = "CMakeDeps", "CMakeToolchain"
8+
9+
def requirements(self):
10+
self.requires("zlib/1.3.1")
11+
12+
def configure(self):
13+
self.options["zlib/*"].shared = False
14+
15+
def layout(self):
16+
cmake_layout(self)

0 commit comments

Comments
 (0)