Skip to content

Instantly share code, notes, and snippets.

@plusangel
Created October 31, 2020 11:25
Show Gist options
  • Save plusangel/9e370e893166dc79cc0c8967871882a1 to your computer and use it in GitHub Desktop.
Save plusangel/9e370e893166dc79cc0c8967871882a1 to your computer and use it in GitHub Desktop.
CMake using conditionals
cmake_minimum_required(VERSION 3.17)
project(cmake_recipe01 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(USE_LIBRARY ON)
message(STATUS "Compile sources into library? ${USE_LIBRARY}")
set(BUILD_SHARED_LIBS OFF)
list(APPEND _sources Message.h Message.cpp)
if(USE_LIBRARY)
add_library(message ${_sources})
add_executable(cmake_recipe01 main.cpp)
target_link_libraries(cmake_recipe01 message)
else()
add_executable(cmake_recipe01 main.cpp ${_sources})
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment