Rebuild apidsl'd headers in cmake.

- Moved apidsl headers next to their generated versions. In the future,
  perhaps all (or most) headers will be apidsl-generated, so the sources
  should stay together.
- Try to find apidsl/apigen binary and astyle binary and use it for the
  format test. Don't run the format test if these can't be found.
This commit is contained in:
iphydf 2016-09-21 10:51:58 +01:00
parent 66e1bb4510
commit b8b9789a69
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
9 changed files with 105 additions and 39 deletions

View File

@ -18,6 +18,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# #
################################################################################ ################################################################################
include(ApiDsl)
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
include(ModulePackage) include(ModulePackage)
@ -98,7 +99,8 @@ set(toxcore_PKGCONFIG_LIBS)
# LAYER 1: Crypto core # LAYER 1: Crypto core
# -------------------- # --------------------
add_module(toxcrypto add_module(toxcrypto
toxcore/crypto_core.c) toxcore/crypto_core.c
toxcore/crypto_core.h)
target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES}) target_link_modules(toxcrypto ${LIBSODIUM_LIBRARIES})
if(WIN32) if(WIN32)
target_link_modules(toxcrypto ws2_32) # for htonl target_link_modules(toxcrypto ws2_32) # for htonl
@ -108,8 +110,11 @@ endif()
# ------------------------- # -------------------------
add_module(toxnetwork add_module(toxnetwork
toxcore/logger.c toxcore/logger.c
toxcore/logger.h
toxcore/network.c toxcore/network.c
toxcore/util.c) toxcore/network.h
toxcore/util.c
toxcore/util.h)
target_link_modules(toxnetwork toxcrypto) target_link_modules(toxnetwork toxcrypto)
if(CMAKE_THREAD_LIBS_INIT) if(CMAKE_THREAD_LIBS_INIT)
@ -131,51 +136,71 @@ endif()
# ------------------------------- # -------------------------------
add_module(toxdht add_module(toxdht
toxcore/DHT.c toxcore/DHT.c
toxcore/DHT.h
toxcore/LAN_discovery.c toxcore/LAN_discovery.c
toxcore/LAN_discovery.h
toxcore/assoc.c toxcore/assoc.c
toxcore/assoc.h
toxcore/ping.c toxcore/ping.c
toxcore/ping_array.c) toxcore/ping.h
toxcore/ping_array.c
toxcore/ping_array.h)
target_link_modules(toxdht toxnetwork) target_link_modules(toxdht toxnetwork)
# LAYER 4: Onion routing, TCP connections, crypto connections # LAYER 4: Onion routing, TCP connections, crypto connections
# ----------------------------------------------------------- # -----------------------------------------------------------
add_module(toxnetcrypto add_module(toxnetcrypto
toxcore/TCP_client.c toxcore/TCP_client.c
toxcore/TCP_client.h
toxcore/TCP_connection.c toxcore/TCP_connection.c
toxcore/TCP_connection.h
toxcore/TCP_server.c toxcore/TCP_server.c
toxcore/TCP_server.h
toxcore/list.c toxcore/list.c
toxcore/list.h
toxcore/net_crypto.c toxcore/net_crypto.c
toxcore/net_crypto.h
toxcore/onion.c toxcore/onion.c
toxcore/onion.h
toxcore/onion_announce.c toxcore/onion_announce.c
toxcore/onion_client.c) toxcore/onion_announce.h
toxcore/onion_client.c
toxcore/onion_client.h)
target_link_modules(toxnetcrypto toxdht) target_link_modules(toxnetcrypto toxdht)
# LAYER 5: Friend requests and connections # LAYER 5: Friend requests and connections
# ---------------------------------------- # ----------------------------------------
add_module(toxfriends add_module(toxfriends
toxcore/friend_connection.c toxcore/friend_connection.c
toxcore/friend_requests.c) toxcore/friend_connection.h
toxcore/friend_requests.c
toxcore/friend_requests.h)
target_link_modules(toxfriends toxnetcrypto) target_link_modules(toxfriends toxnetcrypto)
# LAYER 6: Tox messenger # LAYER 6: Tox messenger
# ---------------------- # ----------------------
add_module(toxmessenger add_module(toxmessenger
toxcore/Messenger.c) toxcore/Messenger.c
toxcore/Messenger.h)
target_link_modules(toxmessenger toxfriends) target_link_modules(toxmessenger toxfriends)
# LAYER 7: Group chats # LAYER 7: Group chats
# -------------------- # --------------------
add_module(toxgroup add_module(toxgroup
toxcore/group.c) toxcore/group.c
toxcore/group.h)
target_link_modules(toxgroup toxmessenger) target_link_modules(toxgroup toxmessenger)
# LAYER 8: Public API # LAYER 8: Public API
# ------------------- # -------------------
apidsl(
toxcore/tox.api.h)
add_module(toxcore add_module(toxcore
toxcore/tox.c) toxcore/misc_tools.h
toxcore/tox.c
toxcore/tox.h)
target_link_modules(toxcore toxgroup) target_link_modules(toxcore toxgroup)
################################################################################ ################################################################################
# #
# :: Audio/Video Library # :: Audio/Video Library
@ -183,20 +208,29 @@ target_link_modules(toxcore toxgroup)
################################################################################ ################################################################################
if(BUILD_TOXAV) if(BUILD_TOXAV)
apidsl(
toxav/toxav.api.h)
add_module(toxav add_module(toxav
toxav/audio.c toxav/audio.c
toxav/audio.h
toxav/bwcontroller.c toxav/bwcontroller.c
toxav/bwcontroller.h
toxav/group.c toxav/group.c
toxav/group.h
toxav/msi.c toxav/msi.c
toxav/msi.h
toxav/ring_buffer.c toxav/ring_buffer.c
toxav/ring_buffer.h
toxav/rtp.c toxav/rtp.c
toxav/rtp.h
toxav/toxav.c toxav/toxav.c
toxav/toxav.h
toxav/toxav_old.c toxav/toxav_old.c
toxav/video.c) toxav/video.c
toxav/video.h)
target_link_modules(toxav toxcore ${OPUS_LIBRARIES} ${VPX_LIBRARIES}) target_link_modules(toxav toxcore ${OPUS_LIBRARIES} ${VPX_LIBRARIES})
endif() endif()
################################################################################ ################################################################################
# #
# :: ToxDNS and block encryption libraries # :: ToxDNS and block encryption libraries
@ -211,16 +245,20 @@ add_module(toxencryptsave
toxencryptsave/toxencryptsave.c) toxencryptsave/toxencryptsave.c)
target_link_modules(toxencryptsave toxcore) target_link_modules(toxencryptsave toxcore)
################################################################################ ################################################################################
# #
# :: Automated regression tests # :: Automated regression tests
# #
################################################################################ ################################################################################
add_test( if(APIDSL AND ASTYLE)
NAME format_test add_test(
COMMAND ${CMAKE_SOURCE_DIR}/other/astyle/format-source "${CMAKE_SOURCE_DIR}") NAME format_test
COMMAND ${CMAKE_SOURCE_DIR}/other/astyle/format-source
"${CMAKE_SOURCE_DIR}"
"${APIDSL}"
"${ASTYLE}")
endif()
function(auto_test target) function(auto_test target)
if(CHECK_FOUND) if(CHECK_FOUND)
@ -251,7 +289,6 @@ if(BUILD_TOXAV)
auto_test(toxav_many) auto_test(toxav_many)
endif() endif()
################################################################################ ################################################################################
# #
# :: Bootstrap daemon # :: Bootstrap daemon
@ -279,7 +316,6 @@ if(LIBCONFIG_FOUND)
target_link_modules(tox-bootstrapd toxnetcrypto ${LIBCONFIG_LIBRARIES}) target_link_modules(tox-bootstrapd toxnetcrypto ${LIBCONFIG_LIBRARIES})
endif() endif()
################################################################################ ################################################################################
# #
# :: Test programs # :: Test programs
@ -329,7 +365,6 @@ if(NOT WIN32)
target_link_modules(irc_syncbot toxcore) target_link_modules(irc_syncbot toxcore)
endif() endif()
################################################################################ ################################################################################
# #
# :: Installation and pkg-config # :: Installation and pkg-config
@ -362,7 +397,6 @@ configure_file(
@ONLY @ONLY
) )
install(FILES install(FILES
${CMAKE_BINARY_DIR}/toxcore.pc ${CMAKE_BINARY_DIR}/toxcore.pc
${CMAKE_BINARY_DIR}/toxdns.pc ${CMAKE_BINARY_DIR}/toxdns.pc

29
cmake/ApiDsl.cmake Normal file
View File

@ -0,0 +1,29 @@
################################################################################
#
# :: APIDSL regeneration
#
################################################################################
find_program(APIDSL NAMES
apidsl
apidsl.native
apidsl.byte
${CMAKE_SOURCE_DIR}/../apidsl/apigen.native)
find_program(ASTYLE NAMES
astyle)
function(apidsl)
if(APIDSL AND ASTYLE)
foreach(in_file ${ARGN})
get_filename_component(dirname ${in_file} DIRECTORY)
get_filename_component(filename ${in_file} NAME_WE)
set(out_file ${CMAKE_SOURCE_DIR}/${dirname}/${filename}.h)
add_custom_command(
OUTPUT ${out_file}
COMMAND "${APIDSL}" "${CMAKE_SOURCE_DIR}/${in_file}"
| "${ASTYLE}" --options="${CMAKE_SOURCE_DIR}/other/astyle/astylerc"
> "${out_file}"
DEPENDS ${in_file})
endforeach()
endif()
endfunction()

View File

@ -13,19 +13,19 @@ If you want to do it quickly and you don't have time for anything other than cop
1. Make sure that you have ``curl`` and ``>=astyle-2.03`` installed 1. Make sure that you have ``curl`` and ``>=astyle-2.03`` installed
2. Modify [``tox.in.h``](/other/apidsl/tox.in.h) 2. Modify [``tox.api.h``](/toxcore/tox.api.h)
3. Run command below ↓ 3. Run command below ↓
Command to run from ``toxcore`` directory (quick way, involves using curl): Command to run from ``toxcore`` directory (quick way, involves using curl):
```bash ```bash
# For tox.h: # For tox.h:
curl -X POST --data-binary @- https://apidsl.herokuapp.com/apidsl \ curl -X POST --data-binary @- https://apidsl.herokuapp.com/apidsl \
< other/apidsl/tox.in.h \ < toxcore/tox.api.h \
| astyle --options=other/astyle/astylerc \ | astyle --options=other/astyle/astylerc \
> toxcore/tox.h > toxcore/tox.h
# For toxav.h: # For toxav.h:
curl -X POST --data-binary @- https://apidsl.herokuapp.com/apidsl \ curl -X POST --data-binary @- https://apidsl.herokuapp.com/apidsl \
< other/apidsl/toxav.in.h \ < toxav/toxav.api.h \
| astyle --options=other/astyle/astylerc \ | astyle --options=other/astyle/astylerc \
> toxav/toxav.h > toxav/toxav.h
``` ```
@ -41,7 +41,7 @@ If you prefer to have more control over what is happening, there are steps below
1. Install [``apidsl``](https://github.com/TokTok/apidsl) 1. Install [``apidsl``](https://github.com/TokTok/apidsl)
2. Install ``astyle``, version 2.03 or later. 2. Install ``astyle``, version 2.03 or later.
3. Modify [``tox.in.h``](/other/apidsl/tox.in.h) 3. Modify [``tox.api.h``](/toxcore/tox.api.h)
4. Use ``apidsl`` ``??`` 4. Use ``apidsl`` ``??``
5. Parse generated ``tox.h`` with astyle, minimal command for it would be: 5. Parse generated ``tox.h`` with astyle, minimal command for it would be:
```bash ```bash

View File

@ -29,4 +29,4 @@ Copy [``astylerc``](/other/astyle/astylerc) to ``toxcore/.git/hooks``
``astylerc`` - this file can be used in the pre-commit hook to try its best at making the code conform to the coding style of toxcore. ``astylerc`` - this file can be used in the pre-commit hook to try its best at making the code conform to the coding style of toxcore.
Furthermore, it is being used to format ``tox.h`` after using [``apidsl``](/other/apidsl) to generate it. Furthermore, it is being used to format ``tox.h`` after using ``apidsl`` to generate it.

View File

@ -3,6 +3,8 @@
set -e set -e
SOURCE_DIR="$1" SOURCE_DIR="$1"
APIDSL="$2"
ASTYLE="$3"
# Go to the source root. # Go to the source root.
if [ -z "$SOURCE_DIR" ]; then if [ -z "$SOURCE_DIR" ]; then
@ -20,10 +22,11 @@ if ! which "$ASTYLE"; then
exit 1 exit 1
fi fi
if [ -f ../apidsl/apigen.native ]; then if ! which "$APIDSL"; then
APIDSL=../apidsl/apigen.native if [ -f ../apidsl/apigen.native ]; then
else APIDSL=../apidsl/apigen.native
APIDSL=apidsl_curl else
APIDSL=apidsl_curl
fi fi
apidsl_curl() { apidsl_curl() {
@ -31,10 +34,10 @@ apidsl_curl() {
} }
# Check if toxcore.h and toxav.h match apidsl tox.in.h and toxav.in.h. # Check if toxcore.h and toxav.h match apidsl tox.in.h and toxav.in.h.
$APIDSL other/apidsl/tox.in.h > toxcore/tox.h $APIDSL toxcore/tox.api.h > toxcore/tox.h
$APIDSL other/apidsl/toxav.in.h > toxav/toxav.h $APIDSL toxav/toxav.api.h > toxav/toxav.h
SOURCES=`find . -name "*.[ch]" -and -not -name "*.in.*" -and -not -wholename "*crypto_pwhash*" -and -not -wholename "./super_donators/*"` SOURCES=`find . -name "*.[ch]" -and -not -name "*.api.h" -and -not -wholename "*crypto_pwhash*" -and -not -wholename "./super_donators/*"`
$ASTYLE -n --options=other/astyle/astylerc $SOURCES $ASTYLE -n --options=other/astyle/astylerc $SOURCES

View File

@ -21,8 +21,8 @@ update() {
fi fi
} }
update "configure.ac" 's/AC_INIT(\[tox\], \[.*\])/AC_INIT([tox], ['$VER'])/' update 'configure.ac' 's/AC_INIT(\[tox\], \[.*\])/AC_INIT([tox], ['$VER'])/'
update "other/apidsl/tox.in.h" 's/\(const VERSION_MAJOR *= \).*;/\1'$MAJOR';/' update 'toxcore/tox.api.h' 's/\(const VERSION_MAJOR *= \).*;/\1'$MAJOR';/'
update "other/apidsl/tox.in.h" 's/\(const VERSION_MINOR *= \).*;/\1'$MINOR';/' update 'toxcore/tox.api.h' 's/\(const VERSION_MINOR *= \).*;/\1'$MINOR';/'
update "other/apidsl/tox.in.h" 's/\(const VERSION_PATCH *= \).*;/\1'$PATCH';/' update 'toxcore/tox.api.h' 's/\(const VERSION_PATCH *= \).*;/\1'$PATCH';/'

View File

@ -37,8 +37,8 @@ extern "C" {
/***************************************************************************** /*****************************************************************************
* `tox.h` SHOULD *NOT* BE EDITED MANUALLY any changes should be made to * * `tox.h` SHOULD *NOT* BE EDITED MANUALLY any changes should be made to *
* `tox.in.h`, located in `other/apidsl/`. For instructions on how to * * `tox.api.h`, located in `toxcore/`. For instructions on how to *
* generate `tox.h` from `tox.in.h` please refer to `other/apidsl/README.md` * * generate `tox.h` from `tox.api.h` please refer to `docs/apidsl.md` *
*****************************************************************************/ *****************************************************************************/

View File

@ -35,8 +35,8 @@ extern "C" {
/******************************************************************************* /*******************************************************************************
* `tox.h` SHOULD *NOT* BE EDITED MANUALLY any changes should be made to * * `tox.h` SHOULD *NOT* BE EDITED MANUALLY any changes should be made to *
* `tox.in.h`, located in `other/apidsl/`. For instructions on how to * * `tox.api.h`, located in `toxcore/`. For instructions on how to *
* generate `tox.h` from `tox.in.h` please refer to `other/apidsl/README.md` * * generate `tox.h` from `tox.api.h` please refer to `docs/apidsl.md` *
******************************************************************************/ ******************************************************************************/