Tuesday, December 7, 2010

just cmake it

CMake is awesome, sure it is a little weird at times but vs all competition it's wiping the floor in maintaining complex builds over many platforms. The code can be really clean in comparison with some things I've seen in the past too. Well anyway, here's a few build scripts I'd like to contribute:

  • A 32bit software on a 64bit linux install configuration handler This, by default, automatically detects if the build environment is not 32 bit and adjusts accordingly when included. The automatic behavior is disableable by setting NO_AUTO_X86_32 before include.
    macro(setx86_32)
    set(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
    set(LINK_FLAGS "-m32 ${LINK_FLAGS}")
    set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS FALSE)
    set(QT_LIBRARY_DIR /usr/lib)
    endmacro()

    if(NOT NO_AUTO_X86_32 AND NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
    setx86_32()
    endif()



  • An XPlane plugin cmake file . Include and use pretty much like add_library / install_target.
    set(XPLANE_LINKER_FLAGS "-nodefaultlibs")
    if(NOT DEFINED XPLANE_SDK)
    if(UNIX)
    set(XPLANE_SDK "/opt/xplane sdk")
    endif()
    endif(NOT DEFINED XPLANE_SDK)

    if(NOT DEFINED XPLANE_PATH)
    if(UNIX)
    set(XPLANE_PATH "/opt/X-Plane 9/")
    endif()
    endif(NOT DEFINED XPLANE_PATH)

    foreach(X Widgets Wrappers XPLM)
    include_directories(${XPLANE_SDK}/CHeaders/${X})
    endforeach()

    if(UNIX)
    add_definitions(-DLIN=1)
    endif()

    add_definitions(-DXPLM200=1)

    macro(add_xplane_plugin TARGET_NAME SRCS)
    add_library(${TARGET_NAME} SHARED ${SRCS})
    set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${XPLANE_LINKER_FLAGS}")
    set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
    set_target_properties(${TARGET_NAME} PROPERTIES SUFFIX ".xpl")
    if(UNIX)
    set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "lin")
    elseif(WINDOWS)
    set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "win")
    endif()
    endmacro()

    macro(install_xplane_plugin TARGET_NAME PLUGIN_NAME)
    install(TARGETS ${TARGET_NAME} LIBRARY DESTINATION "${XPLANE_PATH}/Resources/plugins/${PLUGIN_NAME}")
    endmacro()

No comments:

Post a Comment