1
1
cmake_minimum_required (VERSION 3.18 )
2
2
3
- project (iniparser VERSION 4.2.4 )
3
+ project (
4
+ iniparser
5
+ DESCRIPTION "C library for parsing INI-style files"
6
+ HOMEPAGE_URL https://gitlab.com/iniparser/iniparser/
7
+ LANGUAGES C
8
+ VERSION 4.2.5 )
4
9
5
10
include (GNUInstallDirs )
6
11
include (CMakePackageConfigHelpers )
7
12
include (CMakeDependentOption )
8
13
9
- set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
10
- "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
14
+ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
11
15
12
16
option (
13
17
BUILD_SHARED_LIBS
14
18
"Build using shared libraries"
15
19
ON )
16
- # For packaging by tools like bitbake, shared and static libs should be build
17
- # at once
18
- CMAKE_DEPENDENT_OPTION (BUILD_STATIC_LIBS "Build static libs" ON
19
- "BUILD_SHARED_LIBS" OFF )
20
+ # For packaging by tools like bitbake, shared and static libs should be build at
21
+ # once
22
+ cmake_dependent_option (
23
+ BUILD_STATIC_LIBS
24
+ "Build static libs"
25
+ ON
26
+ "BUILD_SHARED_LIBS"
27
+ OFF )
20
28
if (BUILD_SHARED_LIBS )
21
29
list (
22
30
APPEND
@@ -46,12 +54,47 @@ foreach(TARGET_TYPE ${TARGET_TYPES})
46
54
set (PUBLIC_HEADERS "src/iniparser.h" "src/dictionary.h" )
47
55
set_target_properties (${TARGET_NAME} PROPERTIES PUBLIC_HEADER
48
56
"${PUBLIC_HEADERS} " )
49
-
50
57
target_include_directories (
51
58
${TARGET_NAME}
52
59
PUBLIC $< BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /src>
53
60
$< INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} /${PROJECT_NAME} > )
54
- set_target_properties (${TARGET_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} )
61
+ # If both shared and static libs are build at once with MSVC it generates a
62
+ # shared library consisting of
63
+ #
64
+ # * a DLL (that contains the actual code) with filename suffix `.dll`,
65
+ # * a correspoding import library (against which users should link) with
66
+ # filename suffix `.lib`.
67
+ #
68
+ # and a static library with filename suffix `.lib`
69
+ #
70
+ # As both, the shared import library and the static library share the same
71
+ # basename and suffix one would overwrite the other.
72
+ #
73
+ # To solve this issue we set the PREFIX for *static* libs explicitely so MSVC
74
+ # will build:
75
+ #
76
+ # * shared: iniparser.dll
77
+ # * import: iniparser.lib
78
+ # * static: libiniparser.lib
79
+ #
80
+ # As all other platforms already set `PREFIX` for all lib types they remain
81
+ # unchanged. Therefore no `if(MSVC)` check is needed here.
82
+ #
83
+ if (TARGET_TYPE
84
+ MATCHES
85
+ "static" )
86
+ set_target_properties (${TARGET_NAME}
87
+ PROPERTIES OUTPUT_NAME "${PROJECT_NAME} " PREFIX "lib" )
88
+ else ()
89
+ set_target_properties (${TARGET_NAME} PROPERTIES OUTPUT_NAME ${PROJECT_NAME} )
90
+ # automatically create a module definition (.def) file for MSVC so it will
91
+ # build an import library (.lib)
92
+ set_property (TARGET ${TARGET_NAME} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS 1 )
93
+ if (WIN32 )
94
+ # Let MinGW as MSVC not prefix the DLL
95
+ set_property (TARGET ${TARGET_NAME} PROPERTY PREFIX "" )
96
+ endif ()
97
+ endif ()
55
98
set_target_properties (${TARGET_NAME} PROPERTIES VERSION ${PROJECT_VERSION} )
56
99
set_target_properties (${TARGET_NAME} PROPERTIES SOVERSION
57
100
${PROJECT_VERSION_MAJOR} )
@@ -71,6 +114,7 @@ foreach(TARGET_TYPE ${TARGET_TYPES})
71
114
EXPORT ${TARGETS_EXPORT_NAME}
72
115
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
73
116
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
117
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} # install DLLs on Windows
74
118
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /${PROJECT_NAME} )
75
119
76
120
# build directory package config
@@ -112,8 +156,15 @@ file(COPY ${FIND_MODULES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
112
156
export (PACKAGE ${PROJECT_NAME} )
113
157
# generate pc-file
114
158
include (JoinPaths )
115
- join_paths (libdir_for_pc_file "\$ {exec_prefix}" "${CMAKE_INSTALL_LIBDIR} " )
116
- join_paths (includedir_for_pc_file "\$ {prefix}" "${CMAKE_INSTALL_INCLUDEDIR} " "${PROJECT_NAME} " )
159
+ join_paths (
160
+ libdir_for_pc_file
161
+ "\$ {exec_prefix}"
162
+ "${CMAKE_INSTALL_LIBDIR} " )
163
+ join_paths (
164
+ includedir_for_pc_file
165
+ "\$ {prefix}"
166
+ "${CMAKE_INSTALL_INCLUDEDIR} "
167
+ "${PROJECT_NAME} " )
117
168
configure_file (
118
169
${CMAKE_CURRENT_SOURCE_DIR} /cmake/pc.in
119
170
${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME}.pc
@@ -148,19 +199,16 @@ if(BUILD_EXAMPLES)
148
199
DESTINATION ${CMAKE_INSTALL_DOCDIR} /examples/ )
149
200
endif ()
150
201
151
- option (
152
- BUILD_DOCS
153
- "Build and install docs"
154
- ON )
202
+ option (BUILD_DOCS "Build and install docs" )
155
203
if (BUILD_DOCS )
156
204
find_package (Doxygen REQUIRED )
157
205
set (DOXYGEN_STRIP_FROM_PATH ${CMAKE_CURRENT_SOURCE_DIR} )
206
+ set (DOXYGEN_USE_MDFILE_AS_MAINPAGE README.md )
158
207
doxygen_add_docs (
159
208
docs
160
- ${CMAKE_CURRENT_SOURCE_DIR} /doc/iniparser.txt
209
+ ${CMAKE_CURRENT_SOURCE_DIR} /README.md
161
210
${CMAKE_CURRENT_SOURCE_DIR} /src/iniparser.h
162
- ALL
163
- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /doc )
211
+ ALL )
164
212
install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /html
165
213
DESTINATION ${CMAKE_INSTALL_DOCDIR} )
166
214
endif ()
0 commit comments