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:
+12
@@ -39,3 +39,15 @@
|
||||
|
||||
# debug information files
|
||||
*.dwo
|
||||
|
||||
# Build directory
|
||||
/build/
|
||||
|
||||
# IDE files
|
||||
.vscode/
|
||||
.idea/
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.vsproj
|
||||
|
||||
@@ -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)
|
||||
@@ -0,0 +1,5 @@
|
||||
@echo off
|
||||
if not exist build mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake ..
|
||||
cmake --build .
|
||||
@@ -0,0 +1,5 @@
|
||||
# Add the executable
|
||||
add_executable(Example main.cpp)
|
||||
|
||||
# Link against the library
|
||||
target_link_libraries(Example MyLibrary)
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include "Library.h"
|
||||
|
||||
int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user