From cc5ac41057c85122a152d4cf7e79bd1fa1d27e1a Mon Sep 17 00:00:00 2001 From: jessicaliu06 Date: Sun, 15 Sep 2024 16:52:53 -0400 Subject: [PATCH 1/2] Lab 2 Part 2 --- JessicaLiu/Lab2/Lab2Part2/default.nix | 9 ++++ JessicaLiu/Lab2/Lab2Part2/flake.lock | 26 ++++++++++ JessicaLiu/Lab2/Lab2Part2/flake.nix | 29 +++++++++++ .../Lab2/Lab2Part2/helloapp/CMakeLists.txt | 15 ++++++ JessicaLiu/Lab2/Lab2Part2/helloapp/main.cpp | 7 +++ JessicaLiu/Lab2/Lab2Part2/helloapp/result | 1 + JessicaLiu/Lab2/Lab2Part2/hellolib.nix | 8 +++ .../Lab2/Lab2Part2/hellolib/CMakeLists.txt | 50 +++++++++++++++++++ .../cmake/helloworld_libConfig.cmake.in | 10 ++++ .../Lab2/Lab2Part2/hellolib/include/hello.h | 9 ++++ JessicaLiu/Lab2/Lab2Part2/hellolib/result | 1 + .../Lab2/Lab2Part2/hellolib/src/hello.cpp | 6 +++ JessicaLiu/Lab2/Lab2Part2/result | 1 + 13 files changed, 172 insertions(+) create mode 100644 JessicaLiu/Lab2/Lab2Part2/default.nix create mode 100644 JessicaLiu/Lab2/Lab2Part2/flake.lock create mode 100644 JessicaLiu/Lab2/Lab2Part2/flake.nix create mode 100644 JessicaLiu/Lab2/Lab2Part2/helloapp/CMakeLists.txt create mode 100644 JessicaLiu/Lab2/Lab2Part2/helloapp/main.cpp create mode 120000 JessicaLiu/Lab2/Lab2Part2/helloapp/result create mode 100644 JessicaLiu/Lab2/Lab2Part2/hellolib.nix create mode 100644 JessicaLiu/Lab2/Lab2Part2/hellolib/CMakeLists.txt create mode 100644 JessicaLiu/Lab2/Lab2Part2/hellolib/cmake/helloworld_libConfig.cmake.in create mode 100644 JessicaLiu/Lab2/Lab2Part2/hellolib/include/hello.h create mode 120000 JessicaLiu/Lab2/Lab2Part2/hellolib/result create mode 100644 JessicaLiu/Lab2/Lab2Part2/hellolib/src/hello.cpp create mode 120000 JessicaLiu/Lab2/Lab2Part2/result diff --git a/JessicaLiu/Lab2/Lab2Part2/default.nix b/JessicaLiu/Lab2/Lab2Part2/default.nix new file mode 100644 index 0000000..583dee8 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/default.nix @@ -0,0 +1,9 @@ +{ stdenv, cmake, helloworld_lib }: + +stdenv.mkDerivation rec { + pname = "hello_world"; + version = "0.1.0"; + src = ./helloapp; + nativeBuildInputs = [ cmake ]; + buildInputs = [ helloworld_lib ]; +} \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/flake.lock b/JessicaLiu/Lab2/Lab2Part2/flake.lock new file mode 100644 index 0000000..fe85acd --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1725828683, + "narHash": "sha256-t1xBasEJmv1P9jLpGj2HCsYLtjR++67WcUpamUjE9cw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e248589c0f8d41857070fbd3e84d1ff7a5ecd9fc", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/JessicaLiu/Lab2/Lab2Part2/flake.nix b/JessicaLiu/Lab2/Lab2Part2/flake.nix new file mode 100644 index 0000000..f0c75b3 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/flake.nix @@ -0,0 +1,29 @@ +{ + description = "Lab 02 Part 2 Flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs"; + utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, utils }: + let + helloworld_overlay = final: prev: rec { + helloworld_lib = final.callPackage ./hellolib.nix { }; + helloworld = final.callPackage ./default.nix { + inherit helloworld_lib; + }; + }; + + my_overlays = [ helloworld_overlay ]; + + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ self.overlays.default ]; + }; + + in { + packages.x86_64-linux.default = pkgs.helloworld; + overlays.default = nixpkgs.lib.composeManyExtensions my_overlays; + }; +} \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/helloapp/CMakeLists.txt b/JessicaLiu/Lab2/Lab2Part2/helloapp/CMakeLists.txt new file mode 100644 index 0000000..fbe50c4 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/helloapp/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.15...3.30) + +project(helloapp VERSION 1.0 + DESCRIPTION "HyTech Software Training Lab 2 Part 2" + LANGUAGES CXX) + +find_package(helloworld_lib REQUIRED) + +# creates a target executable file +# helloworld is the name of the executable file that will be generated +# main.cpp is the relative path to a source file +add_executable(helloworld main.cpp) +target_link_libraries(helloworld PUBLIC helloworld_lib::helloworld_lib) + +install(TARGETS helloworld RUNTIME DESTINATION bin) \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/helloapp/main.cpp b/JessicaLiu/Lab2/Lab2Part2/helloapp/main.cpp new file mode 100644 index 0000000..374ff77 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/helloapp/main.cpp @@ -0,0 +1,7 @@ +#include "hello.h" + +int main() { + Hello h; + h.hello_world(); + return 0; +} \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/helloapp/result b/JessicaLiu/Lab2/Lab2Part2/helloapp/result new file mode 120000 index 0000000..abad3f9 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/helloapp/result @@ -0,0 +1 @@ +/nix/store/pkcy89nw9nk895xv2rn2n3ynb724jg2p-hello_world-0.1.0 \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/hellolib.nix b/JessicaLiu/Lab2/Lab2Part2/hellolib.nix new file mode 100644 index 0000000..37366f8 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/hellolib.nix @@ -0,0 +1,8 @@ +{ stdenv, cmake }: + +stdenv.mkDerivation rec { + pname = "hello_world"; + version = "0.1.0"; + src = ./hellolib; + nativeBuildInputs = [ cmake ]; +} \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/hellolib/CMakeLists.txt b/JessicaLiu/Lab2/Lab2Part2/hellolib/CMakeLists.txt new file mode 100644 index 0000000..85ff95e --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/hellolib/CMakeLists.txt @@ -0,0 +1,50 @@ +cmake_minimum_required(VERSION 3.15...3.30) + +project(Lab2 VERSION 1.0 + DESCRIPTION "HyTech Software Training Lab 2" + LANGUAGES CXX) + +add_library(helloworld_lib SHARED src/hello.cpp) + +target_include_directories(helloworld_lib PUBLIC + $ + $ +) + +include(GNUInstallDirs) + +install(TARGETS helloworld_lib + EXPORT helloworld_libTargets + 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 helloworld_libTargets + FILE helloworld_libTargets.cmake + NAMESPACE helloworld_lib:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/helloworld_lib +) + +# 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/helloworld_libConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/helloworld_libConfig.cmake" + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/helloworld_lib +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/helloworld_libConfig.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/helloworld_lib +) + +# actually install your header files +install( + DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_PREFIX}/include + FILES_MATCHING PATTERN "*.h*" + ) \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/hellolib/cmake/helloworld_libConfig.cmake.in b/JessicaLiu/Lab2/Lab2Part2/hellolib/cmake/helloworld_libConfig.cmake.in new file mode 100644 index 0000000..75d2ba6 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/hellolib/cmake/helloworld_libConfig.cmake.in @@ -0,0 +1,10 @@ +@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 + +include("${CMAKE_CURRENT_LIST_DIR}/helloworld_libTargets.cmake") + +check_required_components(helloworld_lib) \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/hellolib/include/hello.h b/JessicaLiu/Lab2/Lab2Part2/hellolib/include/hello.h new file mode 100644 index 0000000..036bc18 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/hellolib/include/hello.h @@ -0,0 +1,9 @@ +#ifndef _HELLO_H_ +#define _HELLO_H_ + +class Hello { + public: + void hello_world(); +}; + +#endif \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/hellolib/result b/JessicaLiu/Lab2/Lab2Part2/hellolib/result new file mode 120000 index 0000000..abad3f9 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/hellolib/result @@ -0,0 +1 @@ +/nix/store/pkcy89nw9nk895xv2rn2n3ynb724jg2p-hello_world-0.1.0 \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/hellolib/src/hello.cpp b/JessicaLiu/Lab2/Lab2Part2/hellolib/src/hello.cpp new file mode 100644 index 0000000..24db953 --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/hellolib/src/hello.cpp @@ -0,0 +1,6 @@ +#include +#include "hello.h" + +void Hello::hello_world() { + std::cout << "Hello, World!" << std::endl; +} \ No newline at end of file diff --git a/JessicaLiu/Lab2/Lab2Part2/result b/JessicaLiu/Lab2/Lab2Part2/result new file mode 120000 index 0000000..0a2037a --- /dev/null +++ b/JessicaLiu/Lab2/Lab2Part2/result @@ -0,0 +1 @@ +/nix/store/fw32v9xzsjfs2gm6g5bmkw98ckx299p3-hello_world-0.1.0 \ No newline at end of file From 06013fce0e37af7437cb73cb565b432675870da4 Mon Sep 17 00:00:00 2001 From: jessicaliu06 Date: Sun, 15 Sep 2024 16:55:06 -0400 Subject: [PATCH 2/2] Lab 2 Part 2 --- JessicaLiu/Lab2/Lab2Part2/flake.lock | 36 +++++++++++++++++++++++++++- JessicaLiu/Lab2/Lab2Part2/result | 1 - 2 files changed, 35 insertions(+), 2 deletions(-) delete mode 120000 JessicaLiu/Lab2/Lab2Part2/result diff --git a/JessicaLiu/Lab2/Lab2Part2/flake.lock b/JessicaLiu/Lab2/Lab2Part2/flake.lock index fe85acd..0fc19ba 100644 --- a/JessicaLiu/Lab2/Lab2Part2/flake.lock +++ b/JessicaLiu/Lab2/Lab2Part2/flake.lock @@ -17,7 +17,41 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" } } }, diff --git a/JessicaLiu/Lab2/Lab2Part2/result b/JessicaLiu/Lab2/Lab2Part2/result deleted file mode 120000 index 0a2037a..0000000 --- a/JessicaLiu/Lab2/Lab2Part2/result +++ /dev/null @@ -1 +0,0 @@ -/nix/store/fw32v9xzsjfs2gm6g5bmkw98ckx299p3-hello_world-0.1.0 \ No newline at end of file