star-geometry-2d

Cleaning and decorating 2D geometries
git clone git://git.meso-star.fr/star-geometry-2d.git
Log | Files | Refs | README | LICENSE

CMakeLists.txt (6275B)


      1 # Copyright (C) 2019, 2020, 2023 |Méso|Star> (contact@meso-star.com)
      2 #
      3 # This program is free software: you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation, either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     15 
     16 cmake_minimum_required(VERSION 3.1)
     17 project(star-geometry-2d C)
     18 enable_testing()
     19 
     20 include(CMakeDependentOption)
     21 
     22 set(STAR_GEOM_SOURCE_DIR ${PROJECT_SOURCE_DIR}/../src)
     23 option(NO_TEST
     24   "Do not build tests"
     25   OFF)
     26 
     27 cmake_dependent_option(SMALL_ADDITIONAL_TESTS
     28   "Build small additional tests originally written for star-enclosures" OFF
     29   "NOT NO_TEST" OFF)
     30 
     31 cmake_dependent_option(HUGE_ADDITIONAL_TESTS
     32   "Build additional tests originally written for star-enclosures that involve \
     33 millions of segments" OFF
     34   "NOT NO_TEST" OFF)
     35 
     36 ################################################################################
     37 # Check dependencies
     38 ################################################################################
     39 find_package(RCMake 0.4 REQUIRED)
     40 find_package(RSys 0.8.1 REQUIRED)
     41 
     42 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${RCMAKE_SOURCE_DIR})
     43 include(rcmake)
     44 include(rcmake_runtime)
     45 
     46 include_directories(
     47   ${RSys_INCLUDE_DIR}
     48   ${StarEnc_INCLUDE_DIR})
     49 
     50 rcmake_append_runtime_dirs(_runtime_dirs RSys StarEnc)
     51 
     52 ################################################################################
     53 # Configure and define targets
     54 ################################################################################
     55 set(VERSION_MAJOR 0)
     56 set(VERSION_MINOR 1)
     57 set(VERSION_PATCH 1)
     58 set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
     59 
     60 set(SG2D_FILES_SRC
     61   sg2d_device.c
     62   sg2d_geometry.c
     63 )
     64 
     65 set(SG2D_FILES_INC_API
     66   sg2d.h
     67   sg2d_sXd_helper.h
     68   sg2d_sencXd_helper.h
     69   sg2d_sdisXd_helper.h
     70   sgX2d.h
     71   sgX2d_undefs.h
     72 )
     73 
     74 set(SG2D_FILES_INC
     75   sg2d_device.h
     76   sg2d_geometry.h
     77   sg2d_misc.h
     78 )
     79 
     80 set(SG2D_FILES_DOC COPYING README.md)
     81 
     82 # Prepend each file by `STAR_GEOM_SOURCE_DIR'
     83 rcmake_prepend_path(SG2D_FILES_SRC ${STAR_GEOM_SOURCE_DIR})
     84 rcmake_prepend_path(SG2D_FILES_INC ${STAR_GEOM_SOURCE_DIR})
     85 rcmake_prepend_path(SG2D_FILES_INC_API ${STAR_GEOM_SOURCE_DIR})
     86 rcmake_prepend_path(SG2D_FILES_DOC ${PROJECT_SOURCE_DIR}/../)
     87 
     88 if(CMAKE_COMPILER_IS_GNUCC)
     89   set(MATH_LIB m)
     90 endif()
     91 
     92 if(MSVC)
     93 
     94 endif()
     95 
     96 add_library(sg2d SHARED
     97   ${SG2D_FILES_SRC}
     98   ${SG2D_FILES_INC}
     99   ${SG2D_FILES_INC_API})
    100 target_link_libraries(sg2d RSys ${MATH_LIB})
    101 
    102 set_target_properties(sg2d PROPERTIES
    103 # C99 needed in case of printf "PRTF_API" used
    104 #  C_STANDARD 99
    105   DEFINE_SYMBOL SG2D_SHARED_BUILD
    106   VERSION ${VERSION}
    107   SOVERSION ${VERSION_MAJOR})
    108 rcmake_copy_runtime_libraries(sg2d)
    109 
    110 rcmake_setup_devel(sg2d StarGeom2D ${VERSION} star/sg2d_version.h)
    111 
    112 ################################################################################
    113 # Add tests
    114 ################################################################################
    115 if(NOT NO_TEST)
    116   function(build_test _name)
    117     add_executable(${_name}
    118       ${STAR_GEOM_SOURCE_DIR}/${_name}.c
    119 	  ${STAR_GEOM_SOURCE_DIR}/test_sg2d_utils.h)
    120     foreach(other ${ARGN})
    121       target_sources(${_name}
    122         PUBLIC ${STAR_GEOM_SOURCE_DIR}/${other})
    123     endforeach()
    124     target_link_libraries(${_name} RSys sg2d)
    125   endfunction()
    126 
    127   function(register_test _name)
    128     add_test(${_name} ${ARGN})
    129     rcmake_set_test_runtime_dirs(${_name} _runtime_dirs)
    130   endfunction()
    131 
    132   function(new_test _name)
    133     build_test(${_name} ${ARGN})
    134     register_test(${_name} ${_name})
    135   endfunction()
    136 
    137   new_test(test_sg2d_device)
    138   new_test(test_sg2d_geometry)
    139   new_test(test_sg2d_geometry_2)
    140 
    141   build_test(test_sg2d_invalid_models)
    142   build_test(test_sg2d_square_behind_square)
    143   build_test(test_sg2d_square_in_square)
    144   build_test(test_sg2d_square_on_square)
    145   build_test(test_sg2d_some_enclosures test_sg2d_utils2.h)
    146   build_test(test_sg2d_some_segments test_sg2d_utils2.h)
    147   build_test(test_sg2d_unspecified_properties)
    148 
    149   build_test(test_sg2d_many_enclosures test_sg2d_utils2.h)
    150   build_test(test_sg2d_many_segments test_sg2d_utils2.h)
    151 
    152   rcmake_copy_runtime_libraries(test_sg2d_device)
    153   rcmake_copy_runtime_libraries(test_sg2d_geometry)
    154   rcmake_copy_runtime_libraries(test_sg2d_geometry_2)
    155 
    156   rcmake_copy_runtime_libraries(test_sg2d_invalid_models)
    157   rcmake_copy_runtime_libraries(test_sg2d_square_behind_square)
    158   rcmake_copy_runtime_libraries(test_sg2d_square_in_square)
    159   rcmake_copy_runtime_libraries(test_sg2d_square_on_square)
    160   rcmake_copy_runtime_libraries(test_sg2d_some_enclosures)
    161   rcmake_copy_runtime_libraries(test_sg2d_some_segments)
    162   rcmake_copy_runtime_libraries(test_sg2d_unspecified_properties)
    163   
    164   rcmake_copy_runtime_libraries(test_sg2d_many_enclosures)
    165   rcmake_copy_runtime_libraries(test_sg2d_many_segments)
    166 
    167   if(SMALL_ADDITIONAL_TESTS)
    168     add_test(test_sg3d_invalid_models test_sg2d_invalid_models)
    169     add_test(test_sg2d_square_behind_square test_sg2d_square_behind_square)
    170     add_test(test_sg2d_square_in_square test_sg2d_square_in_square)
    171     add_test(test_sg2d_square_on_square test_sg2d_square_on_square)
    172     add_test(test_sg2d_some_enclosures test_sg2d_some_enclosures)
    173     add_test(test_sg2d_some_segments test_sg2d_some_segments)
    174     add_test(test_sg2d_unspecified_properties test_sg2d_unspecified_properties)
    175   endif()
    176 
    177   if(HUGE_ADDITIONAL_TESTS)
    178     add_test(test_sg2d_many_enclosures test_sg2d_many_enclosures)
    179     add_test(test_sg2d_many_segments test_sg2d_many_segments)
    180   endif()
    181 
    182 endif()
    183 
    184 ################################################################################
    185 # Define output & install directories
    186 ################################################################################
    187 install(TARGETS sg2d
    188   ARCHIVE DESTINATION bin
    189   LIBRARY DESTINATION lib
    190   RUNTIME DESTINATION bin)
    191 install(FILES ${SG2D_FILES_INC_API} DESTINATION include/star)
    192 install(FILES ${SG2D_FILES_DOC} DESTINATION share/doc/star-geometry-2d)