diff --git a/CMakeLists.txt b/CMakeLists.txt index aeaf1cb..e1fd1d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,25 +1,30 @@ cmake_minimum_required(VERSION 3.22) # Global Variables -set(TARGET_NAME cpp_insa) +set(EXERCICE_TARGET exercice_insa) +set(TD_TARGET td_insa) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Set the etape value -set(ETAPE "1" CACHE STRING "Entrez un nombre d'etape a compiler.") +set(ETAPE "1" CACHE STRING "Entrez l'exercice a compiler.") +set(TD "1" CACHE STRING "Entrez le td a compiler.") -#Setting up the sources directory -file(GLOB SOURCES "${PROJECT_SOURCE_DIR}/src/etape${ETAPE}/*.cpp") +# Etapes exercice +file(GLOB SOURCES_EXE "${PROJECT_SOURCE_DIR}/exercice/etape${ETAPE}/*.cpp") +add_executable(${EXERCICE_TARGET} ${SOURCES_EXE}) -# cpp_insa Project (source, header) -add_executable(${TARGET_NAME} ${SOURCES}) -# Adding the headers -target_include_directories(${TARGET_NAME} PUBLIC "include") +# TD +file(GLOB SOURCES_TD "${PROJECT_SOURCE_DIR}/td/td${TD}/src/*.cpp") +add_executable(${TD_TARGET} ${SOURCES_TD}) +target_include_directories(${TD_TARGET} PUBLIC "${PROJECT_SOURCE_DIR}/td/td${ETAPE}/include") # Adding compilation option depending on the OS if(MSVC) - target_compile_options(${TARGET_NAME} PUBLIC /W3 /WX /DEBUG ) + target_compile_options(${EXERCICE_TARGET} PUBLIC /W3 /WX /DEBUG ) + target_compile_options(${TD_TARGET} PUBLIC /W3 /WX /DEBUG ) else() - target_compile_options(${TARGET_NAME} PUBLIC -Wall -Wextra -Wpedantic -Werror -lstdc++) + target_compile_options(${EXERCICE_TARGET} PUBLIC -Wall -Wextra -Wpedantic -Werror -lstdc++) + target_compile_options(${TD_TARGET} PUBLIC -Wall -Wextra -Wpedantic -Werror -lstdc++) endif() diff --git a/README.md b/README.md index a330412..1376731 100644 --- a/README.md +++ b/README.md @@ -5,24 +5,25 @@ ### Préparer la compilation Pour compiler le projet je recommande CMake, mais il est possible d'utiliser directement 'g++'/'gcc'. -Une simple commande vous permet de préparer les fichiers dépendant de l'étape : +Une simple commande vous permet de préparer les fichiers dépendant de l'étape pour le td ou l'exercice : ``` mkdir build cd build ``` ``` -cmake -DETAPE=2 .. +cmake -DETAPE=2 -DTD=1 .. ``` -_Dans cet exemple, l'étape 2 sera construite._ +_Dans cet exemple, l'étape 2 et le td 1 seront construits._ ### Lancer la compilation Il suffit ensuite de construire l'executable dans le dossier désiré ``` -cmake --build . +cmake --build . --target ``` +>`` étant soit `td_insa` ou `exercice_insa` ## Conseil pour compiler et executer efficacement @@ -30,10 +31,9 @@ Je vous suggère d'aller dans le dossier contenant l'executable dès que les deu Pour cela rendez vous à la racine du projet après avoir crée et préparer le build : ``` -./run.sh +./run.sh ``` _Pour GNU GCC/G++ sur Linux_ -``` -run.bat -``` -_Pour MSVC sur Windows_ \ No newline at end of file +>`` étant soit `td_insa` ou `exercice_insa` + +_le script Windows n'est plus fonctionnel pour le moment_ \ No newline at end of file diff --git a/src/etape1/Mon_nom.cpp b/exercice/etape1/Mon_nom.cpp similarity index 100% rename from src/etape1/Mon_nom.cpp rename to exercice/etape1/Mon_nom.cpp diff --git a/src/etape2/point2d.cpp b/exercice/etape2/point2d.cpp similarity index 100% rename from src/etape2/point2d.cpp rename to exercice/etape2/point2d.cpp diff --git a/src/etape2/point2d.h b/exercice/etape2/point2d.h similarity index 100% rename from src/etape2/point2d.h rename to exercice/etape2/point2d.h diff --git a/src/etape3/point2d.cpp b/exercice/etape3/point2d.cpp similarity index 100% rename from src/etape3/point2d.cpp rename to exercice/etape3/point2d.cpp diff --git a/src/etape3/point2d.h b/exercice/etape3/point2d.h similarity index 100% rename from src/etape3/point2d.h rename to exercice/etape3/point2d.h diff --git a/src/etape4/point2d.cpp b/exercice/etape4/point2d.cpp similarity index 100% rename from src/etape4/point2d.cpp rename to exercice/etape4/point2d.cpp diff --git a/src/etape4/point2d.h b/exercice/etape4/point2d.h similarity index 100% rename from src/etape4/point2d.h rename to exercice/etape4/point2d.h diff --git a/src/etape4/point3d.h b/exercice/etape4/point3d.h similarity index 100% rename from src/etape4/point3d.h rename to exercice/etape4/point3d.h diff --git a/src/etape5/main.cpp b/exercice/etape5/main.cpp similarity index 100% rename from src/etape5/main.cpp rename to exercice/etape5/main.cpp diff --git a/src/etape5/point2d.cpp b/exercice/etape5/point2d.cpp similarity index 100% rename from src/etape5/point2d.cpp rename to exercice/etape5/point2d.cpp diff --git a/src/etape5/point2d.h b/exercice/etape5/point2d.h similarity index 100% rename from src/etape5/point2d.h rename to exercice/etape5/point2d.h diff --git a/src/etape5/point3d.cpp b/exercice/etape5/point3d.cpp similarity index 100% rename from src/etape5/point3d.cpp rename to exercice/etape5/point3d.cpp diff --git a/src/etape5/point3d.h b/exercice/etape5/point3d.h similarity index 100% rename from src/etape5/point3d.h rename to exercice/etape5/point3d.h diff --git a/src/etape6/main.cpp b/exercice/etape6/main.cpp similarity index 92% rename from src/etape6/main.cpp rename to exercice/etape6/main.cpp index 288028e..105236f 100644 --- a/src/etape6/main.cpp +++ b/exercice/etape6/main.cpp @@ -12,5 +12,6 @@ int main(void) Point2D pointC; std::cin >> pointC; std::cout << "pointC entered: " << pointC << std::endl; + friendFunction(pointA); return 0; } \ No newline at end of file diff --git a/src/etape6/point2d.cpp b/exercice/etape6/point2d.cpp similarity index 92% rename from src/etape6/point2d.cpp rename to exercice/etape6/point2d.cpp index 60003dd..a4a412b 100644 --- a/src/etape6/point2d.cpp +++ b/exercice/etape6/point2d.cpp @@ -59,4 +59,9 @@ std::istream& operator>>(std::istream& stream, Point2D& point) Point2D operator*(int value, const Point2D& point) { return {point._x*value, point._y*value}; +} + +void friendFunction(Point2D& obj) +{ + std::cout << obj._x << std::endl; } \ No newline at end of file diff --git a/src/etape6/point2d.h b/exercice/etape6/point2d.h similarity index 92% rename from src/etape6/point2d.h rename to exercice/etape6/point2d.h index 1d42e27..66ec280 100644 --- a/src/etape6/point2d.h +++ b/exercice/etape6/point2d.h @@ -16,6 +16,7 @@ class Point2D { friend std::ostream& operator<<(std::ostream& stream, const Point2D& point); friend std::istream& operator>>(std::istream& stream, Point2D& point); friend Point2D operator*(int value, const Point2D& point); + friend void friendFunction(Point2D& obj); protected: float _x,_y; }; diff --git a/src/etape6/point3d.cpp b/exercice/etape6/point3d.cpp similarity index 100% rename from src/etape6/point3d.cpp rename to exercice/etape6/point3d.cpp diff --git a/src/etape6/point3d.h b/exercice/etape6/point3d.h similarity index 100% rename from src/etape6/point3d.h rename to exercice/etape6/point3d.h diff --git a/run.sh b/run.sh index 31d7791..7a60910 100755 --- a/run.sh +++ b/run.sh @@ -1,2 +1,12 @@ -cmake --build build -./build/cpp_insa \ No newline at end of file +#!/bin/bash + +# check target name cmake +#return an error if not successful +if [ $# -eq 0 ]; then + echo "Usage: $0 " + exit 1 +fi + +target_name="$1" +cmake --build build --target "$target_name" +"./build/$target_name" \ No newline at end of file diff --git a/td/td1/src/main.cpp b/td/td1/src/main.cpp new file mode 100644 index 0000000..5c0937c --- /dev/null +++ b/td/td1/src/main.cpp @@ -0,0 +1,7 @@ +#include + +int main(void) +{ + std::cout << "Hello world!" << std::endl; + return 0; +} \ No newline at end of file