CMake: Configure C++11 correctly, support shared library, fix install dirs
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.7)
project(liblcf VERSION 0.5.3 LANGUAGES CXX)
-option(DISABLE_ICU "Disable ICU encoding detection (fallback to iconv)" OFF)
+option(BUILD_SHARED_LIBS "Build shared library, disable for building the static library" ON)
+option(DISABLE_ICU "Disable ICU encoding detection (fallback to iconv, not recommended)" OFF)
option(DISABLE_XML "Disable XML reading support (expat)" OFF)
set(DEBUG_POSTFIX "d")
@@ -114,8 +115,7 @@ add_library(lcf
)
# C++11 is required
-set_property(TARGET lcf PROPERTY CXX_STANDARD 11)
-set_property(TARGET lcf PROPERTY CXX_STANDARD_REQUIRED ON)
+target_compile_features(lcf PUBLIC cxx_std_11)
# includes
target_include_directories(
@@ -136,6 +136,9 @@ endif()
# Add optional library name postfix
set_property(TARGET lcf PROPERTY DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
+# Export symbols for DLL
+set_property(TARGET lcf PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
+
if(MSVC)
# bigobj for reader_struct
set_property(TARGET lcf PROPERTY COMPILE_FLAGS "/bigobj")
@@ -160,6 +163,9 @@ if(NOT DISABLE_XML)
list(APPEND LIBLCF_DEPS "expat")
endif()
+# .so version
+set_property(TARGET lcf PROPERTY SOVERSION 0)
+
# pkg-config file generation
set(PACKAGE_TARNAME ${PROJECT_NAME})
set(PACKAGE_VERSION ${PROJECT_VERSION})
@@ -190,13 +196,13 @@ install(
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/liblcf)
install(
- FILES ${CMAKE_BINARY_DIR}/builds/${PROJECT_NAME}.pc
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/builds/${PROJECT_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
install(
FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/builds/liblcf-config.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/builds/liblcf-config.cmake
${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules/FindEXPAT.cmake
${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules/FindICU.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/liblcf)

MODIFY
builds/liblcf-config.cmake.in
builds/liblcf-config.cmake.in
@@ -85,6 +85,7 @@ if(LIBLCF_FOUND)
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
INTERFACE_INCLUDE_DIRECTORIES "${LIBLCF_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${LIBLCF_LINK_LIBRARIES}")
+ target_compile_features(liblcf::liblcf PUBLIC cxx_std_11)
if(LIBLCF_LIBRARY_RELEASE)
set_property(TARGET liblcf::liblcf APPEND PROPERTY

CMake: Configure C++11 correctly, support shared library, fix install dirs