cmake_minimum_required(VERSION 3.10)
project(MyProject)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
file(GLOB_RECURSE SRC_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")
include_directories("${PROJECT_SOURCE_DIR}/include")
add_executable(MyExecutable ${SRC_FILES})
add_library(MyLibrary STATIC ${SRC_FILES})
add_library(MyLibrary SHARED ${SRC_FILES})
target_link_libraries(MyExecutable MyLibrary)
install(TARGETS MyExecutable MyLibrary
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)
add_subdirectory(src)
file(GLOB_RECURSE SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
add_library(MyLibrary STATIC ${SRC_FILES})
target_link_libraries(MyExecutable MyLibrary)
cmake_minimum_required(VERSION 3.5)
project(Proj.bin)
set(CMAKE_VERBOSE_MAKEFILEON)
add_compile_options(-std=c++11 -Wall)
file(GLOB source_dir "${CMAKE_SOURCE_DIR}/*cpp")
file(GLOB source_dir_c "${CMAKE_SOURCE_DIR}/*c")
list(APPEND source_dir ${source_dir_c})
add_executable(Proj.bin ${source_dir})
target_link_libraries(Proj.bin pthread)
target_compile_definitions(Proj.bin PUBLIC _SWITCH_ENABLE_=1)
cmake .. -G "Visual Studio 16 2019"
cmake --build . --config Release
cmake -DCMAKE_INSTALL_PREFIX=/opt/project ..
make
sudo make install
install(TARGETS hello DESTINATION bin)
install(TARGETS mylib DESTINATION bin)
install(FILES myHeader.h DESTINATION include)
install(DIRECTORY myDirectory DESTINATION share/myProject)
project
├── CMakeLists.txt
├── include
│ └── mylib.h
└── src
├── main.cpp
└── mylib.cpp
cmake_minimum_required(VERSION 3.10)
project(HelloWorld)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include_directories(include)
add_library(mylib src/mylib.cpp)
add_executable(hello src/main.cpp)
target_link_libraries(hello mylib)
install(TARGETS hello DESTINATION bin)
install(TARGETS mylib DESTINATION lib)
install(FILES include/mylib.h DESTINATION include)
install(FILES README.md DESTINATION share/docs)