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

Lab 2 Part 2 #81

Open
wants to merge 2 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
9 changes: 9 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/default.nix
Original file line number Diff line number Diff line change
@@ -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 ];
}
60 changes: 60 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/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 JessicaLiu/Lab2/Lab2Part2/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
description = "Lab 02 Part 2 Flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
utils.url = "github:numtide/flake-utils";
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to include flake utils here if not using it

};

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;
};
}
15 changes: 15 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/helloapp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/helloapp/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "hello.h"

int main() {
Hello h;
h.hello_world();
return 0;
}
1 change: 1 addition & 0 deletions JessicaLiu/Lab2/Lab2Part2/helloapp/result
Copy link
Contributor

Choose a reason for hiding this comment

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

pls dont push up result symlink

8 changes: 8 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/hellolib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ stdenv, cmake }:

stdenv.mkDerivation rec {
pname = "hello_world";
version = "0.1.0";
src = ./hellolib;
nativeBuildInputs = [ cmake ];
}
50 changes: 50 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/hellolib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

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*"
)
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 9 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/hellolib/include/hello.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef _HELLO_H_
#define _HELLO_H_

class Hello {
public:
void hello_world();
};

#endif
1 change: 1 addition & 0 deletions JessicaLiu/Lab2/Lab2Part2/hellolib/result
Copy link
Contributor

Choose a reason for hiding this comment

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

pls dont push up this file

6 changes: 6 additions & 0 deletions JessicaLiu/Lab2/Lab2Part2/hellolib/src/hello.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include<iostream>
Copy link
Contributor

Choose a reason for hiding this comment

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

missing space

#include "hello.h"

void Hello::hello_world() {
std::cout << "Hello, World!" << std::endl;
}