-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
167 lines (152 loc) · 4.2 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
cmake_minimum_required(VERSION 3.16)
project(GAlib VERSION 2.4.7 LANGUAGES CXX)
include(GNUInstallDirs)
# Check if this is the top-level project (standalone), or a subproject
set(_galib_standalone FALSE)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(_galib_standalone TRUE)
endif()
#
# Options
#
# GALIB_BUILD_SHARED controls if GAlib libraries are built as shared or
# static
#
# It defaults to the value of BUILD_SHARED_LIBS if set, and in most cases
# that should be used instead. The purpose of GALIB_BUILD_SHARED is to allow
# overriding it when built as a subproject. For static libraries with position
# independent code, set CMAKE_POSITION_INDEPENDENT_CODE to True.
set(_galib_shared_default OFF)
if(DEFINED BUILD_SHARED_LIBS)
set(_galib_shared_default ${BUILD_SHARED_LIBS})
endif()
option(GALIB_BUILD_SHARED "Build shared libraries" ${_galib_shared_default})
unset(_galib_shared_default)
if(GALIB_BUILD_SHARED)
set(_galib_library_type SHARED)
else()
set(_galib_library_type STATIC)
endif()
# GALIB_BUILD_INSTALL controls if GAlib adds install support
#
# When built standalone or as a shared library subproject, the default is ON,
# and for static library subproject the default is OFF.
if(_galib_standalone OR GALIB_BUILD_SHARED)
option(GALIB_BUILD_INSTALL "Add install support" ON)
else()
option(GALIB_BUILD_INSTALL "Add install support" OFF)
endif()
#
# galib
#
add_library(galib ${_galib_library_type}
ga/GA1DArrayGenome.C
ga/GA1DBinStrGenome.C
ga/GA2DArrayGenome.C
ga/GA2DBinStrGenome.C
ga/GA3DArrayGenome.C
ga/GA3DBinStrGenome.C
ga/GABaseGA.C
ga/GABin2DecGenome.C
ga/gabincvt.C
ga/GABinStr.C
ga/GADCrowdingGA.C
ga/GADemeGA.C
ga/gaerror.C
ga/GAGenome.C
ga/GAIncGA.C
ga/GAList.C
ga/GAListBASE.C
ga/GAListGenome.C
ga/GAParameter.C
ga/GAPopulation.C
ga/garandom.C
ga/GARealGenome.C
ga/GAScaling.C
ga/GASelector.C
ga/GASimpleGA.C
ga/GASStateGA.C
ga/GAStatistics.C
ga/GAStringGenome.C
ga/GATree.C
ga/GATreeBASE.C
ga/GATreeGenome.C
ga/GAAllele.C
)
target_include_directories(galib
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
set_target_properties(galib PROPERTIES
EXPORT_NAME GAlib
VERSION ${GAlib_VERSION}
SOVERSION ${GAlib_VERSION_MAJOR}
)
if(MSVC AND GALIB_BUILD_SHARED)
# The defines below for compiling and using as a DLL are described in
# gaconfig.h, but do not seem to be implemented yet. So we use this
# brute-force approach to generate an import library.
set_target_properties(galib PROPERTIES
WINDOWS_EXPORT_ALL_SYMBOLS ON
)
target_compile_definitions(galib
PRIVATE COMPILE_GALIB_AS_DLL
PUBLIC USE_GALIB_AS_DLL
)
endif()
if(MSVC)
target_compile_definitions(galib PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
# Create alias
#
# Makes targets available to projects using GAlib as a subproject using the
# same names as in the config file package.
add_library(GAlib::GAlib ALIAS galib)
#
# Install
#
if(GALIB_BUILD_INSTALL)
install(TARGETS galib
EXPORT galib_targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY ga
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN *.h
)
install(FILES
ga/GA1DArrayGenome.C
ga/GA2DArrayGenome.C
ga/GA3DArrayGenome.C
ga/GAList.C
ga/GAListGenome.C
ga/GARealGenome.C
ga/GAStringGenome.C
ga/GATree.C
ga/GATreeGenome.C
ga/GAAllele.C
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ga
)
# Install config file package
#
# This allows CMake based projects to use the installed libraries with
# find_package(GAlib).
include(CMakePackageConfigHelpers)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/GAlibConfigVersion.cmake
VERSION ${GAlib_VERSION}
COMPATIBILITY SameMajorVersion
)
# Since we have no dependencies, use export file directly as config file
install(EXPORT galib_targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/GAlib
NAMESPACE GAlib::
FILE GAlibConfig.cmake
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/GAlibConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/GAlib
)
endif()