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

Dhruv - labs 1 and 2 #86

Open
wants to merge 4 commits into
base: main
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
3 changes: 3 additions & 0 deletions dhruv/lab1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.15...3.30)
project(part1 LANGUAGES CXX)
add_executable(test src/main.cpp)
6 changes: 6 additions & 0 deletions dhruv/lab1/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>

int main()
{
std::cout << "Hello, World!\n";
}
8 changes: 8 additions & 0 deletions dhruv/lab1p2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15...3.30)
project(lab1p2 LANGUAGES CXX)

add_library(part2lib SHARED src/hello_world.cpp)
target_include_directories(part2lib PUBLIC include)

add_executable(part2 src/main.cpp)
target_link_libraries(part2 PUBLIC part2lib)
14 changes: 14 additions & 0 deletions dhruv/lab1p2/include/hello_world.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#ifndef HelloWorld
#define HelloWorld
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

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

by convention these are supposed to be all caps

#include <iostream>

class HelloWorldLib
{
public:
HelloWorldLib() = default;
void hello();

};

#endif

6 changes: 6 additions & 0 deletions dhruv/lab1p2/src/hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include <hello_world.hpp>

void HelloWorldLib::hello() {
std::cout << "Hello, World again\n";
}
8 changes: 8 additions & 0 deletions dhruv/lab1p2/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <hello_world.hpp>

int main() {
HelloWorldLib obj;
obj.hello();

return 0;
}
1 change: 1 addition & 0 deletions dhruv/lab2p1/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

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

please use the top-level .gitignore

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/result/
10 changes: 10 additions & 0 deletions dhruv/lab2p1/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.15...3.30)
project(lab2p1 LANGUAGES CXX)

add_library(HelloWorldLib STATIC src/hello_world.cpp)
target_include_directories(HelloWorldLib PUBLIC include)

add_executable(HelloWorld src/main.cpp)
target_link_libraries(HelloWorld PUBLIC HelloWorldLib)

install(TARGETS HelloWorld DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
8 changes: 8 additions & 0 deletions dhruv/lab2p1/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{stdenv, cmake}:
#instructions on how to build the nix package
stdenv.mkDerivation rec {
pname = "HelloLib";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [ cmake ];
}
27 changes: 27 additions & 0 deletions dhruv/lab2p1/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions dhruv/lab2p1/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
description = "flakep1";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};

outputs = {self, nixpkgs}:

let
HelloLib_overlay = final: prev: { #Overlays in Nix are functions that accept two arguments (usually called final and prev) and return a set of packages
HelloLib = final.callPackage ./default.nix {}; #this makes "HelloLib" a package or sets it as a package here?
};

my_overlays = [ HelloLib_overlay ]; #so this is where I would add multiple overlays if needed
#HelloLib_overlay returns packages?

pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ self.overlays.default ]; #are the self.overlays what I set earlier?
};

in
{
packages.x86_64-linux.default = pkgs.HelloLib;
overlays.default = nixpkgs.lib.composeManyExtensions my_overlays;
};

}
11 changes: 11 additions & 0 deletions dhruv/lab2p1/include/hello_world.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef HelloWorld
#define HelloWorld
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

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

all caps please

#include <iostream>

class HelloWorldLib {
public:
HelloWorldLib() = default;
void hello();
};

#endif
1 change: 1 addition & 0 deletions dhruv/lab2p1/result
6 changes: 6 additions & 0 deletions dhruv/lab2p1/src/hello_world.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include <hello_world.hpp>

void HelloWorldLib::hello() {
std::cout << "hi";
}
9 changes: 9 additions & 0 deletions dhruv/lab2p1/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>
#include <hello_world.hpp>

int main() {
HelloWorldLib obj;
obj.hello();

return 0;
}
1 change: 1 addition & 0 deletions dhruv/lab2p2/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

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

pls use top-level .gitignore

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/result/
9 changes: 9 additions & 0 deletions dhruv/lab2p2/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ stdenv, cmake, hellolib }:

stdenv.mkDerivation rec {
pname = "hellolib_exe";
version = "0.1.0";
src = ./hellolib_exe;
nativeBuildInputs = [ cmake ];
buildInputs = [ hellolib ];
}
27 changes: 27 additions & 0 deletions dhruv/lab2p2/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions dhruv/lab2p2/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
description = "lab2p2 flake";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};

