CMake: Improve Windows build, fix install, substitute CMAKE_DEBUG_POSTFIX
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -5,17 +5,15 @@ project(liblcf VERSION 0.5.3 LANGUAGES CXX)
option(DISABLE_ICU "Disable ICU encoding detection (fallback to iconv)" OFF)
option(DISABLE_XML "Disable XML reading support (expat)" OFF)
-if(MSVC)
set(DEBUG_POSTFIX "d")
-else()
- set(DEBUG_POSTFIX "")
-endif()
mark_as_advanced(DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX ${DEBUG_POSTFIX} CACHE STRING "Override CMAKE_DEBUG_POSTFIX.")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/builds/cmake/Modules)
+include(ConfigureWindows)
+
# Doxygen
find_package(Doxygen)
if(DOXYGEN_FOUND)
@@ -139,8 +137,8 @@ endif()
set_property(TARGET lcf PROPERTY DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}")
if(MSVC)
- # Exception handling
- set_property(TARGET lcf PROPERTY COMPILE_FLAGS "/EHsc")
+ # bigobj for reader_struct
+ set_property(TARGET lcf PROPERTY COMPILE_FLAGS "/bigobj")
endif()
# icu or fallback to iconv
@@ -192,13 +190,16 @@ install(
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/liblcf)
install(
- FILES builds/${PROJECT_NAME}.pc
- DESTINATION lib/pkgconfig
+ FILES ${CMAKE_BINARY_DIR}/builds/${PROJECT_NAME}.pc
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)
install(
- FILES builds/liblcf-config.cmake
- DESTINATION lib/cmake/liblcf)
+ FILES
+ ${CMAKE_CURRENT_SOURCE_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)
# tests
file(GLOB TEST_FILES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)

ADD
builds/cmake/Modules/ConfigureWindows.cmake
+if(WIN32)
+ option(SHARED_RUNTIME "Windows: Build using the shared runtime library (/MD), disable for static runtime (/MT)" ON)
+
+ # Set compiler options.
+ set(variables
+ CMAKE_C_FLAGS_DEBUG
+ CMAKE_C_FLAGS_MINSIZEREL
+ CMAKE_C_FLAGS_RELEASE
+ CMAKE_C_FLAGS_RELWITHDEBINFO
+ CMAKE_CXX_FLAGS_DEBUG
+ CMAKE_CXX_FLAGS_MINSIZEREL
+ CMAKE_CXX_FLAGS_RELEASE
+ CMAKE_CXX_FLAGS_RELWITHDEBINFO
+ )
+ if(SHARED_RUNTIME)
+ message(STATUS "Windows: Using dynamic runtime library (/MD)")
+ foreach(variable ${variables})
+ if(${variable} MATCHES "/MT")
+ string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
+ endif()
+ endforeach()
+ else()
+ message(STATUS "Windows: Using static runtime library (/MT)")
+ foreach(variable ${variables})
+ if(${variable} MATCHES "/MD")
+ string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
+ endif()
+ endforeach()
+ endif()
+
+ # Target Unicode API
+ add_definitions(-D_UNICODE)
+ add_definitions(-DUNICODE)
+
+ # Disable API deprecation warnings
+ add_definitions(-D_CRT_SECURE_NO_WARNINGS)
+endif()
+
+if(MSVC)
+ option(MSVC_MULTICORE "MSVC: Build using multiple cores (/MP)" ON)
+ if (MSVC_MULTICORE)
+ add_compile_options(/MP)
+ endif()
+endif()

MODIFY
builds/liblcf-config.cmake.in
builds/liblcf-config.cmake.in
@@ -44,7 +44,7 @@ if(NOT LIBLCF_LIBRARY)
HINTS ${PC_LIBLCF_LIBRARY_DIRS})
find_library(LIBLCF_LIBRARY_DEBUG
- NAMES lcfd liblcfd
+ NAMES lcf@CMAKE_DEBUG_POSTFIX@ liblcf@CMAKE_DEBUG_POSTFIX@
HINTS ${PC_LIBLCF_LIBRARY_DIRS})
include(SelectLibraryConfigurations)

MODIFY
configure.ac
configure.ac
@@ -52,6 +52,9 @@ AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_LDFLAGS])
+# liblcf-config.cmake (use empty postfix)
+AC_SUBST([CMAKE_DEBUG_POSTFIX])
+
# Files to generate
AC_CONFIG_FILES([Makefile
builds/liblcf.pc

CMake: Improve Windows build, fix install, substitute CMAKE_DEBUG_POSTFIX