Skip to content

Commit

Permalink
make extract main ism logic into lib
Browse files Browse the repository at this point in the history
  • Loading branch information
neferin12 committed Nov 6, 2023
1 parent ca156ad commit cbf3961
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
18 changes: 11 additions & 7 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.5)

project(cISM)
project(cISM VERSION 1.0.0 DESCRIPTION "C implementation of iSM")

include(GNUInstallDirs)

set(CMAKE_C_STANDARD 11)

Expand All @@ -17,19 +19,21 @@ set(CMAKE_C_FLAGS_RELEASE "-O3")
include_directories(${PROJECT_SOURCE_DIR}/src/headers)

add_subdirectory(src)
configure_file(ism.pc.in ism.pc @ONLY)

install(TARGETS cism)
install(TARGETS ism cism
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${CMAKE_BINARY_DIR}/ism.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)

# Tests
enable_testing()
find_package(PkgConfig REQUIRED)
find_package(MPI REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0)


add_executable(testISM tests/testIsm.c tests/copy.c src/algorithm.c src/cismMPI.c src/constants.c src/errorHandling.c src/io.c src/organization.c src/log.c)
add_executable(testISM tests/testIsm.c tests/copy.c src/cismMPI.c)
set_target_properties(testISM PROPERTIES EXCLUDE_FROM_ALL TRUE)
target_link_libraries(testISM PkgConfig::deps MPI::MPI_C)
target_link_libraries(testISM PkgConfig::deps MPI::MPI_C ism)
add_test(test_build
"${CMAKE_COMMAND}"
--build "${CMAKE_BINARY_DIR}"
Expand All @@ -41,4 +45,4 @@ add_test(testISM testISM version)
set_tests_properties(testISM PROPERTIES FIXTURES_REQUIRED test_fixture)
add_test(NAME IO COMMAND testISM io ${PROJECT_SOURCE_DIR}/../example-files/Wahlen.csv ${PROJECT_SOURCE_DIR}/../example-files/Seminare.csv)
add_test(NAME DeepCopyStudents COMMAND testISM copy ${PROJECT_SOURCE_DIR}/../example-files/Wahlen.csv ${PROJECT_SOURCE_DIR}/../example-files/Seminare.csv)
add_test(NAME Algorithm COMMAND testISM alg ${PROJECT_SOURCE_DIR}/../example-files/Wahlen.csv ${PROJECT_SOURCE_DIR}/../example-files/Seminare.csv)
add_test(NAME Algorithm COMMAND testISM alg ${PROJECT_SOURCE_DIR}/../example-files/Wahlen.csv ${PROJECT_SOURCE_DIR}/../example-files/Seminare.csv)
12 changes: 12 additions & 0 deletions c/ism.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
Version: @PROJECT_VERSION@

Requires:
Libs: -L${libdir} -lism
Cflags: -I${includedir}
9 changes: 7 additions & 2 deletions c/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
add_executable(cism main.c io.c errorHandling.c organization.c headers/algorithm.h algorithm.c headers/constants.h constants.c cismMPI.c headers/cismMPI.h log.c headers/log.h)
add_library(ism SHARED algorithm.c io.c log.c organization.c errorHandling.c constants.c)
target_include_directories(ism PUBLIC ${PROJECT_SOURCE_DIR}/src/headers)

add_executable(cism main.c cismMPI.c headers/cismMPI.h)

find_package(PkgConfig REQUIRED)
find_package(MPI REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0)

target_link_libraries(cism PkgConfig::deps MPI::MPI_C)
target_link_libraries(ism PkgConfig::deps)

target_link_libraries(cism MPI::MPI_C ism)
1 change: 0 additions & 1 deletion c/src/cismMPI.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "headers/errorHandling.h"
#include "headers/log.h"
#include <mpi.h>
#include <stdio.h>
#include <stdbool.h>

GArray *mpiRun(int runsPerProcess, const char *filenameVotes, const char *filenameSeminars) {
Expand Down

0 comments on commit cbf3961

Please sign in to comment.