Menu

CMake and

2018-02-09
2018-02-13
  • Thomas Bechmann

    Thomas Bechmann - 2018-02-09

    I have created a CMakeLists.txt for multi platform builds and included a UNICODE switch. After compilation it will destribute a static lib into a lib folder and destributes all header files into an include folder. I have only tested it on Windows 10 with CMake 3.7 and therefore set the minimum required version to 3.7, but i guess it should also work with the 2.8 version of CMake. Feel free to add it to the project. :)

    EDIT: Sorry for the messed up title. I decided to split up my post and forgot to change the title.

    Regards
    Thomas Bechmann

    The CMakeLists.txt, it should be placed in the Source folder:

    cmake_minimum_required(VERSION 3.7)
    project(SimpleXlsx)
    
    if(NOT CMAKE_DEBUG_POSTFIX)
      set(CMAKE_DEBUG_POSTFIX d)
    endif()
    
    set(UNICODE false CACHE BOOL "Use Unicode macro")
    
    if(${UNICODE})
        add_definitions(-DUNICODE -D_UNICODE)
    endif()
    
    file(GLOB MAIN_HDRS
        "*.hpp"
        "*.h"
        )
    file(GLOB XLSX_HDRS
        "Xlsx/*.h"
        )
    file(GLOB XLSXCOLORS_HDRS
        "XLSXColors/*.h"
        )
    
    file(GLOB ZIP_HDRS
        "Zip/*.h"
        )
    
    file(GLOB SRCS
        "*.cpp" 
        "Xlsx/*.cpp"
        "XLSXColors/*.cpp"
        "Zip/*.cpp"
        )
    
    add_library(SimpleXlsx STATIC 
                ${SRCS}
                ${MAIN_HDRS}
                ${XLSX_HDRS}
                ${XLSXCOLORS_HDRS}
                ${ZIP_HDRS}
                )
    set_target_properties(SimpleXlsx PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX})
    
    install(TARGETS SimpleXlsx DESTINATION lib)
    install(FILES ${MAIN_HDRS} DESTINATION include)
    install(FILES ${XLSX_HDRS} DESTINATION include/Xlsx)
    install(FILES ${XLSXCOLORS_HDRS} DESTINATION include/XLSXColors)
    install(FILES ${ZIP_HDRS} DESTINATION include/Zip)
    
     

    Last edit: Thomas Bechmann 2018-02-09
  • Alexandr Belyak

    Alexandr Belyak - 2018-02-12

    Hi Thomas,

    You are ahead of me in creating CMakeLists.txt :-) Thanks for this great job!
    I tested the build on Linux x64 with CMake 3.10 - everything is fine.
    I'll try to test with CMake 2.8 and let you know more. Then I will add CMakeLists.txt to the project.

     
  • Alexandr Belyak

    Alexandr Belyak - 2018-02-13

    I tested the build with CMake 2.8.12 - all ok.
    Thanks again for your help!

     

Log in to post a comment.