Unverified Commit 7b247671 authored by Mark Lindner's avatar Mark Lindner Committed by GitHub

Merge pull request #91 from fenglc/master

configure cmake
parents 9ad6ee70 82a77398
cmake_minimum_required(VERSION 3.1)
project(libconfig)
option(BUILD_EXAMPLES "Enable examples" ON)
option(BUILD_SHARED_LIBS "Enable shared library" ON)
option(BUILD_TESTS "Enable tests" ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(LIB_TYPE STATIC)
if(BUILD_SHARED_LIBS)
set(LIB_TYPE SHARED)
add_definitions(-DLIBCONFIG_EXPORTS)
add_definitions(-DLIBCONFIGXX_EXPORTS)
else()
add_definitions(-DLIBCONFIG_STATIC)
add_definitions(-DLIBCONFIGXX_STATIC)
endif()
include(GNUInstallDirs)
add_subdirectory(lib)
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(tinytest)
add_subdirectory(tests)
endif()
add_subdirectory(c)
add_subdirectory(c++)
\ No newline at end of file
add_executable(c++_example1 example1.cpp )
add_executable(c++_example2 example2.cpp )
add_executable(c++_example3 example3.cpp )
add_executable(c++_example4 example4.cpp )
target_include_directories(c++_example1 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example2 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example3 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c++_example4 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_link_libraries(c++_example1 libconfig++ )
target_link_libraries(c++_example2 libconfig++ )
target_link_libraries(c++_example3 libconfig++ )
target_link_libraries(c++_example4 libconfig++ )
\ No newline at end of file
add_executable(c_example1 example1.c )
add_executable(c_example2 example2.c )
add_executable(c_example3 example3.c )
target_include_directories(c_example1 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c_example2 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_include_directories(c_example3 PRIVATE ${CMAKE_SOURCE_DIR}/lib)
target_link_libraries(c_example1 libconfig )
target_link_libraries(c_example2 libconfig )
target_link_libraries(c_example3 libconfig )
\ No newline at end of file
set(libinc
libconfig.h)
set(libsrc
grammar.h
parsectx.h
scanctx.h
scanner.h
win32/stdint.h
strbuf.h
strvec.h
util.h
wincompat.h
grammar.c
libconfig.c
scanctx.c
scanner.c
strbuf.c
strvec.c
util.c)
set(libinc_cpp
libconfig.h++
libconfig.hh)
set(libsrc_cpp
${libsrc}
libconfigcpp.cc)
add_library(libconfig ${LIB_TYPE} ${libsrc} ${libinc})
add_library(libconfig++ ${LIB_TYPE} ${libsrc_cpp} ${libinc_cpp})
set_target_properties(libconfig
PROPERTIES LINKER_LANGUAGE C
PUBLIC_HEADER "${libinc}")
set_target_properties(libconfig++
PROPERTIES LINKER_LANGUAGE CXX
PUBLIC_HEADER "${libinc_cpp}")
target_compile_definitions(libconfig
PRIVATE
_CRT_SECURE_NO_DEPRECATE
_STDLIB_H
YY_NO_UNISTD_H
YY_USE_CONST )
target_compile_definitions(libconfig++
PRIVATE
_CRT_SECURE_NO_DEPRECATE
_STDLIB_H
YY_NO_UNISTD_H
YY_USE_CONST )
if(CMAKE_HOST_WIN32)
target_link_libraries(libconfig Shlwapi.lib)
target_link_libraries(libconfig++ Shlwapi.lib)
endif()
install(TARGETS libconfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS libconfig++
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
\ No newline at end of file
add_executable(libconfig_tests
tests.c )
target_link_libraries(libconfig_tests
libconfig
libtinytest )
target_include_directories(libconfig_tests
PRIVATE ${CMAKE_SOURCE_DIR}/lib
${CMAKE_SOURCE_DIR}/tinytest )
add_test(NAME libconfig_tests COMMAND libconfig_tests)
\ No newline at end of file
add_library(libtinytest STATIC
tinytest.h
tinytest.c)
if(CMAKE_HOST_WIN32)
if(MSVC)
set_target_properties(libtinytest
PROPERTIES
COMPILE_FLAGS "/wd4996"
)
endif()
endif()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment