diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9b26360 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,73 @@ +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}) +set_target_properties(${LIB_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) + +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() + +install(EXPORT ${LIB_NAME}Targets + FILE ${LIB_NAME}Targets.cmake + NAMESPACE ${LIB_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB_NAME} +) + +include(CMakePackageConfigHelpers) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/cmake/${LIB_NAME}Config.cmake" + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/cmake/${LIB_NAME}Config.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${LIB_NAME} +) 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/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/ diff --git a/gmshData.hpp b/include/gmsh_tools/gmshData.hpp similarity index 100% rename from gmshData.hpp rename to include/gmsh_tools/gmshData.hpp diff --git a/gmshElement.hpp b/include/gmsh_tools/gmshElement.hpp similarity index 100% rename from gmshElement.hpp rename to include/gmsh_tools/gmshElement.hpp diff --git a/gmshMesh.hpp b/include/gmsh_tools/gmshMesh.hpp similarity index 100% rename from gmshMesh.hpp rename to include/gmsh_tools/gmshMesh.hpp diff --git a/gmshData.cpp b/src/gmshData.cpp similarity index 98% rename from gmshData.cpp rename to src/gmshData.cpp index 3f20047..be373ca 100644 --- a/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/gmshElement.cpp b/src/gmshElement.cpp similarity index 98% rename from gmshElement.cpp rename to src/gmshElement.cpp index cc00efe..3f1c549 100644 --- a/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/gmshMesh.cpp b/src/gmshMesh.cpp similarity index 99% rename from gmshMesh.cpp rename to src/gmshMesh.cpp index b5fe7b8..45a8447 100644 --- a/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/main.cc b/src/main.cc similarity index 95% rename from main.cc rename to src/main.cc index 774ee64..f249e31 100644 --- a/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;