Skip to content

CMake tips

Ahmed Yakout edited this page Apr 21, 2018 · 2 revisions

Some tips about CMake to make life easier:

  • to add all .cpp file in some variable to use them
FILE(GLOB SRC_FILES *.cpp)

this way you have SRC_FILES includes all .cpp files

  • since you can't have two mains in the same program you can add two executables and link them to some library.
add_executable(Main1 main1.cpp)
add_executable(Main2 main2.cpp)
add_library(Lib <all the other files the are used by main1 and main2>)

target_link_libraries(Main1 Lib)
target_link_libraries(Main2 Lib)

Note: it's better to make the library SHARED or STATIC so you don't rebuild the files twice for each executable

add_library(Lib SHARED <all the other files the are used by main1 and main2>)
  • // TODO add more tips
Clone this wiki locally