Open Martins3 opened 3 years ago
cmake_minimum_required(VERSION 2.8.4)
set(LIBHELLO_SRC hello.c)
add_library(hello_dynamic SHARED ${LIBHELLO_SRC})
add_library(hello_static STATIC ${LIBHELLO_SRC})
set_target_properties(hello_dynamic PROPERTIES OUTPUT_NAME "hello")
set_target_properties(hello_dynamic PROPERTIES VERSION 1.2 SOVERSION 1)
set_target_properties(hello_static PROPERTIES OUTPUT_NAME "hello")
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
install(TARGETS hello_dynamic hello_static
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
install(FILES hello.h DESTINATION include/hello)
add_executable(main main.cpp)
set(CMAKE_INCLUDE_CURRENT_DIR 0) # bug
message(STATUS ${CMAKE_INCLUDE_CURRENT_DIR})
message(STATUS ${CMAKE_CURRENT_SOURCE_DIR})
message(STATUS ${CMAKE_CURRENT_BINARY_DIR})
# include_directories(../include/hello) # bug
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
#include <iostream>
#include <fuck.hpp>
#include <hello.hpp>
int main(void) {
std::cout << "fuck" << std::endl;
return 0;
}
├── include
│ └── hello
│ └── hello.hpp
└── src
├── main.cpp
cmake_minimum_required(VERSION 3.10)
project(foo)
set(TEST_FILE "log.txt")
set(GG_FILE "gg.txt")
# add_custom_command does not create a new target. You have to define targets explicitly
# by add_executable, add_library or add_custom_target in order to make them visible to make
add_custom_command(OUTPUT ${TEST_FILE}
COMMAND touch ${TEST_FILE}
# Display the given message before the commands are executed at build time
COMMENT "Creating ${TEST_FILE}"
DEPENDS ${GG_FILE}
)
add_custom_command(OUTPUT ${GG_FILE}
COMMAND touch ${GG_FILE}
# Display the given message before the commands are executed at build time
COMMENT "Creating ${GG_FILE}"
)
# target zoo is always built
add_custom_target(zoo ALL
COMMAND echo "This is ALL target 'zoo', and it depends on ${TEST_FILE}"
# If the file exists, then commands related to that file won't be executed
# DONOT let other target depends on the same OUTPUT as current target,
# or it may be bad when doing parallel make
DEPENDS ${TEST_FILE}
# to make quotes printable,for example
VERBATIM
)
Generate exe for every cpp