forked from jturney/levmar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
95 lines (80 loc) · 3.18 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
cmake_minimum_required(VERSION 3.0)
project(levmar VERSION 2.6 LANGUAGES C)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
################################### Options ####################################
include(Psi4Macros)
option_with_default(CMAKE_BUILD_TYPE "Build type" Release)
option_with_print(BUILD_SHARED_LIBS "Build final library as shared, not static" OFF)
option_with_default(BUILD_FPIC "Libraries will be compiled with position independent code" ON)
if(${BUILD_SHARED_LIBS} AND NOT ${BUILD_FPIC})
message(FATAL_ERROR "BUILD_SHARED_LIBS ON and BUILD_FPIC OFF are incompatible, as shared library requires position independent code")
endif()
option_with_print(ENABLE_GENERIC "Enable mostly static linking in shared library" OFF)
option_with_flags(ENABLE_XHOST "Enable processor-specific optimization" ON
"-xHost" "-march=native")
######################### Process & Validate Options ###########################
include(autocmake_safeguards)
include(autocmake_static_library)
################################# Main Project #################################
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
set(PN ${PROJECT_NAME})
set(LM_DBL_PREC 1)
set(HAVE_LAPACK 1)
# For add_library STATIC/SHARED is governed by BUILD_SHARED_LIBS
add_library(levmar
src/lm.c
src/Axb.c
src/misc.c
src/lmlec.c
src/lmbc.c
src/lmblec.c
src/lmbleic.c
src/misc.h
src/compiler.h
)
configure_file(
${CMAKE_SOURCE_DIR}/src/levmar.h.in
${CMAKE_BINARY_DIR}/src/levmar.h
)
include_directories(
${CMAKE_SOURCE_DIR}/src
${CMAKE_BINARY_DIR}/src
)
set_target_properties(levmar PROPERTIES POSITION_INDEPENDENT_CODE ${BUILD_FPIC})
if (${BUILD_SHARED_LIBS})
target_link_libraries(levmar PRIVATE ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${LIBC_INTERJECT})
endif()
# <<< Install >>>
install(FILES
${CMAKE_BINARY_DIR}/src/levmar.h
DESTINATION
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/levmar
)
install(TARGETS
levmar
EXPORT
"${PN}Targets"
ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
)
# <<< Export Interface >>>
target_compile_definitions(levmar INTERFACE USING_${PN})
target_include_directories(levmar INTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# <<< Export Config >>>
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/cmake/${PN}")
configure_package_config_file(${PN}Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR})
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
VERSION ${${PN}_VERSION}
COMPATIBILITY SameMajorVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PN}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PN}ConfigVersion.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
install(EXPORT "${PN}Targets"
NAMESPACE "${PN}::"
DESTINATION ${CMAKECONFIG_INSTALL_DIR})