Add build scripts and update .gitignore

This commit introduces build scripts for both Windows (`build.bat`) and Linux/macOS (`build.sh`) to simplify the build process.

It also updates the `.gitignore` file to a more comprehensive version that includes common patterns for C++ projects and various IDEs.
This commit is contained in:
google-labs-jules[bot]
2025-08-18 08:15:49 +00:00
parent 963c3a554b
commit 3b29526b9e
8 changed files with 80 additions and 0 deletions
+12
View File
@@ -39,3 +39,15 @@
# debug information files
*.dwo
# Build directory
/build/
# IDE files
.vscode/
.idea/
*.suo
*.ntvs*
*.njsproj
*.sln
*.vsproj
+24
View File
@@ -0,0 +1,24 @@
# CMake minimum version
cmake_minimum_required(VERSION 3.10)
# Project name
project(MyLibrary)
# Add the library
add_library(MyLibrary SHARED src/Library.cpp)
# Define MY_LIB_EXPORT, so that __declspec(dllexport) is used
target_compile_definitions(MyLibrary PRIVATE MY_LIB_EXPORT)
# Public headers
target_include_directories(MyLibrary PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)
# Set the output directory for the library
set_target_properties(MyLibrary PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
# Add the examples subdirectory
add_subdirectory(examples)
+5
View File
@@ -0,0 +1,5 @@
@echo off
if not exist build mkdir build
cd build
cmake ..
cmake --build .
+6
View File
@@ -0,0 +1,6 @@
#!/bin/bash
set -e
mkdir -p build
cd build
cmake ..
cmake --build .
+5
View File
@@ -0,0 +1,5 @@
# Add the executable
add_executable(Example main.cpp)
# Link against the library
target_link_libraries(Example MyLibrary)
+8
View File
@@ -0,0 +1,8 @@
#include <iostream>
#include "Library.h"
int main() {
int result = add(2, 3);
std::cout << "2 + 3 = " << result << std::endl;
return 0;
}
+5
View File
@@ -0,0 +1,5 @@
#include "Library.h"
int add(int a, int b) {
return a + b;
}
+15
View File
@@ -0,0 +1,15 @@
#pragma once
// Define MY_LIB_EXPORT for exporting symbols from the DLL
#if defined(_WIN32)
#if defined(MY_LIB_EXPORT)
#define MY_LIB_API __declspec(dllexport)
#else
#define MY_LIB_API __declspec(dllimport)
#endif
#else
#define MY_LIB_API
#endif
// A simple function to be exported
MY_LIB_API int add(int a, int b);