-
Notifications
You must be signed in to change notification settings - Fork 66
/
CMakeLists.txt
134 lines (105 loc) · 4.56 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(cadmesh)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 ")
set(CADMESH_MAJOR_VERSION 2)
set(CADMESH_MINOR_VERSION 0)
set(CADMESH_PATCH_VERSION 0)
set(CADMESH_VERSION ${CADMESH_MAJOR_VERSION}.${CADMESH_MINOR_VERSION}.${CADMESH_PATCH_VERSION})
include(FindPkgConfig)
include(ExternalProject)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
# Make the include and lib directories in the build area.
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# GEANT4
option(WITH_GEANT4_UIVIS "Build with Geant4 UI and VIS drivers" ON)
if(WITH_GEANT4_UIVIS)
find_package(Geant4 REQUIRED ui_all vis_all)
else()
find_package(Geant4 REQUIRED)
endif()
include(${Geant4_USE_FILE})
# X11 if on a Mac
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(OPENGL_INCLUDE_DIR_MAC /var/empty/X11/include )
include_directories(${OPENGL_INCLUDE_DIR_MAC})
set(OPENGL_INCLUDE_DIR /var/empty/include )
include_directories(${OPENGL_INCLUDE_DIR})
endif()
# Tetgen
option(WITH_SYS_TETGEN "WITH_TETGEN" OFF)
if(${WITH_SYS_TETGEN} MATCHES "ON")
find_package(tetgen)
endif()
# Open Asset Importer Library
option(WITH_SYS_ASSIMP "WITH_ASSIMP" OFF)
if(${WITH_SYS_ASSIMP} MATCHES "ON")
find_package(assimp)
endif()
# Catch unit testing library
option(WITH_TESTS "WITH_TESTS" OFF)
if(${WITH_TESTS} MATCHES "ON")
ExternalProject_Add(
catch_external
SOURCE_DIR ${PROJECT_SOURCE_DIR}/external/catch
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.11.3
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR} -DNO_SELFTEST=ON
)
include_directories(${PROJECT_BINARY_DIR}/include/catch)
endif()
# CADMesh
set(DEFAULT_READER "BuiltIn" CACHE STRING "The CAD file reader to use by default.")
configure_file(${PROJECT_SOURCE_DIR}/include/Configuration.hh.in "${CMAKE_CURRENT_BINARY_DIR}/include/Configuration.hh" @ONLY)
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${CMAKE_INSTALL_PREFIX}/include)
include_directories(${PROJECT_BINARY_DIR}/include)
# Set up the target.
add_library(cadmesh "SHARED" ${sources} ${headers})
# Link against either the system libraries, or the external project libaries.
if(${WITH_SYS_TETGEN} MATCHES "OFF")
target_link_libraries(cadmesh tet)
endif()
if(${WITH_SYS_ASSIMP} MATCHES "OFF")
target_link_libraries(cadmesh assimp)
endif()
target_link_libraries(cadmesh ${Geant4_LIBRARIES})
# Build the examples as well.
if(${WITH_EXAMPLES} MATCHES "ON")
add_subdirectory(${PROJECT_SOURCE_DIR}/examples/basic)
add_subdirectory(${PROJECT_SOURCE_DIR}/examples/template)
endif()
# Configure the installation.
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/cadmesh-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cadmesh-config.cmake" @ONLY IMMEDIATE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cadmesh-config.cmake" DESTINATION "lib/cmake/cadmesh-${CADMESH_MAJOR_VERSION}.${CADMESH_MINOR_VERSION}.${CADMESH_PATCH_VERSION}")
# Install the CADMesh headers and library.
install(FILES ${PROJECT_SOURCE_DIR}/include/CADMesh.hh DESTINATION include)
install(FILES ${PROJECT_BINARY_DIR}/include/Configuration.hh DESTINATION include)
install(TARGETS cadmesh DESTINATION lib)
# Set CPack to build an archive.
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_NAME "cadmesh")
set(CPACK_PACKAGE_VERSION ${CADMESH_VERSION})
set(CPACK_PACKAGE_VERSION_MAJOR ${CADMESH_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${CADMESH_MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${CADMESH_PATCH_VERSION})
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
include(CPack)
# Tests
if(${WITH_TESTS} MATCHES "ON")
enable_testing()
add_executable(CADMeshTests tests/CADMeshTests.cc)
add_dependencies(CADMeshTests catch_external)
target_link_libraries(CADMeshTests cadmesh)
add_test(NAME CADMeshTests COMMAND CADMeshTests)
add_executable(ValidTessellatedMeshTests tests/ValidTessellatedMeshTests.cc)
add_dependencies(ValidTessellatedMeshTests catch_external)
target_link_libraries(ValidTessellatedMeshTests cadmesh)
add_test(NAME ValidTessellatedMeshTests COMMAND ValidTessellatedMeshTests)
add_executable(InvalidTessellatedMeshTests tests/InvalidTessellatedMeshTests.cc)
add_dependencies(InvalidTessellatedMeshTests catch_external)
target_link_libraries(InvalidTessellatedMeshTests cadmesh)
add_test(NAME InvalidTessellatedMeshTests COMMAND InvalidTessellatedMeshTests)
endif()