diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2012cee --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,57 @@ +cmake_minimum_required(VERSION 3.10) +project(libcyaml VERSION 2.0.0 LANGUAGES C) + +# Version defines +add_compile_definitions( + VERSION_MAJOR=2 + VERSION_MINOR=0 + VERSION_PATCH=0 + VERSION_DEVEL=1 +) + +# Set default build type to Debug if not specified +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Debug) +endif() + +# Set output directories +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +# Source files +set(LIBCYAML_SRC + src/mem.c + src/free.c + src/load.c + src/save.c + src/copy.c + src/util.c + src/utf8.c +) + +# Include directories +include_directories(include) + +# Find libyaml +find_package(PkgConfig REQUIRED) +pkg_check_modules(LIBYAML REQUIRED yaml-0.1) +include_directories(${LIBYAML_INCLUDE_DIRS}) +link_directories(${LIBYAML_LIBRARY_DIRS}) + +# Build shared library +add_library(cyaml_shared SHARED ${LIBCYAML_SRC}) +set_target_properties(cyaml_shared PROPERTIES OUTPUT_NAME cyaml) +target_link_libraries(cyaml_shared ${LIBYAML_LIBRARIES}) + +# Build static library +add_library(cyaml_static STATIC ${LIBCYAML_SRC}) +set_target_properties(cyaml_static PROPERTIES OUTPUT_NAME cyaml) +target_link_libraries(cyaml_static ${LIBYAML_LIBRARIES}) + +# Examples +add_executable(planner examples/planner/main.c) +target_link_libraries(planner cyaml_static ${LIBYAML_LIBRARIES}) + +add_executable(numerical examples/numerical/main.c) +target_link_libraries(numerical cyaml_static ${LIBYAML_LIBRARIES}) \ No newline at end of file diff --git a/README.md b/README.md index 45bc3a5..b700718 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,16 @@ with valgrind) can be built with: make VARIANT=san + +To build on Windows use CMake in conjunction with vcpkg + + mkdir build; cd build + cmake .. -DCMAKE_TOOLCHAIN_FILE=\path\to\toolchain\file\vcpkg.cmake + cmake --build . + +Note: + This does not currently build any tests etc, only static and dynamic libs. + Installation ------------