commit 55aff2e562fb349960a9408928d8208f7613c51e
parent 79ce28551a91c95cd04797a080a0bafad217278c
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Tue, 14 Jun 2022 16:29:20 +0200
Change build system from make to cmake
Diffstat:
| D | Makefile | | | 50 | -------------------------------------------------- |
| A | cmake/CMakeLists.txt | | | 105 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| D | config.mk | | | 7 | ------- |
3 files changed, 105 insertions(+), 57 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,50 +0,0 @@
-# Copyright (C) 2022 |Meso|Star> (contact@meso-star.com)
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-.POSIX:
-.SUFFIXES: # Clean up default inference rules
-
-include config.mk
-
-SRC = src/scad.c
-OBJ = $(SRC:.c=.o)
-
-libscad.a: $(OBJ)
- $(AR) $(AFLAGS) libscad.a $(OBJ)
-
-$(OBJ): config.mk
-
-.SUFFIXES: .c .o
-.c.o:
- $(CC) $(CFLAGS) -c $< -o $@
-
-test: $(OBJ) src/test.o
- $(CC) -o $@ src/test.o $(OBJ) libscad.a $(LDLIBS) $(LDFLAGS)
-
-src/test.o: src/test.c
- $(CC) $(CFLAGS) -c $< -o $@
-
-clean:
- rm -f $(OBJ) libscad.a src/test.o test
-
-install: static_lib
- mkdir -p $(PREFIX)/lib
- mkdir -p $(PREFIX)/include/
- cp libscad.a $(PREFIX)/lib
- cp src/scad.h $(PREFIX)/include/
-
-uninstall:
- rm -f $(PREFIX)/lib/libscad.a
- rm -f $(PREFIX)/include/scad.h
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -0,0 +1,105 @@
+# Copyright (C) 2022 |Meso|Star> (contact@meso-star.com)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+cmake_minimum_required(VERSION 3.1)
+project(star-cad C)
+enable_testing()
+
+set(SCAD_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
+option(NO_TEST "Disable the test" OFF)
+
+################################################################################
+# Check dependencies
+################################################################################
+find_package(gmsh 4.9.5 EXACT REQUIRED)
+find_package(RCMake 0.4.1 REQUIRED)
+find_package(RSys 0.12.1 REQUIRED)
+
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
+include(rcmake)
+include(rcmake_runtime)
+
+include_directories(${GMSH_INCLUDE_DIR} ${RSys_INCLUDE_DIR})
+
+################################################################################
+# Configure and define targets
+################################################################################
+set(VERSION_MAJOR 0)
+set(VERSION_MINOR 1)
+set(VERSION_PATCH 0)
+set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
+
+set(SCAD_FILES_SRC
+ scad.c)
+set(SCAD_FILES_INC_API scad.h)
+set(SCAD_FILES_INC
+ )
+set(SCAD_FILES_DOC COPYING README.md)
+
+# Prepend each file in the `SCAD_FILES_<SRC|INC>' list by `SCAD_SOURCE_DIR'
+rcmake_prepend_path(SCAD_FILES_SRC ${SCAD_SOURCE_DIR})
+rcmake_prepend_path(SCAD_FILES_INC ${SCAD_SOURCE_DIR})
+rcmake_prepend_path(SCAD_FILES_INC_API ${SCAD_SOURCE_DIR})
+rcmake_prepend_path(SCAD_FILES_DOC ${PROJECT_SOURCE_DIR}/../)
+
+add_library(scad SHARED ${SCAD_FILES_SRC} ${SCAD_FILES_INC} ${SCAD_FILES_INC_API})
+target_link_libraries(scad RSys ${GMSH_LIBRARIES})
+
+set_target_properties(scad PROPERTIES
+ DEFINE_SYMBOL SCAD_SHARED_BUILD
+ VERSION ${VERSION}
+ SOVERSION ${VERSION_MAJOR})
+
+rcmake_setup_devel(scad StarCAD ${VERSION} star/scad_version.h)
+
+################################################################################
+# Add tests
+################################################################################
+if(NOT NO_TEST)
+ function(build_test _name)
+ add_executable(${_name}
+ ${SCAD_SOURCE_DIR}/${_name}.c)
+ target_link_libraries(${_name} scad RSys)
+ set(_libraries ${ARGN})
+ foreach(_lib ${_libraries})
+ target_link_libraries(${_name} ${_lib})
+ endforeach()
+ endfunction()
+
+ function(register_test _name)
+ add_test(${_name} ${ARGN})
+ endfunction()
+
+ function(new_test _name)
+ build_test(${_name} ${ARGN})
+ register_test(${_name} ${_name})
+ endfunction()
+
+ new_test(test1)
+
+ rcmake_copy_runtime_libraries(test)
+
+endif(NOT NO_TEST)
+
+################################################################################
+# Define output & install directories
+################################################################################
+install(TARGETS scad
+ ARCHIVE DESTINATION bin
+ LIBRARY DESTINATION lib
+ RUNTIME DESTINATION bin)
+install(FILES ${SCAD_FILES_INC_API} DESTINATION include/star)
+install(FILES ${SCAD_FILES_DOC} DESTINATION share/doc/star-cad)
+
diff --git a/config.mk b/config.mk
@@ -1,7 +0,0 @@
-CC = cc
-PREFIX = /usr/local
-
-AFLAGS = crs
-WFLAGS = -Wall -Wextra -Wmissing-declarations -Wmissing-prototypes -Wconversion -Wshadow
-CFLAGS = -O2 -std=c89 -pedantic $(WFLAGS)
-LDLIBS = -lm -lrsys -lgmsh