-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathCMakeLists.txt
130 lines (99 loc) · 3.97 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
cmake_minimum_required(VERSION 3.15)
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" projectVersion)
project("proxyfmu" VERSION ${projectVersion})
message("Current ${PROJECT_NAME} version: ${CMAKE_PROJECT_VERSION}\n")
# ==============================================================================
# Build settings
# ==============================================================================
option(BUILD_SHARED_LIBS "Build shared libraries instead of static libraries" ON)
option(PROXYFMU_BUILD_TESTS "Build tests" OFF)
option(PROXYFMU_BUILD_EXAMPLES "Build examples" OFF)
# ==============================================================================
# Global internal configuration
# ==============================================================================
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(Boost_NO_WARN_NEW_VERSIONS ON)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(generatedSourcesDir "${CMAKE_BINARY_DIR}/generated")
if (MSVC)
add_definitions("-D_WIN32_WINNT=0x600" "-D_CRT_SECURE_NO_WARNINGS")
add_compile_options("/wd4996" "/wd4251" "/wd4244" "/wd4267")
endif ()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()
# Prepare for export and installation.
set(PROXYFMU_HEADER_INSTALL_DIR "include")
if (WIN32)
set(PROXYFMU_CMAKE_INSTALL_DIR "cmake")
else ()
set(PROXYFMU_CMAKE_INSTALL_DIR "share/${PROJECT_NAME}/cmake")
endif ()
set(PROXYFMU_INSTALL_DESTINATIONS
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${PROXYFMU_HEADER_INSTALL_DIR}")
set(PROXYFMU_EXPORT_TARGET "${PROJECT_NAME}-targets")
# ==============================================================================
# Dependencies
# ==============================================================================
set(BOOST_COMPONENTS filesystem)
if (PROXYFMU_BUILD_TESTS)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.8
)
FetchContent_MakeAvailable(Catch2)
endif ()
find_package(Boost 1.71 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
find_package(CLI11 REQUIRED)
find_package(Thrift REQUIRED)
find_package(FMILIB MODULE REQUIRED)
# ==============================================================================
# Targets
# ==============================================================================
add_subdirectory(src)
add_subdirectory(tool)
if (PROXYFMU_BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
if (PROXYFMU_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif ()
# ==============================================================================
# Exports and remaining installation
# ==============================================================================
install(
EXPORT "${PROXYFMU_EXPORT_TARGET}"
DESTINATION "${PROXYFMU_CMAKE_INSTALL_DIR}"
NAMESPACE "${PROJECT_NAME}::"
)
include(CMakePackageConfigHelpers)
# Generate and install package-config file.
set(configFile "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-config.cmake")
set(targetsFile "${PROXYFMU_CMAKE_INSTALL_DIR}/${PROXYFMU_EXPORT_TARGET}.cmake")
configure_package_config_file(
"${CMAKE_SOURCE_DIR}/cmake/project-config.cmake.in"
"${configFile}"
INSTALL_DESTINATION "${PROXYFMU_CMAKE_INSTALL_DIR}"
PATH_VARS targetsFile
)
install(FILES "${configFile}" DESTINATION "${PROXYFMU_CMAKE_INSTALL_DIR}")
# Generate and install package-version file
set(versionFile "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake")
write_basic_package_version_file(
"${versionFile}"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY "SameMajorVersion")
install(FILES "${versionFile}" DESTINATION "${PROXYFMU_CMAKE_INSTALL_DIR}")
# Install custom find modules
install(FILES
"${CMAKE_SOURCE_DIR}/cmake/FindFMILIB.cmake"
DESTINATION
"${PROXYFMU_CMAKE_INSTALL_DIR}"
)