CMAKE notes

tech2023-09-08  103

1. How to set relative path to a variable

Here is the folder struct. We run cmake in 'folder_cmake' and we hope to use something in 'my_folder'.

 

   /folder_top/folder_level1/folder_cmake

  /folder_top/my_folder

 

SET(my_variable ${CMAKE_CURRENT_SOURCE_DIR}/../../my_folder)

${CMAKE_CURRENT_SOURCE_DIR} is CMAKE internal variable which save the full path of 'folder_cmake'.

2. Put all sub folder's source files and include files to top folder

in sub folder:

list(APPEND MY_SRCS "a.c"                     "b.c") list(APPEND MY_INCS "a.h" "b.h") set(MY_SRCS ${MY_SRCS} TOPPARENT) set(MY_INCS ${MY_INCS} TOPPARENT)

Then you can use MY_SRCS and MY_INCS at the top folder. Will provide example later.

最新回复(0)