

New in version 3.11: An ALIAS can target a GLOBAL Imported Target.
The actual file name of the executable built is constructed based on conventions of the native platform (such asCmake add executable code#
Like add_executable, add EXCLUDE_FROM_ALL before the list of source files to exclude it from the all target: add_library(my_lib EXCLUDE_FROM_ALL lib.cpp) I use CMake for building and want to keep my project flexible and consice, so I decided to group code files in separate folders.
Cmake add executable windows#
For example, an shared library on Unix systems is usually called libmy_shared_library.so, but on Windows it would be my_shared_library.dll and my_shared_library.lib.

The actual output file differs between systems.

However, you can explicitly set to build an shared or an static library by adding STATIC or SHARED after the target name: add_library(my_shared_lib SHARED lib.cpp) # Builds an shared libraryĪdd_library(my_static_lib STATIC lib.cpp) # Builds an static library The CMake variable BUILD_SHARED_LIBS controls whenever to build an static ( OFF) or an shared ( ON) library, using for example cmake. We can extend our executable from above by linking it to our libray libtest.a. To create an build target that creates an library, use the add_library command: add_library(my_lib lib.cpp) Linking libraries to executables with CMake. To exclude an executable from being built with the default all target, one can add the optional parameter EXCLUDE_FROM_ALL right after the target name: add_executable(my_optional_exe EXCLUDE_FROM_ALL main.cpp) An INTERFACE library target does not directly create build output, though it may have properties set on it and it may be installed, exported and imported. see the icon on the top-left corner of the window, and also the icon is set on the executable(.exe) itself. Add executable called helloDemo that is built from the source files demo.cxx and demob.cxx. make my_exe for GNU make, with the appropriate invocations of the configured compiler to produce an executable my_exe from the two source files main.cpp and utilities.cpp.īy default, all executable targets are added to the builtin all target ( all for GNU make, BUILD_ALL for MSVC). Set application icon using CMake on Windows. To create a build target producing an executable, one should use the add_executable command: add_executable(my_exe
