0

This is my sqrt library CMake file .

CMakeLists.txt

add_library(MathFunctions mysqrt.cpp)    
set(REF_FILES mysqrt.cpp)    
add_definitions(-Wall -Wextra -pedantic -std=c++11)    
add_custom_target(build_reference_library
      DEPENDS sqrtlib
      COMMENT "Generating sqrtlib")    
ADD_LIBRARY(sqrtlib OBJECT ${REF_FILES})

Below is my CMakeLists.txt (located in other folder ) using this library to execute sqrt operation on given input.

set(REF_MATHLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../MathFunctions)

macro(GENERATION file input)
  set(ip_generator ctest_input_${input})    
  add_executable(${ip_generator}
    ${file}
    $<TARGET_OBJECTS:sqrtlib>
    )

  target_compile_options(${ip_generator} PUBLIC
    -Wall -Wextra -g -std=c++11 
    -DCTEST_INPUT=${input})
  target_link_libraries(${ip_generator} PUBLIC
    dl pthread
    )    
  target_include_directories(${ip_generator} PUBLIC
    ${REF_MATHLIB_DIR}
    )

  set(INPUT_FILE0 ip0_${input}.y)
  set(INPUT_FILE0_TXT ip0_${input}.txt)    
  add_custom_command(
    OUTPUT ${INPUT_FILE0}  ${INPUT_FILE0_TXT}
    COMMAND ${ip_generator} > ${INPUT_FILE0_TXT}
    MAIN_DEPENDENCY ${sqrtlib}
    COMMENT "Generating output files of for testcase")
  
  add_custom_target(gen_input_${input}
    DEPENDS ${INPUT_FILE0}
    COMMENT "Generated output files")

endmacro() 

I want to add dependency for my sqrtlib in GENERATION MACRO to make sure that the object file for mysqrt.o should be available before executing GENERATION macro.

Can anyone guide me for the same .

  • `REF_MATHLIB_DIR` is a *variable*, not a **macro** as you note it in the question post. Do you mean `GENERATION` macro instead? Also, a CMake macro (specified with `macro()` command) is processed at **configuration stage** (when `cmake` is executed), but files like `mysqrt.o` are created at **build state** (when `make` or other build tool is executed). So, an object file simply cannot exist at the time when a CMake macro is processing. Probably, you want something else, but it is difficult to guess. If you trying to resolve some error, then add error message into the question post. – Tsyvarev Aug 20 '20 at 07:48
  • my mistake ..I want to say about ´GENERATION´ macro .I have updated now my question . – mahesh narlekar Aug 20 '20 at 09:33
  • @Tsyvarev, This is my actual question here : https://stackoverflow.com/questions/63495424/strange-behavior-of-cmake-ctest-for-bigger-ctest-parallel-level – mahesh narlekar Aug 20 '20 at 09:35
  • @Tsyvarev, I have added the detail question here.I am still having the dependency issue for the sqrtlib during my macro execution. I have added the dependency of the sqrtlib for this test execution.Means I wants to have that library available during the macro execution .This sqrtlib is (must)necessary to execute the square root operation on given input . https://stackoverflow.com/questions/63495424/strange-behavior-of-cmake-ctest-for-bigger-ctest-parallel-level – mahesh narlekar Aug 20 '20 at 09:41
  • @Tsyvarev,Can you please check my this question .https://stackoverflow.com/questions/63495424/strange-behavior-of-cmake-ctest-for-bigger-ctest-parallel-level – mahesh narlekar Aug 20 '20 at 09:54

0 Answers0