0

CMake: download a file

The following code download a file from URL as FILE.

Advertisements
0

CMakeLists.txt working with CodeSynthesis XSD

I made a repository that uses CodeSynthesis XSD with CMake. The CMakeLists.txt calls XSD and generates C++ classes so that we can avoid calling XSD from terminal, meaning the compilation is fully automatic. The CMakeLists.txt does

  1. find necessary packages (Xerces-C and CodeSynthesis XSD) and add include directories.
  2. make a build rule for each xsd file.
    1. make a directory for storing cxx and hxx files.
    2. run xsdcxx and store the resulting cxx and hxx files in the made directory.
    3. define compilation rules to make a library for the xsd file
# 1. find necessary packages
find_package(XercesC REQUIRED)
include_directories( ${XERCESC_INCLUDE_DIR})
find_package(XSD REQUIRED)
include_directories( ${XSD_INCLUDE_DIR} )
if(XSD_FOUND)
  # file all xsd files
  file( GLOB xsds ${CMAKE_SOURCE_DIR}/*.xsd )
  # 2. make a build rule for each xsd file
  foreach( xsd ${xsds} )
    get_filename_component(xsdName ${xsd} NAME_WE)
    set(xsdDir ${CMAKE_SOURCE_DIR}/${xsdName})
    # 2.1. make a directory for the xsd file
    file(MAKE_DIRECTORY ${xsdDir})
    include_directories( ${xsdDir} )
    # 2.2. run xsdcxx and store the resulting cxx and hxx files in the made directory
    execute_process(COMMAND ${XSD_EXECUTABLE} cxx-tree ${xsd} WORKING_DIRECTORY ${xsdDir} )
    set(PROJ_SCHEME_SOURCE  ${xsdDir}/${xsdName}.cxx)
    set(PROJ_SCHEME_INCLUDE ${xsdDir}/${xsdName}.hxx)
    # 2.3. define compilation rules to make a library for the xsd file
    add_library( ${xsdName} ${PROJ_SCHEME_SOURCE} ${PROJ_SCHEME_INCLUDE} )
    target_link_libraries( ${xsdName} ${XERCESC_LIBRARIES} )
    list(APPEND PROJ_SCHEME_NAME ${xsdName} )
    list(APPEND PROJ_INCLUDE ${PROJ_SCHEME_INCLUDE} )
    list(APPEND PROJ_SOURCE  ${PROJ_SCHEME_SOURCE} )
  endforeach()
endif()
0

Install CMake 2.8.12.2 from source

There are several ways for CMake installation from source. I tried to install CMake 2.8.12.2 from source using pre-installed CMake 2.8.7 but it failed.

#!/bin/bash

wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
tar zxvf cmake-2.8.12.2.tar.gz
cd cmake-2.8.12.2
./bootstrap –prefix=/usr/local –qt-gui 2>&1 | tee Cmake2.8.12.2bootstrap.log
make 2>&1 | tee Cmake2.8.12.2Make.log
sudo make install 2>&1 | tee Cmake2.8.12.2MakeInstall.log

0

CMake: how to get the name of parent directory

I have been looking for how to get the name of parent directory of CMAKE_SOURCE_DIR and could find the answer today. The solution is to use get_filename_component() function with “PATH” argument.

Let’s say CMAKE_SOURCE_DIR is “/code/testCmake/“. I wanna access “/code/data/” directory using CMake. The solution is
get_filename_component(DATA_DIR ${CMAKE_SOURCE_DIR} PATH)
set(DATA_DIR ${DATA_DIR}/data/)
Then, DATA_DIR stores “/code/data/“.