This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCMakeLists.txt
133 lines (98 loc) · 4.93 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
# Copyright (C) 2018 Fondazione Istituto Italiano di Tecnologia
#
# Licensed under either the GNU Lesser General Public License v3.0 :
# https://www.gnu.org/licenses/lgpl-3.0.html
# or the GNU Lesser General Public License v2.1 :
# https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
# at your option.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
cmake_minimum_required(VERSION 2.8)
project(ALGLIB CXX)
set(libraryname ALGLIB)
include(AddWarningsConfigurationToTargets)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# ouptut paths
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
# Build shared libs
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
if(MSVC)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
option(BUILD_SHARED_LIBS "Build libraries as shared as opposed to static" ON)
option(ENABLE_RPATH "Enable RPATH for this library" ON)
mark_as_advanced(ENABLE_RPATH)
include(AddInstallRPATHSupport)
add_install_rpath_support(BIN_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}"
LIB_DIRS "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
DEPENDS ENABLE_RPATH
USE_LINK_PATH)
# Encourage user to specify a build type (e.g. Release, Debug, etc.), otherwise set it to Release.
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Setting build type to 'Release' as none was specified.")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY VALUE "Release")
endif()
endif()
include(ExternalProject)
set(ALGLIB_VERSION_FILE "3.14.0" CACHE STRING "Version of ALGLIB.")
string(REPLACE "\"" "" ALGLIB_VERSION ${ALGLIB_VERSION_FILE})
set(ALGLIB_FILE alglib-${ALGLIB_VERSION_FILE}.cpp.gpl.tgz)
set(ALGLIB_URI http://www.alglib.net/translator/re/${ALGLIB_FILE})
set(ALGLIB_DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR})
set(ALGLIB_FULL_PATH ${ALGLIB_DOWNLOAD_DIR}/${ALGLIB_FILE})
if (NOT EXISTS ${ALGLIB_FULL_PATH})
file(DOWNLOAD ${ALGLIB_URI} ${ALGLIB_FULL_PATH} SHOW_PROGRESS STATUS DL_STATUS)
list(GET DL_STATUS 0 status_code)
if (NOT status_code EQUAL 0)
message(FATAL_ERROR "Error while downloading '${ALGLIB_URI}'.")
endif()
endif()
set (UNZIP_DIR "${ALGLIB_DOWNLOAD_DIR}/src")
file(REMOVE_RECURSE ${UNZIP_DIR})
file(MAKE_DIRECTORY ${UNZIP_DIR})
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xfz ${ALGLIB_FULL_PATH} WORKING_DIRECTORY "${ALGLIB_DOWNLOAD_DIR}/src" RESULT_VARIABLE rv)
if(NOT rv EQUAL 0)
message(FATAL_ERROR "Error while extracting '${ALGLIB_FULL_PATH}'.")
endif()
file(GLOB ALGLIB_HEADERS "${UNZIP_DIR}/cpp/src/*.h")
file(GLOB ALGLIB_SOURCES "${UNZIP_DIR}/cpp/src/*.cpp")
add_library(${libraryname} ${ALGLIB_HEADERS} ${ALGLIB_SOURCES})
set_property(TARGET ${libraryname} PROPERTY POSITION_INDEPENDENT_CODE ON)
set(COMPILER_OPTIONS)
if(MSVC OR MSYS OR MINGW)
set(COMPILER_OPTIONS ${COMPILER_OPTIONS} /Ox /DAE_OS=AE_WINDOWS)
execute_process( COMMAND wmic CPU get Name OUTPUT_VARIABLE CPU_NAME)
if (${CPU_NAME} MATCHES "Intel")
set(COMPILER_OPTIONS ${COMPILER_OPTIONS} /DAE_CPU=AE_INTEL)
endif()
elseif(UNIX)
set(COMPILER_OPTIONS ${COMPILER_OPTIONS} -O3 -DAE_OS=AE_POSIX -pthread)
execute_process( COMMAND uname -m OUTPUT_VARIABLE ARCHITECTURE)
if (${ARCHITECTURE} MATCHES "x86_64")
set(COMPILER_OPTIONS ${COMPILER_OPTIONS} -DAE_CPU=AE_INTEL)
endif()
endif()
target_compile_options(${libraryname} PUBLIC ${COMPILER_OPTIONS})
# install
set_target_properties(${libraryname} PROPERTIES VERSION ${ALGLIB_VERSION}
PUBLIC_HEADER "${ALGLIB_HEADERS}")
target_include_directories(${libraryname} PUBLIC "$<BUILD_INTERFACE:${UNZIP_DIR}/cpp/src>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
install(TARGETS ${libraryname}
EXPORT ${libraryname}
COMPONENT runtime
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT bin
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT shlib
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" COMPONENT lib
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT ${libraryname}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${libraryname})
configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/ALGLIB-config.cmake.in
${CMAKE_BINARY_DIR}/alglib-config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ALGLIB)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/alglib-configVersion.cmake VERSION ${ALGLIB_VERSION} COMPATIBILITY ExactVersion)
install(FILES ${CMAKE_BINARY_DIR}/alglib-config.cmake ${CMAKE_BINARY_DIR}/alglib-configVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ALGLIB)
include(AddUninstallTarget)