From 0a634d905873a0ddc2e712cbd7ad7e022fa20b64 Mon Sep 17 00:00:00 2001 From: Matteo Cicuttin Date: Wed, 25 Mar 2026 22:37:29 +0100 Subject: [PATCH 1/4] Updated to CMake. --- CMakeLists.txt | 75 ++++++++++++++++++++++ Makefile | 16 ----- gmshData.hpp => include/gmshData.hpp | 0 gmshElement.hpp => include/gmshElement.hpp | 0 gmshMesh.hpp => include/gmshMesh.hpp | 0 gmshData.cpp => src/gmshData.cpp | 0 gmshElement.cpp => src/gmshElement.cpp | 0 gmshMesh.cpp => src/gmshMesh.cpp | 0 main.cc => src/main.cc | 0 9 files changed, 75 insertions(+), 16 deletions(-) create mode 100644 CMakeLists.txt delete mode 100644 Makefile rename gmshData.hpp => include/gmshData.hpp (100%) rename gmshElement.hpp => include/gmshElement.hpp (100%) rename gmshMesh.hpp => include/gmshMesh.hpp (100%) rename gmshData.cpp => src/gmshData.cpp (100%) rename gmshElement.cpp => src/gmshElement.cpp (100%) rename gmshMesh.cpp => src/gmshMesh.cpp (100%) rename main.cc => src/main.cc (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b8e2dbc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.20) +project(gmsh_tools VERSION 1.0 LANGUAGES CXX) + +set(PROJECT_IS_TOP_LEVEL OFF) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set(PROJECT_IS_TOP_LEVEL ON) +endif() + +option(BUILD_GMSH_TOOLS_EXECUTABLE "Build the gmsh_tools executable" ${PROJECT_IS_TOP_LEVEL}) + +set(LIB_NAME gmshtools) +set(EXE_NAME ${PROJECT_NAME}) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(LIB_SOURCES src/gmshData.cpp src/gmshElement.cpp src/gmshMesh.cpp) + +add_library(${LIB_NAME} STATIC ${LIB_SOURCES}) + +target_include_directories(${LIB_NAME} + PUBLIC + $ + $ +) + +if(BUILD_GMSH_TOOLS_EXECUTABLE) + add_executable(${EXE_NAME} src/main.cc) + + target_link_libraries(${EXE_NAME} + PRIVATE ${LIB_NAME} + ) +endif() + + +include(GNUInstallDirs) + +install(TARGETS ${LIB_NAME} + EXPORT ${LIB_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install(DIRECTORY include/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +if(BUILD_EXECUTABLE) + install(TARGETS ${EXE_NAME} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) +endif() + +# Export targets (for find_package / parent projects) +install(EXPORT ${LIB_NAME}Targets + FILE ${LIB_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +# Optional: generate a basic config file +include(CMakePackageConfigHelpers) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +install(FILES + "${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 01d9421..0000000 --- a/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -CXX = g++ -std=c++11 -DEBUG_FLAG = -DDEBUG -Wall -Wextra -pedantic -Weffc++ -Wshadow -Wundef -RELEASE = -O2 - -PROG = gmsh_tools -SRC = gmshElement.cpp gmshMesh.cpp gmshData.cpp main.cc - -debug : - $(CXX) $(DEBUG_FLAG) $(SRC) -o $(PROG) - -release : - $(CXX) $(RELEASE) $(SRC) -o $(PROG) - -clean : - @rm *.o $(PROG) - @echo "On a fait du nettoyage" diff --git a/gmshData.hpp b/include/gmshData.hpp similarity index 100% rename from gmshData.hpp rename to include/gmshData.hpp diff --git a/gmshElement.hpp b/include/gmshElement.hpp similarity index 100% rename from gmshElement.hpp rename to include/gmshElement.hpp diff --git a/gmshMesh.hpp b/include/gmshMesh.hpp similarity index 100% rename from gmshMesh.hpp rename to include/gmshMesh.hpp diff --git a/gmshData.cpp b/src/gmshData.cpp similarity index 100% rename from gmshData.cpp rename to src/gmshData.cpp diff --git a/gmshElement.cpp b/src/gmshElement.cpp similarity index 100% rename from gmshElement.cpp rename to src/gmshElement.cpp diff --git a/gmshMesh.cpp b/src/gmshMesh.cpp similarity index 100% rename from gmshMesh.cpp rename to src/gmshMesh.cpp diff --git a/main.cc b/src/main.cc similarity index 100% rename from main.cc rename to src/main.cc From 93938bd8f73093143a8e5cb699ae5d7f88038d0c Mon Sep 17 00:00:00 2001 From: Matteo Cicuttin Date: Wed, 25 Mar 2026 22:41:09 +0100 Subject: [PATCH 2/4] Fixed README.md. --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e0b8f2b..fc7be80 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,18 @@ This C++ librairy provides some tools to read and write meshes: The library runs on Unix systems. It is written in C++11 and requires a recent compiler to be compiled (GCC >= 5.0 or Clang >= 3.8). Older compilers may work but they are neither supported nor tested. To compile it: - make + + mkdir build + cd build + cmake .. + make You will end up with an executable named `gmsh_tools` and some meshes in `/meshes`. -# Exemple -There is an exemple in main.cc +# Example +There is an example in main.cc gmsh_tools ./meshes/ From c6d0a6e2912805a9def5a72e5db8c04f55549042 Mon Sep 17 00:00:00 2001 From: Matteo Cicuttin Date: Wed, 25 Mar 2026 22:52:17 +0100 Subject: [PATCH 3/4] Small fixes --- CMakeLists.txt | 15 ++++++--------- include/{ => gmsh_tools}/gmshData.hpp | 0 include/{ => gmsh_tools}/gmshElement.hpp | 0 include/{ => gmsh_tools}/gmshMesh.hpp | 0 src/gmshData.cpp | 6 +++--- src/gmshElement.cpp | 4 ++-- src/gmshMesh.cpp | 4 ++-- src/main.cc | 6 +++--- 8 files changed, 16 insertions(+), 19 deletions(-) rename include/{ => gmsh_tools}/gmshData.hpp (100%) rename include/{ => gmsh_tools}/gmshElement.hpp (100%) rename include/{ => gmsh_tools}/gmshMesh.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8e2dbc..8f52021 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,24 +52,21 @@ if(BUILD_EXECUTABLE) ) endif() -# Export targets (for find_package / parent projects) install(EXPORT ${LIB_NAME}Targets FILE ${LIB_NAME}Targets.cmake - NAMESPACE ${PROJECT_NAME}:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} + NAMESPACE ${LIB_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB_NAME} ) -# Optional: generate a basic config file include(CMakePackageConfigHelpers) write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/cmake/${LIB_NAME}Config.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) install(FILES - "${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} -) \ No newline at end of file + "${CMAKE_CURRENT_BINARY_DIR}/cmake/${LIB_NAME}Config.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB_NAME} +) diff --git a/include/gmshData.hpp b/include/gmsh_tools/gmshData.hpp similarity index 100% rename from include/gmshData.hpp rename to include/gmsh_tools/gmshData.hpp diff --git a/include/gmshElement.hpp b/include/gmsh_tools/gmshElement.hpp similarity index 100% rename from include/gmshElement.hpp rename to include/gmsh_tools/gmshElement.hpp diff --git a/include/gmshMesh.hpp b/include/gmsh_tools/gmshMesh.hpp similarity index 100% rename from include/gmshMesh.hpp rename to include/gmsh_tools/gmshMesh.hpp diff --git a/src/gmshData.cpp b/src/gmshData.cpp index 3f20047..be373ca 100644 --- a/src/gmshData.cpp +++ b/src/gmshData.cpp @@ -20,9 +20,9 @@ #include #include -#include "gmshData.hpp" -#include "gmshElement.hpp" -#include "gmshMesh.hpp" +#include "gmsh_tools/gmshData.hpp" +#include "gmsh_tools/gmshElement.hpp" +#include "gmsh_tools/gmshMesh.hpp" namespace gmsh { diff --git a/src/gmshElement.cpp b/src/gmshElement.cpp index cc00efe..3f1c549 100644 --- a/src/gmshElement.cpp +++ b/src/gmshElement.cpp @@ -14,8 +14,8 @@ * cite it. */ -#include "gmshElement.hpp" -#include "gmshMesh.hpp" +#include "gmsh_tools/gmshElement.hpp" +#include "gmsh_tools/gmshMesh.hpp" #include #include #include diff --git a/src/gmshMesh.cpp b/src/gmshMesh.cpp index b5fe7b8..45a8447 100644 --- a/src/gmshMesh.cpp +++ b/src/gmshMesh.cpp @@ -14,8 +14,8 @@ * cite it. */ -#include "gmshMesh.hpp" -#include "gmshElement.hpp" +#include "gmsh_tools/gmshMesh.hpp" +#include "gmsh_tools/gmshElement.hpp" #include #include #include diff --git a/src/main.cc b/src/main.cc index 774ee64..f249e31 100644 --- a/src/main.cc +++ b/src/main.cc @@ -17,9 +17,9 @@ #include #include #include -#include "gmshMesh.hpp" -#include "gmshData.hpp" -#include "gmshElement.hpp" +#include "gmsh_tools/gmshMesh.hpp" +#include "gmsh_tools/gmshData.hpp" +#include "gmsh_tools/gmshElement.hpp" using namespace std; From 8c85d7f6e7e8a4bb9b96913b4386f4dc6b632b0c Mon Sep 17 00:00:00 2001 From: Matteo Cicuttin Date: Wed, 22 Apr 2026 12:43:05 +0200 Subject: [PATCH 4/4] Enabled PIC code. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f52021..9b26360 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(LIB_SOURCES src/gmshData.cpp src/gmshElement.cpp src/gmshMesh.cpp) add_library(${LIB_NAME} STATIC ${LIB_SOURCES}) +set_target_properties(${LIB_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(${LIB_NAME} PUBLIC