Skip to content

Commit

Permalink
See issue #76: Pulling over code from other, oolder branch
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshjoshi committed Dec 6, 2022
1 parent 91ca9fc commit 622e386
Show file tree
Hide file tree
Showing 30 changed files with 18,226 additions and 4 deletions.
File renamed without changes.
28 changes: 28 additions & 0 deletions examples/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
cmake_minimum_required(VERSION 3.19)

project(pantscc
LANGUAGES
C CXX
VERSION
0.0.1
)

set(CMAKE_VERBOSE_MAKEFILE TRUE)
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Don't fallback if CXX_STANDARD not found
set(CMAKE_CXX_EXTENSIONS OFF)

add_subdirectory(app)
add_subdirectory(core)
add_subdirectory(trivialc)
add_subdirectory(trivialcpp)
21 changes: 21 additions & 0 deletions examples/cc/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
set(MODULE_NAME "app")
set(EXECUTABLE_NAME "${PROJECT_NAME}-${MODULE_NAME}")

project(${EXECUTABLE_NAME})

add_executable(${EXECUTABLE_NAME})
target_sources(${EXECUTABLE_NAME}
PRIVATE
src/foo.c
src/main.cpp
)

target_compile_options(${EXECUTABLE_NAME}
PRIVATE
-Wall -Wextra -Wno-c++98-compat
)

target_link_libraries(${EXECUTABLE_NAME}
PRIVATE
pantscc-core
)
6 changes: 6 additions & 0 deletions examples/cc/app/src/BUILD.pants
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cc_sources(name="sources")

cc_binary(
name="exe",
dependencies=[":sources"]
)
6 changes: 6 additions & 0 deletions examples/cc/app/src/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "foo.h"

int add(int a, int b)
{
return a + b;
}
13 changes: 13 additions & 0 deletions examples/cc/app/src/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef FOO_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

int add(int a, int b);

#ifdef __cplusplus
}
#endif //__cplusplus

#endif
12 changes: 12 additions & 0 deletions examples/cc/app/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>

#include "core/greeter.h"
#include "foo.h"

int main()
{
int result = add(1, 2);
greet();
std::cout << "Hello, C++ world! " << result << std::endl;
return 0;
}
4 changes: 4 additions & 0 deletions examples/cc/core/BUILD.pants
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cc_binary(
name="tests",
dependencies=["./src:sources", "./tests:tests"]
)
22 changes: 22 additions & 0 deletions examples/cc/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set(MODULE_NAME "core")
set(LIBRARY_NAME "${PROJECT_NAME}-${MODULE_NAME}")

project(${LIBRARY_NAME})

add_library(${LIBRARY_NAME} STATIC)
target_sources(${LIBRARY_NAME}
PRIVATE
src/greeter.c
)

target_include_directories(${LIBRARY_NAME}
PUBLIC
include
)

target_compile_options(${LIBRARY_NAME}
PRIVATE
-Wall -Wextra -Wno-c++98-compat
)


1 change: 1 addition & 0 deletions examples/cc/core/include/core/BUILD.pants
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cc_sources()
15 changes: 15 additions & 0 deletions examples/cc/core/include/core/greeter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef CORE_GREETER_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

void greet(void);

int add(int a, int b);

#ifdef __cplusplus
}
#endif //__cplusplus

#endif // CORE_GREETER_H
3 changes: 3 additions & 0 deletions examples/cc/core/src/BUILD.pants
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cc_sources(
name="sources"
)
6 changes: 6 additions & 0 deletions examples/cc/core/src/greeter-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef CORE_GREETER_PRIVATE_H

// This file only exists to ensure that private and exported headers can work together
char greetingSymbol(void);

#endif // CORE_GREETER_PRIVATE_H
22 changes: 22 additions & 0 deletions examples/cc/core/src/greeter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "core/greeter.h"

#include "greeter-private.h"
#include <stdio.h>

// Declared in core/greeter.h
void greet(void)
{
char symbol = greetingSymbol();
printf("Greetings, world%c", symbol);
}

int add(int a, int b)
{
return a + b;
}

// Declared in greeter-private.h
char greetingSymbol(void)
{
return '!';
}
3 changes: 3 additions & 0 deletions examples/cc/core/tests/BUILD.pants
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cc_sources(
name="tests"
)
Loading

0 comments on commit 622e386

Please sign in to comment.