-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
121 lines (100 loc) · 3.44 KB
/
Copy pathCMakeLists.txt
File metadata and controls
121 lines (100 loc) · 3.44 KB
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
cmake_minimum_required(VERSION 3.2)
project("Vectorpack" CXX)
set(exec_name "vectorpack")
set(lib_name "Vectorpack")
######### TODO ##########
# set the library extension and make the executable/library usable in Windows
#########################
# Set default install path in build directory if not specified by the user
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "install prefix" FORCE)
message("Setting default install path to ${CMAKE_INSTALL_PREFIX}. Add cmake option `-DCMAKE_INSTALL_PREFIX=/your/install/path` to manually set it")
endif()
message("Install prefix: ${CMAKE_INSTALL_PREFIX}")
# Enable C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Build options
option(include_algorithms "Include packing algorithms in the vectorpack library" ON)
option(build_executable "Build the vectorpack executable" OFF)
# Algorithms are required in the executable
if (build_executable AND NOT include_algorithms)
message("Forcing 'include_algorithms' to ON to build the executable")
set(include_algorithms ON)
endif()
if (include_algorithms)
message("Packing algorithms will be included in the Vectorpack library")
endif()
if (build_executable)
message("Only the executable will be built. The Vectorpack library will NOT be installed")
endif()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Get the vectorpack lib
set(HEADER_LIB
src/lib/bin.hpp
src/lib/item.hpp
src/lib/instance.hpp
)
set(SOURCE_LIB
src/lib/bin.cpp
src/lib/item.cpp
src/lib/instance.cpp
)
if (include_algorithms)
set(SOURCE_ALGOS
src/algos/weights_measures_scores.cpp
src/algos/base_algo.cpp
src/algos/algos_ItemCentric.cpp
src/algos/algos_BinCentric.cpp
src/algos/algos_MultiBin.cpp
src/algos/lower_bounds.cpp
src/algos/algo_utils.cpp
)
set(HEADER_ALGOS
# TODO hide some header files?
src/algos/weights_measures_scores.hpp
src/algos/base_algo.hpp
src/algos/algos_ItemCentric.hpp
src/algos/algos_BinCentric.hpp
src/algos/algos_MultiBin.hpp
src/algos/lower_bounds.hpp
src/algos/algo_utils.hpp
)
endif()
add_library(${lib_name} STATIC
${HEADER_LIB}
${SOURCE_LIB}
${HEADER_ALGOS}
${SOURCE_ALGOS}
)
target_include_directories(${lib_name}
PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/lib>
PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src/algos># TODO hide some header files?
PUBLIC $<INSTALL_INTERFACE:lib>
PUBLIC $<INSTALL_INTERFACE:include/${PROJECT_NAME}>
)
set_target_properties(${lib_name} PROPERTIES PUBLIC_HEADER "${HEADER_LIB};${HEADER_ALGOS}")
### if build executable
if (build_executable)
add_executable(${exec_name} src/main_vectorpack.cpp)
target_link_libraries(${exec_name}
PRIVATE ${lib_name}
)
endif()
###
# Install rule
### Depending whether only executable should be installed
### or the Vectorpack library only
if (build_executable)
# Install only the executable
install(TARGETS ${exec_name} RUNTIME DESTINATION bin)
else()
# Else, install the Vectorpack library
install(TARGETS ${lib_name}
EXPORT ${lib_name}Config
LIBRARY DESTINATION lib
PUBLIC_HEADER DESTINATION include/${PROJECT_NAME}
)
install(EXPORT ${lib_name}Config DESTINATION lib/cmake/${PROJECT_NAME})
endif()