outputs = { self, nixpkgs }:
let
pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ self.overlays.default ];
};

hellolib_overlay = final: prev: {
hellolib = final.callPackage ./hellolib.nix { };
hellolib_exe = final.callPackage ./default.nix { };
};
my_overlays = [ hellolib_overlay ];


in
{
packages.x86_64-linux.default = pkgs.hellolib;
overlays.default = nixpkgs.lib.composeManyExtensions my_overlays;
};
}
8 changes: 8 additions & 0 deletions dhruv/lab2p2/hellolib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ stdenv, cmake, hellolib }:

stdenv.mkDerivation rec {
pname = "hellolib";
version = "0.1.0";
src = ./hellolib;
nativeBuildInputs = [ cmake ];
}
45 changes: 45 additions & 0 deletions dhruv/lab2p2/hellolib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.15...3.30)

project(HelloLib LANGUAGES CXX)

add_library(HelloLib SHARED src/hellolib.cpp)
target_include_directories(HelloLib PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

include(GNUInstallDirs)
install(TARGETS HelloLib
EXPORT HelloLibTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION include
)

# NAMESPACE sets the namespace that your target will live within.
# you can have multiple targets under the same namespace
install(EXPORT HelloLibTargets
FILE HelloLibTargets.cmake
NAMESPACE HelloLib::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/HelloLib
)

# this looks for your .cmake.in file that you created in step 1.
# if you set the directory differently you may need to handle this differently
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/HelloLibConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/HelloLibConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/HelloLib
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/HelloLibConfig.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/HelloLib
)

install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp"
)
11 changes: 11 additions & 0 deletions dhruv/lab2p2/hellolib/cmake/HelloLibConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@PACKAGE_INIT@

# if you have find_package calls, use find_dependency() here with the package
# that you need to find_package() for. this handles transitive dep finding so
# your downstream cmake doesnt have to `find_package()` it instead gets done
# upon package configuration

find_dependency(Boost)
include("${CMAKE_CURRENT_LIST_DIR}/HelloLibTargets.cmake")

check_required_components(HelloLib)
11 changes: 11 additions & 0 deletions dhruv/lab2p2/hellolib/include/hellolib.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef HelloWorld
#define HelloWorld
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

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

all caps pls

#include <iostream>

class HelloWorldLib {
public:
HelloWorldLib() = default;
void hello();
};

#endif
6 changes: 6 additions & 0 deletions dhruv/lab2p2/hellolib/src/hellolib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <hellolib.hpp>
Copy link
Contributor

Choose a reason for hiding this comment

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

this one is correct lol

#include <iostream>

void HelloWorldLib::hello() {
std::cout << "Hello, world l2p2" << std::endl;
}
13 changes: 13 additions & 0 deletions dhruv/lab2p2/hellolib_exe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.15...3.30)
project(lab2p2 LANGUAGES CXX)

find_package(hellolib REQUIRED)

add_executable(HelloWorld main.cpp)

target_link_directories(HelloWorld PUBLIC HelloLib::HelloLib)

install(TARGETS HelloWorld RUNTIME DESTINATION bin)



8 changes: 8 additions & 0 deletions dhruv/lab2p2/hellolib_exe/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <hellolib.hpp>

int main() {
HelloWorldLib test;
test.hello();

return 0;
}
1 change: 1 addition & 0 deletions dhruv/lab2p2/result
1 change: 1 addition & 0 deletions dhruv/lab2p3/.gitignore
Copy link
Contributor

Choose a reason for hiding this comment

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

top level

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/result/
13 changes: 13 additions & 0 deletions dhruv/lab2p3/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.15...3.30)
project(lab2p2 LANGUAGES CXX)

find_package(hellolib REQUIRED)

add_executable(HelloWorld main.cpp)

target_link_directories(HelloWorld PUBLIC HelloLib::HelloLib)

install(TARGETS HelloWorld RUNTIME ${CMAKE_INSTALL_PREFIX}/bin)



9 changes: 9 additions & 0 deletions dhruv/lab2p3/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ stdenv, cmake, hellolib }:

stdenv.mkDerivation rec {
pname = "hellolib_exe";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [ cmake ];
buildInputs = [ hellolib ];
}
Loading