[CMake] Custom command with included header file

Reza Housseini reza.housseini at gmx.ch
Fri Sep 21 08:26:22 EDT 2012


Hello
I want to add my own library libsieve.so with the header file Sieve.h
to the custom target. I have the following setup:

find_program(MKOCTFILE_EXECUTABLE mkoctfile)
if(NOT MKOCTFILE_EXECUTABLE)
  message(SEND_ERROR "Failed to find mkoctfile, is it in your $PATH?")
endif()

set(OCT_FILE "multidecksieve.oct")
set(OCT_SRC "${CMAKE_CURRENT_SOURCE_DIR}/multidecksieve.cpp")
set(CPPLIB_DIR "${CMAKE_SOURCE_DIR}/../core/build")
set(CPPLIB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/../core")

find_library(CPPLIB_SIEVE_LIBRARY NAMES sieve PATHS ${CPPLIB_DIR})
find_path(CPPLIB_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/../core)

if ("${CPPLIB_SIEVE_LIBRARY}" STREQUAL "CPPLIB_SIEVE_LIBRARY-NOTFOUND")
  message(FATAL_ERROR "One of the libraries wasn't found!")
endif ()

include_directories(CPPLIB_INCLUDE_DIR)

add_custom_command(
  OUTPUT ${OCT_FILE}
  COMMAND ${MKOCTFILE_EXECUTABLE} "${OCT_SRC}"
  DEPENDS ${CPPLIB_INCLUDE_DIR}/Sieve.h ${CPPLIB_SIEVE_LIBRARY}
  COMMENT "Generating ${OCT_FILE}"
  VERBATIM)

add_custom_target(multidecksieve ALL
  DEPENDS ${OCT_FILE})

But it gives me the error that it can't find the Sieve.h file:
fatal error: Sieve.h: No such file or directory

What is the correct way to do it?

Thanks and best wishes
Reza


More information about the CMake mailing list