From 0aa55a29e50adf2f7603619f2620922bc2a318d8 Mon Sep 17 00:00:00 2001 From: Jamis Hoo Date: Sun, 29 Mar 2020 17:28:01 +0800 Subject: [PATCH] Replace CMAKE_XXX_DIR with PROJECT_XXX_DIR, so that this project can be used in an enclosing project --- CMakeLists.txt | 24 ++++++++++++------------ doc/CMakeLists.txt | 20 ++++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c955a42a..77ce1129 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,12 @@ project(${PROJECT_NAME} VERSION ${PROJECT_VERSION}) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") -#set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/out) -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) -set(RUNTIME_SHARED_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/shared/bin) +#set(PROJECT_BINARY_DIR ${PROJECT_SOURCE_DIR}/out) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) +set(RUNTIME_SHARED_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/shared/bin) set(CMAKE_MACOSX_RPATH TRUE) @@ -43,19 +43,19 @@ if (NOT WITH_EMBEDDED_SRC) endif () # Run platform tests -include(${CMAKE_SOURCE_DIR}/cmake/configure.cmake) -configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.cmake ${CMAKE_BINARY_DIR}/src/config.h) -add_definitions(-I$(CMAKE_BINARY_DIR)/src) +include(${PROJECT_SOURCE_DIR}/cmake/configure.cmake) +configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.cmake ${PROJECT_BINARY_DIR}/src/config.h) +add_definitions(-I${PROJECT_BINARY_DIR}/src) add_definitions(-DHAVE_CONFIG_H) # pkg-config configure_file( - ${CMAKE_SOURCE_DIR}/cmake/shadowsocks-libev.pc.cmake - ${CMAKE_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc + ${PROJECT_SOURCE_DIR}/cmake/shadowsocks-libev.pc.cmake + ${PROJECT_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc @ONLY ) install(FILES - ${CMAKE_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc + ${PROJECT_BINARY_DIR}/pkgconfig/shadowsocks-libev.pc DESTINATION lib/pkgconfig ) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 3c9626e7..9abd4552 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -22,10 +22,10 @@ if (EXISTS ${XMLTO_CATALOG_DIR_MACOS}) message(STATUS "Detect xmlto catalog dir ${XMLTO_CATALOG_DIR_MACOS}") endif () -set(CMAKE_MANPAGE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/man) -set(CMAKE_HTML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/html) +set(CMAKE_MANPAGE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/man) +set(CMAKE_HTML_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/html) -set(DOC_DIR ${CMAKE_SOURCE_DIR}/doc) +set(DOC_DIR ${PROJECT_SOURCE_DIR}/doc) set(XMLTO_OPTS -m ${DOC_DIR}/manpage-normal.xsl -m ${DOC_DIR}/manpage-bold-literal.xsl man) set(ASCIIDOC_XML_OPTS -b docbook -d manpage -f ${DOC_DIR}/asciidoc.conf -aversion=${PROJECT_VERSION}) set(ASCIIDOC_HTML_OPTS -b html4 -d article -f ${DOC_DIR}/asciidoc.conf -aversion=${PROJECT_VERSION}) @@ -50,7 +50,7 @@ foreach (manfile IN LISTS MAN_NAMES) # After we built the manpage, the xmlfile is nolongger needed COMMAND ${CMAKE_COMMAND} -E remove ${xmlfile} DEPENDS ${docfile} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/man + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/man COMMENT "Building manpage ${manfile}" VERBATIM) list(APPEND MAN_FILES ${manfile}) @@ -58,7 +58,7 @@ foreach (manfile IN LISTS MAN_NAMES) add_custom_command(OUTPUT ${htmlfile} COMMAND ${ASCIIDOC_EXECUTABLE} ${ASCIIDOC_HTML_OPTS} -o ${htmlfile} ${docfile} DEPENDS ${docfile} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/html + WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/html COMMENT "Building htmlfile ${htmlfile}" VERBATIM) list(APPEND HTML_FILES ${htmlfile}) @@ -71,11 +71,11 @@ add_custom_target(doc-html ALL DEPENDS ${HTML_FILES}) if (NOT WITH_DOC_MAN) set_target_properties(doc-man PROPERTIES EXCLUDE_FROM_ALL TRUE) else () - install(DIRECTORY ${CMAKE_BINARY_DIR}/man/ + install(DIRECTORY ${PROJECT_BINARY_DIR}/man/ DESTINATION share/man/man1 FILES_MATCHING PATTERN "*.1" ) - install(DIRECTORY ${CMAKE_BINARY_DIR}/man/ + install(DIRECTORY ${PROJECT_BINARY_DIR}/man/ DESTINATION share/man/man8 FILES_MATCHING PATTERN "*.8" ) @@ -83,10 +83,10 @@ endif () if (NOT WITH_DOC_HTML) set_target_properties(doc-html PROPERTIES EXCLUDE_FROM_ALL TRUE) else () - install(DIRECTORY ${CMAKE_BINARY_DIR}/html/ + install(DIRECTORY ${PROJECT_BINARY_DIR}/html/ DESTINATION share/doc/${PROJECT_NAME}) endif () # This is required for custom command -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/man) -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/html) +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/man) +file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/html)