-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
137 lines (105 loc) · 4.28 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
134
135
136
137
# CMakeLists.txt - CMake configuration file for EPANET 2.0
#
# CMake is a cross-platform build tool. CMake generates platform native
# build systems that can be used with your compiler of choice. CMake uses a
# generator concept to represent different build tooling. CMake automatically
# detects the platform it is running on and generates the appropriate makefiles
# for the platform default compiler. Different generators can also be specified.
#
# Note: CMake requires that your platform build system and compiler are
# properly installed. Build using Visual Studio requires msbuild shell.
#
# Build Options:
# BUILD_TESTS = ON/OFF
# BUILD_PY_LIB = ON/OFF
#
# Generic Invocation:
# cmake -E make_directory buildprod
# cd build
# cmake -G GENERATOR -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON ..
# cmake --build . --target SOME_TARGET --config Release
#
# More information:
# cmake --help
#
# CMake is available at https://cmake.org/download/
#
cmake_minimum_required (VERSION 2.8.8)
project(EPANET)
# Append local dir to module search path
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
option(BUILD_TESTS "Build tests (requires Boost)" OFF)
option(BUILD_PY_LIB "Build library for Python wrapper" OFF)
option(BUILD_COVERAGE "Build library for coverage" OFF)
IF (NOT BUILD_PY_LIB)
add_subdirectory(run)
ENDIF (NOT BUILD_PY_LIB)
add_subdirectory(src/outfile)
IF (BUILD_TESTS)
#Prep ourselves for compiling with boost
IF(WIN32)
set(Boost_USE_STATIC_LIBS ON)
ELSE(TRUE)
set(Boost_USE_STATIC_LIBS OFF)
add_definitions(-DBOOST_ALL_DYN_LINK)
ENDIF(WIN32)
find_package(Boost COMPONENTS unit_test_framework system thread filesystem)
include_directories (${Boost_INCLUDE_DIRS})
enable_testing()
add_subdirectory(tests)
add_subdirectory(tests/outfile)
add_subdirectory(tests/util)
ENDIF (BUILD_TESTS)
# Sets for output directory for executables and libraries.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# Sets the position independent code property for all targets
SET(CMAKE_POSITION_INDEPENDENT_CODE ON)
IF (APPLE)
set(INSTALL_NAME_DIR @executable_path/../lib)
set(CMAKE_MACOSX_RPATH 1)
ENDIF (APPLE)
IF (MSVC)
set(CMAKE_C_FLAGS_RELEASE "/GL")
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
ENDIF (MSVC)
# configure file groups
file(GLOB EPANET_SOURCES RELATIVE ${PROJECT_SOURCE_DIR} src/*.c src/util/*.c)
file(GLOB EPANET_LIB_ALL RELATIVE ${PROJECT_SOURCE_DIR} src/* src/util/*)
# exclude epanet python API from the default build
list(REMOVE_ITEM EPANET_LIB_ALL "src/epanet_py.c")
source_group("Library" FILES ${EPANET_LIB_ALL})
# create build target for epanet library with python API
IF (BUILD_PY_LIB)
# exclude legacy epanet 2.0 API and include epanet py API
list(REMOVE_ITEM EPANET_LIB_ALL "src/epanet2.c")
add_library(epanet_py SHARED ${EPANET_LIB_ALL} src/epanet_py.c src/util/errormanager.c)
target_include_directories(epanet_py PUBLIC ${PROJECT_SOURCE_DIR}/include)
include(GenerateExportHeader)
GENERATE_EXPORT_HEADER(epanet_py
BASE_NAME epanet_py
EXPORT_MACRO_NAME EXPORT_PY_API
EXPORT_FILE_NAME epanet_py_export.h
STATIC_DEFINE SHARED_EXPORTS_BUILT_AS_STATIC)
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/epanet_py_export.h
DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include)
# create build target for code coverage
ELSEIF (BUILD_COVERAGE)
include(CodeCoverage)
set(CMAKE_BUILD_TYPE "Debug")
APPEND_COVERAGE_COMPILER_FLAGS()
set(CMAKE_C_FLAGS_DEBUG "-O0")
add_library(epanet2 SHARED ${EPANET_LIB_ALL})
target_include_directories(epanet2 PUBLIC ${PROJECT_SOURCE_DIR}/include)
# create build target for default epanet library with 2.0 and 2.2 API
ELSE (BUILD_PY_LIB)
# the shared library
IF("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)" OR NOT MSVC)
add_library(epanet2 SHARED ${EPANET_LIB_ALL})
ELSE(TRUE)
add_library(epanet2 SHARED ${EPANET_LIB_ALL} ${PROJECT_SOURCE_DIR}/include/epanet2.def)
set_source_files_properties(${PROJECT_SOURCE_DIR}/include/epanet2.def PROPERTIES_HEADER_FILE_ONLY TRUE)
ENDIF("${CMAKE_GENERATOR}" MATCHES "(Win64|IA64)" OR NOT MSVC)
target_include_directories(epanet2 PUBLIC ${PROJECT_SOURCE_DIR}/include)
ENDIF (BUILD_PY_LIB)