forked from IOHprofiler/IOHexperimenter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
148 lines (114 loc) · 3.95 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
## Build the ioh library.
##
cmake_minimum_required(VERSION 3.12)
project(ioh
VERSION 0.0.0.1
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 17)
set(EXTERNAL_DIR "${PROJECT_SOURCE_DIR}/external")
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
option(BUILD_PYTHON_PACKAGE "Whether to build Python package" OFF)
option(BUILD_TESTS "Whether to build test cases with gtest" ON)
option(BUILD_EXAMPLE "Whether to build Python package" ON)
option(BUILD_DOCS "Build docs" OFF)
option(ENABLE_PYTHON_PROBLEMS "Enable the ability to call external Python modules as if they were an IOH problem" OFF)
if(MSVC)
set(ENABLE_PYTHON_PROBLEMS FALSE) # The call-problem-from-python interface is broken on windows
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT /02")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd ")
endif()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++17 -lstdc++fs")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math")
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 6.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
link_libraries(stdc++fs)
add_compile_definitions(FSEXPERIMENTAL)
endif()
endif()
# Define project targets.
file(GLOB_RECURSE HEADERS include/ioh *.hpp)
# Exlude python problems if not enabled
if(NOT ENABLE_PYTHON_PROBLEMS)
list(FILTER HEADERS EXCLUDE REGEX "include/ioh/problem/python/*")
endif()
add_library(ioh INTERFACE)
add_library(ioh::ioh ALIAS ioh)
#Include external formatting lib
add_subdirectory(${EXTERNAL_DIR}/fmt)
target_link_libraries(ioh INTERFACE fmt::fmt-header-only)
# Add Python Library
if(ENABLE_PYTHON_PROBLEMS)
find_package(PythonLibs REQUIRED)
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(ioh INTERFACE ${PYTHON_LIBRARIES})
add_compile_definitions(PYTHON_DEFINED)
endif()
target_include_directories(ioh
INTERFACE
# Interface paths are relative to the installation path, not the current directory.
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
target_compile_features(ioh
INTERFACE
cxx_std_17
)
# Generate package config files.
include(CMakePackageConfigHelpers)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/ioh-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/ioh-config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/ioh
)
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/ioh-config-version.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
# Define installation rules.
include(GNUInstallDirs)
install(TARGETS ioh fmt-header-only
EXPORT ioh-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/ioh-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/ioh-config-version.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/ioh
)
install(EXPORT ioh-targets
FILE ioh-targets.cmake
NAMESPACE ioh::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ioh
)
# Export targets. If an external project adds this project to its build tree
# via `add_subdirectory()`, then `find_package()` will work without
# requiring this project to be installed.
export(EXPORT ioh-targets
FILE ${CMAKE_CURRENT_BINARY_DIR}/ioh-targets.cmake
NAMESPACE ioh::
)
export(PACKAGE ioh)
# Add subdirectories to build.
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
if(BUILD_EXAMPLE)
add_subdirectory(example)
endif()
if(BUILD_DOCS)
add_subdirectory(doc)
endif()
if(BUILD_PYTHON_PACKAGE)
add_subdirectory(ioh)
endif()