-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
114 lines (86 loc) · 3.86 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
cmake_minimum_required(VERSION 3.12)
project(libmsym C)
option(MSYM_BUILD_EXAMPLES "Build example executables" OFF)
option(MSYM_BUILD_PYTHON "Build python binding" OFF)
include (GenerateExportHeader)
set(LIBMSYM_MAJOR_VERSION 0)
set(LIBMSYM_MINOR_VERSION 2)
set(LIBMSYM_PATCH_VERSION 4)
set(LIBMSYM_VERSION ${LIBMSYM_MAJOR_VERSION}.${LIBMSYM_MINOR_VERSION}.${LIBMSYM_PATCH_VERSION})
set(INSTALL_LIB_DIR lib CACHE PATH "Installation directory for msym library")
set(INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
if(WIN32 AND NOT CYGWIN)
set(DEF_INSTALL_CMAKE_DIR CMake)
else()
set(DEF_INSTALL_CMAKE_DIR lib/cmake/libmsym)
endif()
set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
foreach(p LIB BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
include_directories("${PROJECT_SOURCE_DIR}")
file (GLOB source src/*.c)
add_library (msym ${source})
if (BUILD_SHARED_LIBS)
set_target_properties(msym PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
C_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1)
else()
set_target_properties(msym PROPERTIES COMPILE_FLAGS -DMSYM_EXPORTS_BUILT_AS_STATIC)
endif ()
include_directories("${PROJECT_BINARY_DIR}")
set_target_properties(msym PROPERTIES VERSION ${LIBMSYM_VERSION})
set_target_properties(msym PROPERTIES SOVERSION ${LIBMSYM_MAJOR_VERSION}.${LIBMSYM_MINOR_VERSION})
generate_export_header(msym
BASE_NAME msym
EXPORT_MACRO_NAME MSYM_EXPORT
EXPORT_FILE_NAME msym_EXPORTS.h
STATIC_DEFINE MSYM_EXPORTS_BUILT_AS_STATIC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
#set_target_properties (msym PROPERTIES
# C_STANDARD 99
# C_STANDARD_REQUIRED ON)
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -flto")
#set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto" )
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fsanitize=address -fno-omit-frame-pointer")
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -DLIBMSYM_DEBUG")
set_target_properties(msym PROPERTIES PUBLIC_HEADER "src/msym.h;src/msym_error.h")
if(UNIX)
target_link_libraries(msym m)
endif(UNIX)
export(TARGETS msym FILE "${PROJECT_BINARY_DIR}/libmsymTargets.cmake")
export(PACKAGE libmsym)
file(RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
set(CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}" "${PROJECT_BINARY_DIR}")
configure_file(libmsymConfig.cmake.in "${PROJECT_BINARY_DIR}/libmsymConfig.cmake" @ONLY)
set(CONF_INCLUDE_DIRS "\${LIBMSYM_CMAKE_DIR}/${REL_INCLUDE_DIR}")
configure_file(libmsymConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libmsymConfig.cmake" @ONLY)
configure_file(libmsymConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/libmsymConfigVersion.cmake" @ONLY)
install(FILES
"${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/libmsymConfig.cmake"
"${PROJECT_BINARY_DIR}/libmsymConfigVersion.cmake"
DESTINATION "${INSTALL_CMAKE_DIR}")
# EXPORT HEADER
install(FILES "${PROJECT_BINARY_DIR}/msym_EXPORTS.h" DESTINATION "${INSTALL_INCLUDE_DIR}/libmsym")
install(TARGETS msym
EXPORT libmsymTargets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/libmsym"
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" )
install(EXPORT libmsymTargets DESTINATION "${INSTALL_CMAKE_DIR}")
if(MSYM_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(MSYM_BUILD_PYTHON)
if(BUILD_SHARED_LIBS)
add_subdirectory(bindings/python)
else()
message(SEND_ERROR "python requires libmsym to be built as a shared library, use -DBUILD_SHARED_LIBS:BOOL=ON")
endif()
endif()